selfupdate 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. set -eu -o pipefail
  3. helpexit() {
  4. echo "$0 install|check|update <url>"
  5. exit 1
  6. }
  7. test -n "${1:-}" || helpexit
  8. action=$1
  9. appimage=Paimon_Launcher.AppImage
  10. bin_path="$HOME/.local/bin/"
  11. bin_appimage="$bin_path$appimage"
  12. launcher_path="$HOME/.local/share/paimon-launcher/"
  13. launcher_bin=${launcher_path}bin/
  14. install() {
  15. check
  16. echo "Installing v$version"
  17. update "$link"
  18. echo
  19. echo "Installation to $bin_appimage finished"
  20. echo
  21. echo "Command to start launcher:"
  22. echo " $appimage"
  23. }
  24. check() {
  25. url='https://notabug.org/loentar/paimon-launcher/releases'
  26. temp=`mktemp`
  27. trap "rm -f '$temp'" EXIT
  28. aria2c --allow-overwrite --dir `dirname "$temp"` -o `basename "$temp"` "$url" >&2
  29. whole_content=$(<$temp)
  30. content=`sed '/<ul id="release-list"/,/span class="dot"/!d;/href=/!d' <<< "$whole_content"`
  31. version=`sed '/tag icon/!d;s/<[^>]*>//g;s/[ \t]*//g' <<< "$content"`
  32. link=`sed '/google/!d;s/.*href="//g;s/".*//g' <<< "$content"`
  33. if [ -e "$launcher_bin$appimage" ]; then
  34. mode=update
  35. else
  36. mode=download
  37. fi
  38. echo "PLVERSION $mode $version $link"
  39. }
  40. update() {
  41. appimage_url=${1:-}
  42. if [ -z "$appimage_url" ]; then
  43. helpexit
  44. fi
  45. mkdir -p "$launcher_bin"
  46. mkdir -p "$bin_path"
  47. launcher=${launcher_path}bin/$appimage
  48. # https://drive.google.com/file/d/1GC-PFibSdo8Mwx2xG50gcfia3wSClN87/view?usp=sharing
  49. # vvv
  50. # https://drive.google.com/uc?id=1GC-PFibSdo8Mwx2xG50gcfia3wSClN87&export=download
  51. download_link=`sed 's/file\/d\//uc\?id=/;s/\/view.*/\&export=download/' <<< "$appimage_url"`
  52. echo "$download_link"
  53. aria2c --allow-overwrite --dir "$launcher_bin" -o "$appimage.new" "$download_link"
  54. if [ -f "$launcher" ]; then
  55. mv -f "$launcher" "$launcher.bak"
  56. fi
  57. mv -f "$launcher.new" "$launcher"
  58. chmod +x "$launcher"
  59. ln -nsf "$launcher" "$bin_appimage"
  60. }
  61. restart() {
  62. ($launcher >/dev/null 2>&1) &
  63. disown
  64. }
  65. case "$action" in
  66. install)
  67. install
  68. ;;
  69. check)
  70. check
  71. ;;
  72. update)
  73. update "$2"
  74. restart
  75. ;;
  76. *)
  77. helpexit
  78. ;;
  79. esac