-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
installgui
executable file
·74 lines (63 loc) · 2.46 KB
/
installgui
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
#!/bin/bash
DIRECTORY="$(dirname $0)"
#variable 1 is a space-seperated list of packages
NUM_PKGS=$(echo "$1" | wc -w)
#echo "$NUM_PKGS"
#repeat for each package listed
i=1
while [ $i -le "$NUM_PKGS" ]; do
REQ_PKG="$(echo $1 | cut -d " " -f $i)"
#echo "$REQ_PKG"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' "$REQ_PKG"|grep "install ok installed")
if [ "" == "$PKG_OK" ]; then
PKG_LIST="${PKG_LIST} ${REQ_PKG}" #add package to install list
fi
#echo $i
PKG_LIST="$(echo "$PKG_LIST" | sed -e 's/^ //g')"
i=$((i+1))
done
#list created that only has packages not installed
#remove spaces
echo "To be installed: ${PKG_LIST}"
#if blank or contains only spaces
if [ ! -z "$PKG_LIST" ];then
#has newline chars to display properly
package_list="$(echo "$PKG_LIST" | tr ' ' '\n')"
#If yad exists, use a yad dialog
if [ -f /usr/bin/yad ];then
echo -e "$package_list" | yad --list --no-click --no-columns --separator='\n' \
--title='Pi Power Tools' --center --window-icon="${DIRECTORY}/icons/logo-64.png" \
--text=" These packages are required but not installed. \n Install them now?" \
--column=Package \
--button="No!${DIRECTORY}/icons/exit.png:1" \
--button="Yes!${DIRECTORY}/icons/check.png:0" \
--image="${DIRECTORY}/icons/install.png" \
--print-column=2 --no-selection 2>/dev/null
button=$?
else #if yad does not exist then fallback to zenity
echo -e "$package_list" | zenity --title='Pi Power Tools' --window-icon="${DIRECTORY}/icons/logo-64.png" \
--list --text=" These packages are required but not installed. \n Install them now?" \
--ok-label=Yes --cancel-label=No \
--column=foo --hide-header 2>/dev/null
button=$?
fi
#echo $button
if [ ! $button -eq 0 ];then
echo "User declined."
exit 1
fi
echo $PKG_LIST > "${DIRECTORY}/installedpackages"
"${DIRECTORY}/functions/terminal-run" "sudo apt install -y $PKG_LIST;echo -e '\nInstallation finished.\nClosing in 5 seconds.';sleep 5" "Installing packages..."
if [ ! $? -eq 0 ];then #if apt exits with error
echo -e "Could not install the packages!\nTry installing them yourself by running this in the terminal:\nsudo apt install $PGK_LIST" | yad --text-info \
--width=700 --height=150 --title='Pi Power Tools' --center \
--button="OK!${DIRECTORY}/icons/check.png:0" --window-icon="${DIRECTORY}/icons/logo-64.png" 2>/dev/null
exit 1
fi
sleep 1
#wait until apt process finishes
while ps -C apt,dpkg >/dev/null;do
sleep 1
done
fi
#all of the above is skipped if there are no new packages to install.