#!/bin/sh APP=jq SITE="jqlang/jq" # CREATE DIRECTORIES if [ -z "$APP" ]; then exit 1; fi mkdir -p "/opt/$APP/tmp" "/opt/$APP/icons" && cd "/opt/$APP/tmp" || exit 1 # ADD THE REMOVER echo "#!/bin/sh rm -f /usr/local/bin/$APP rm -R -f /opt/$APP" >> "/opt/$APP/remove" chmod a+x "/opt/$APP/remove" # DOWNLOAD AND PREPARE THE APP # $version is also used for updates version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*linux.*amd64' | head -1) wget "$version" echo "$version" >> /opt/$APP/version cd .. mv ./tmp/jq* ./"$APP" chmod a+x "/opt/$APP/$APP" rm -R -f ./tmp # LINK ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP" # SCRIPT TO UPDATE THE PROGRAM cat >> "/opt/$APP/AM-updater" << 'EOF' #!/bin/sh APP=jq SITE="jqlang/jq" if [ -z "$APP" ]; then exit 1; fi version0=$(cat "/opt/$APP/version") version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*linux.*amd64' | head -1) if [ "$version" = "$version0" ]; then echo "Update not needed!" && exit 0 else notify-send "A new version of $APP is available, please wait" mkdir "/opt/$APP/tmp" cd "/opt/$APP/tmp" || exit 1 wget "$version" if ls . | grep jq; then cd .. if test -f ./tmp/*jq; then rm ./version fi echo "$version" >> ./version mv --backup=t ./tmp/* ./"$APP" chmod a+x "/opt/$APP/$APP" rm -R -f ./tmp ./*~ fi notify-send "$APP is updated!" fi EOF chmod a+x "/opt/$APP/AM-updater"