/
cpu-x
92 lines (82 loc) · 3.13 KB
/
cpu-x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
APP=cpu-x
SITE="TheTumultuousUnicornOfDarkness/CPU-X"
# 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/share/applications/AM-$APP.desktop /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/TheTumultuousUnicornOfDarkness/CPU-X/releases | jq '.' | grep browser_download_url | grep -w -v continuous | grep -i appimage | cut -d '"' -f 4 | head -1)
wget "$version"
wget "$version.zsync" 2> /dev/null
echo "$version" >> /opt/$APP/version
# Use tar fx ./*tar* for example in this line in case a compressed file is downloaded.
cd ..
mv ./tmp/*mage ./"$APP"
mv ./tmp/*.zsync ./"$APP".zsync 2> /dev/null
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=cpu-x
SITE="TheTumultuousUnicornOfDarkness/CPU-X"
if [ -z "$APP" ]; then exit 1; fi
version0=$(cat "/opt/$APP/version")
version=$(curl -Ls https://api.github.com/repos/TheTumultuousUnicornOfDarkness/CPU-X/releases | jq '.' | grep browser_download_url | grep -w -v continuous | grep -i appimage | cut -d '"' -f 4 | head -1)
if test -f "/opt/$APP/*.zsync"; then
mkdir "/opt/$APP/tmp"
cd "/opt/$APP/tmp" || exit 1
wget "$version.zsync" 2> /dev/null
cd ..
mv ./tmp/*.zsync ./"$APP".zsync
rm -R -f ./tmp
zsync "/opt/$APP/$APP.zsync"
rm -R -f "/opt/$APP/*zs-old" "/opt/$APP/*.part"
chmod a+x /opt/$APP/$APP
if [ "$version" != "$version0" ]; then
rm -f /opt/$APP/version
echo "$version" >> /opt/$APP/version
fi
else
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 mage; then
cd ..
if test -f ./tmp/*mage; 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
fi
EOF
chmod a+x "/opt/$APP/AM-updater"
# LAUNCHER & ICON
cd "/opt/$APP" || exit 1
./"$APP" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
./"$APP" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$APP".desktop
./"$APP" --appimage-extract share/applications/*.desktop 1>/dev/null && mv ./squashfs-root/share/applications/*.desktop ./"$APP".desktop
./"$APP" --appimage-extract usr/share/applications/*.desktop 1>/dev/null && mv ./squashfs-root/usr/share/applications/*.desktop ./"$APP".desktop
if [ -L ./DirIcon ]; then
LINKPATH=$(readlink ./DirIcon)
./"$APP" --appimage-extract "$LINKPATH" && mv ./squashfs-root/"$LINKPATH" ./DirIcon
fi
sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
mv ./"$APP".desktop /usr/share/applications/AM-"$APP".desktop && mv ./DirIcon ./icons/"$APP" 2>/dev/null
rm -R -f ./squashfs-root