yazi 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # AM INSTALL SCRIPT VERSION 3.
  3. set -u
  4. APP=yazi
  5. SITE="sxyazi/yazi"
  6. # CREATE DIRECTORIES AND ADD REMOVER
  7. [ -n "$APP" ] && mkdir -p "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
  8. printf "#!/bin/sh\nset -e\nrm -f /usr/local/bin/$APP\nrm -R -f /opt/$APP" > "/opt/$APP/remove"
  9. printf '\n%s' "rm -f /usr/local/bin/ya" >> "/opt/$APP/remove"
  10. chmod a+x "/opt/$APP/remove"
  11. # DOWNLOAD AND PREPARE THE APP
  12. # $version is also used for updates
  13. version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*aarch64.*linux.*gnu.*zip$' | head -1)
  14. wget "$version" && echo "$version" > "/opt/$APP/version" || exit 1
  15. unzip ./*zip || exit 1
  16. cd ..
  17. mv --backup=t ./tmp/*/* ./ && rm -R -f ./tmp || exit 1
  18. chmod a+x "/opt/$APP/$APP" "/opt/$APP/ya" || exit 1
  19. # LINK TO PATH
  20. ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP" && ln -s "/opt/$APP/ya" "/usr/local/bin/ya"
  21. # SCRIPT TO UPDATE THE PROGRAM
  22. cat >> "/opt/$APP/AM-updater" << 'EOF'
  23. #!/bin/sh
  24. set -u
  25. APP=yazi
  26. SITE="sxyazi/yazi"
  27. version0=$(cat /opt/$APP/version)
  28. version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*aarch64.*linux.*gnu.*zip$' | head -1)
  29. [ -n "$version" ] || { echo "Error getting link"; exit 1; }
  30. if [ "$version" != "$version0" ]; then
  31. notify-send "A new version of $APP is available, please wait"
  32. mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
  33. wget "$version" || exit 1
  34. unzip ./*zip || exit 1
  35. cd ..
  36. mv --backup=t ./tmp/*/* ./ && rm -R -f ./tmp || exit 1
  37. echo "$version" > ./version
  38. rm -R -f ./tmp ./*~
  39. chmod a+x "/opt/$APP/$APP" "/opt/$APP/ya" || exit 1
  40. notify-send "$APP is updated!"
  41. exit 0
  42. fi
  43. echo "Update not needed!"
  44. EOF
  45. chmod a+x "/opt/$APP/AM-updater" || exit 1