-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
home
executable file
·185 lines (161 loc) · 6.27 KB
/
home
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
DIRECTORY="$(dirname $0)"
#check for ppt updates
LATEST_VER="$(wget -qO- https://raw.githubusercontent.com/Botspot/Pi-Power-Tools/master/data/version)"
LOCAL_VER="$(head -n 1 "${DIRECTORY}/data/version")"
echo "latest version: $LATEST_VER"
echo "local version: $LOCAL_VER"
#if run as menubutton, open default startup window
if [ "$1" = 'menubutton' ];then
defopen="$(cat "${DIRECTORY}/data/home.conf" | sed -n 2p)"
echo "defopen: $defopen"
if [ "$defopen" = "This window" ];then
true #dont prompt for update since user will see it in home page
elif [ "$defopen" = "USB Mode" ];then
#display update dialog if update is available
if [ ! -z $LATEST_VER ] && [ $LATEST_VER -gt $LOCAL_VER ];then
yad --title='Pi Power Tools' --window-icon="${DIRECTORY}/icons/logo-64.png" \
--text="Version ${LATEST_VER} is available. Install now?" \
--center --text-align=center \
--button="Not now!${DIRECTORY}/icons/forward.png:1" \
--button="Install!${DIRECTORY}/icons/download.png:0" 2>/dev/null && wget -O - https://raw.githubusercontent.com/Botspot/Pi-Power-Tools/master/update | bash
fi
#and now go to usb mode
"${DIRECTORY}/usb-mode" &
exit 0
elif [ "$defopen" = "IMG Mode" ];then
#display update dialog if update is available
if [ ! -z $LATEST_VER ] && [ $LATEST_VER -gt $LOCAL_VER ];then
yad --title='Pi Power Tools' --window-icon="${DIRECTORY}/icons/logo-64.png" \
--text="Version ${LATEST_VER} is available. Install now?" \
--center --text-align=center \
--button="Not now!${DIRECTORY}/icons/forward.png:1" \
--button="Install!${DIRECTORY}/icons/download.png:0" 2>/dev/null && wget -O - https://raw.githubusercontent.com/Botspot/Pi-Power-Tools/master/update | bash
fi
#and now go to img mode
"${DIRECTORY}/img-mode" &
exit 0
elif [ "$defopen" = "Flash" ];then
"${DIRECTORY}/flash"
else
echo "conf corrupted or nonexistent"
rm "${DIRECTORY}/data/home.conf"
#make conf file
echo "
This window
FALSE
Desktop
TRUE" > "${DIRECTORY}/data/home.conf"
fi
fi
"${DIRECTORY}/installgui" yad
while true;do
if [ ! -z $LATEST_VER ] && [ $LATEST_VER -gt $LOCAL_VER ];then
addtext="
Version $LATEST_VER is available. Click Update to install it.
"
addbutton="--button=Update!${DIRECTORY}/icons/download.png!Installs the latest version of Pi Power Tools.:6"
elif [ "$(cat "${DIRECTORY}/data/home.conf" | sed -n 3p)" = 'TRUE' ];then
#if update enabled always
addbutton="--button=Update!${DIRECTORY}/icons/download.png!Click this to factory reset Pi Power Tools.:6"
else
addbutton=''
fi
output="$(echo "Welcome to Pi Power Tools!
General Purpose Raspbian Image & SD Card Manager
$addtext
Click USB Mode or IMG Mode to get started.
Curious what a button does? Just hover your mouse over it!
For full help click here:
https://github.com/Botspot/Pi-Power-Tools#instructions" | yad --text-info \
--wrap --justify=center --fore=#80FFFF --back=#000000 --title="Pi Power Tools - Home" \
--width=530 --height=260 --center --wrap --window-icon="${DIRECTORY}/icons/logo-64.png" \
--image=${DIRECTORY}/icons/logo-tall.png --show-uri --fontname="12" \
"$addbutton" \
--button='Settings'!"${DIRECTORY}/icons/settings.png"!'Customize your experience with Pi Power Tools.':4 \
--button='USB Mode'!"${DIRECTORY}/icons/usb-16.png"!'Manage a USB device that has Raspbian flashed to it.':2 \
--button='IMG Mode'!"${DIRECTORY}/icons/img-16.png"!'Everything you need to customize a Raspbian image.':0 \
2>/dev/null)"
button=$?
case $button in
1)
echo "Error"
exit 1
;;
2)
echo "USB mode"
"${DIRECTORY}/usb-mode" &
exit 0
;;
0)
echo "IMG mode"
"${DIRECTORY}/img-mode" &
exit 0
;;
4)
echo "Settings"
settings="$(cat "${DIRECTORY}/data/home.conf")"
echo "$settings"
openoptions="This window
USB Mode
IMG Mode
Flash"
if [ -z "$(echo "$openoptions" | grep "$settings")" ];then
echo "conf corrupted or nonexistent"
rm "${DIRECTORY}/data/home.conf"
echo -e "
This window
FALSE
Desktop
1
" > "${DIRECTORY}/data/home.conf"
exit 0
fi
sorted_open="$(echo "$settings" | sed -n 2p)!$(echo "$openoptions" | grep -v "$(echo "$settings" | sed -n 2p)" | tr '\n' '!' )"
bootoptions="Desktop
Console - autologin
Console - no autologin"
sorted_boot="$(echo "$settings" | sed -n 5p)!$(echo "$bootoptions" | grep -v "$(echo "$settings" | sed -n 5p)" | tr '\n' '!' )"
output="$(yad --form --window-icon="${DIRECTORY}/icons/logo-64.png" \
--title="Settings" --center \
--field="<big>Home Settings</big>:LBL" '' \
--field="Menu button opens::CB" "${sorted_open::-1}" \
--field="Show Update button even if latest version:CHK" "$(echo "$settings" | sed -n 3p)" \
--field="<big>Boot Settings</big>:LBL" '' \
--field="Boot to::CB" "${sorted_boot::-1}" \
--field="<big>IMG Mode Settings</big>:LBL" '' \
--field="Run zerofree during Shrink:CHK" "$(echo "$settings" | sed -n 7p)" \
--field="GB of free space:NUM" "$(echo "$settings" | sed -n 8p)!1..1024" \
--button='Cancel'!"${DIRECTORY}/icons/back.png":1 \
--button='Save'!"${DIRECTORY}/icons/save.png":0 \
--separator='\n' 2>/dev/null)"
button=$?
if [ $button -eq 0 ];then
echo "output: ${output}EOO"
#save to conf file
echo "$output" > "${DIRECTORY}/data/home.conf"
#generate vdesktop.conf
if [ "$(echo "$output" | sed -n 5p)" = "Desktop" ];then
echo "gui" > "${DIRECTORY}/data/vdesktop.conf"
elif [ "$(echo "$output" | sed -n 5p)" = 'Console - autologin' ];then
echo "cli-login" > "${DIRECTORY}/data/vdesktop.conf"
elif [ "$(echo "$output" | sed -n 5p)" = 'Console - no autologin' ];then
echo "cli" > "${DIRECTORY}/data/vdesktop.conf"
else
echo "Failed to generate vdesktop config."
fi
fi
;;
6)
echo "Update"
wget -O - https://raw.githubusercontent.com/Botspot/Pi-Power-Tools/master/update | bash &
exit 0
;;
*)
#any other button
echo "exiting"
echo ''
exit 0
;;
esac
done