/ programs / x86_64 / apifox
apifox
 1  #!/bin/sh
 2  
 3  # AM INSTALL SCRIPT VERSION 3.5
 4  set -u
 5  APP=apifox
 6  SITE="https://apifox.com"
 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  printf '\n%s' "rm -f /usr/local/share/applications/$APP-AM.desktop" >> ../remove
12  chmod a+x ../remove || exit 1
13  
14  # DOWNLOAD AND PREPARE THE APP, $version is also used for updates
15  version=$(wget -q https://repology.org/project/apifox/related -O - | grep "version-newest" | head -1 | tr '>' '\n' | grep "[0-9]" | sed 's#</span##g')
16  wget "https://cdn.apifox.cn/download/Apifox-linux-latest.zip" || exit 1
17  [ -e ./*zip ] && unzip -qq ./*zip 1>/dev/null && rm -f ./*zip
18  cd ..
19  mv ./tmp/*mage ./"$APP" || exit 1
20  rm -R -f ./tmp || exit 1
21  echo "$version" > ./version
22  chmod a+x ./$APP || exit 1
23  
24  # LINK TO PATH
25  ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP"
26  
27  # SCRIPT TO UPDATE THE PROGRAM
28  cat >> ./AM-updater << 'EOF'
29  #!/bin/sh
30  set -u
31  APP=apifox
32  SITE="https://apifox.com"
33  version0=$(cat "/opt/$APP/version")
34  version=$(wget -q https://repology.org/project/apifox/related -O - | grep "version-newest" | head -1 | tr '>' '\n' | grep "[0-9]" | sed 's#</span##g')
35  [ -n "$version" ] || { echo "Error getting link"; exit 1; }
36  if [ "$version" != "$version0" ]; then
37  	mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
38  	notify-send "A new version of $APP is available, please wait"
39  	wget "https://cdn.apifox.cn/download/Apifox-linux-latest.zip" || exit 1
40  	[ -e ./*zip ] && unzip -qq ./*zip 1>/dev/null && rm -f ./*zip
41  	cd ..
42  	mv --backup=t ./tmp/*mage ./"$APP"
43  	chmod a+x ./"$APP" || exit 1
44  	echo "$version" > ./version
45  	rm -R -f ./*zs-old ./*.part ./tmp ./*~
46  	notify-send "$APP is updated!"
47  else
48  	echo "Update not needed!"
49  fi
50  EOF
51  chmod a+x ./AM-updater || exit 1
52  
53  # LAUNCHER & ICON
54  ./"$APP" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$APP".desktop
55  ./"$APP" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
56  COUNT=0
57  while [ "$COUNT" -lt 10 ]; do # Tries to get the actual icon/desktop if it is a symlink to another symlink
58  	if [ -L ./"$APP".desktop ]; then
59  		LINKPATH="$(readlink ./"$APP".desktop | sed 's|^\./||')"
60  		./"$APP" --appimage-extract "$LINKPATH" 1>/dev/null && mv ./squashfs-root/"$LINKPATH" ./"$APP".desktop
61  	fi
62  	if [ -L ./DirIcon ]; then
63  		LINKPATH="$(readlink ./DirIcon | sed 's|^\./||')"
64  		./"$APP" --appimage-extract "$LINKPATH" 1>/dev/null && mv ./squashfs-root/"$LINKPATH" ./DirIcon
65  	fi
66  	[ ! -L ./"$APP".desktop ] && [ ! -L ./DirIcon ] && break
67  	COUNT=$((COUNT + 1))
68  done
69  sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
70  mv ./"$APP".desktop /usr/local/share/applications/"$APP"-AM.desktop && mv ./DirIcon ./icons/"$APP" 1>/dev/null
71  rm -R -f ./squashfs-root