xdg-ninja 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # AM INSTALL SCRIPT VERSION 3.
  3. set -u
  4. APP=xdg-ninja
  5. SITE="b3nj5m1n/xdg-ninja"
  6. # CREATE DIRECTORIES AND ADD REMOVER
  7. [ -n "$APP" ] && mkdir -p "/opt/$APP/tmp" "/opt/$APP/icons" && 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/share/applications/$APP-AM.desktop" >> "/opt/$APP/remove"
  10. chmod a+x "/opt/$APP/remove"
  11. # DOWNLOAD AND PREPARE THE APP, $version is also used for updates
  12. version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{} ]/\n/g' | grep -i "https.*$APP.*tarball" | grep -vi "apple\|windows\|darwin" | head -1)
  13. wget "$version" -O download.tar.gz || exit 1
  14. [ -e ./*tar.* ] && tar fx ./*tar.* && rm -f ./*tar.*
  15. cd ..
  16. if [ -d ./tmp/* 2>/dev/null ]; then mv ./tmp/*/* ./; else mv ./tmp/* ./"$APP" 2>/dev/null || mv ./tmp/* ./; fi
  17. rm -R -f ./tmp || exit 1
  18. echo "$version" > ./version
  19. chmod a+x "/opt/$APP/$APP.sh" || exit 1
  20. # LINK TO PATH
  21. ln -s "/opt/$APP/$APP.sh" "/usr/local/bin/$APP"
  22. # SCRIPT TO UPDATE THE PROGRAM
  23. cat >> "/opt/$APP/AM-updater" << 'EOF'
  24. #!/bin/sh
  25. set -u
  26. APP=xdg-ninja
  27. SITE="b3nj5m1n/xdg-ninja"
  28. version0=$(cat "/opt/$APP/version")
  29. version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{} ]/\n/g' | grep -i "https.*$APP.*tarball" | grep -vi "apple\|windows\|darwin" | head -1)
  30. [ -n "$version" ] || { echo "Error getting link"; exit 1; }
  31. if [ "$version" != "$version0" ]; then
  32. mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
  33. notify-send "A new version of $APP is available, please wait"
  34. wget "$version" -O download.tar.gz || exit 1
  35. [ -e ./*tar.* ] && tar fx ./*tar.* && rm -f ./*tar.*
  36. cd ..
  37. if [ -d ./tmp/* 2>/dev/null ]; then mv --backup=t ./tmp/*/* ./; else mv --backup=t ./tmp/* ./"$APP" 2>/dev/null || mv --backup=t ./tmp/* ./; fi
  38. chmod a+x "/opt/$APP/$APP.sh" || exit 1
  39. echo "$version" > ./version
  40. rm -R -f ./tmp ./*~
  41. notify-send "$APP is updated!"
  42. exit 0
  43. fi
  44. echo "Update not needed!"
  45. EOF
  46. chmod a+x "/opt/$APP/AM-updater"