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