2
# part of the power installer application
13
# input sent from vala
24
tmpname="$(mktemp -d /dev/shm/.power-installer.XXXXXX)"
26
# if input equals something
27
if [ "$input$ppa$pkg" != "" ]; then
31
echo -e "\nUSER SESSION: OPEN\n"
33
# load all the functions from "functions.sh"
34
source "/usr/share/power-installer/functions.sh"
36
# launch all as sudo // this function was written origrinally by Luca Borrione
41
tmpfile="/dev/shm/$RANDOM.sh"
50
installed='"$installed"'
51
sendfile="$tmpname/send-success.sh"
55
for param in "${params[@]}"; do
56
if [[ $param =~ $regex ]]; then
57
content="${content}\t\"${param}\"\n"
59
content="${content}\t${param}\n"
64
echo -e "$content" > "$tmpfile"
66
echo "#$(type "$_funcname_")" >> "$tmpfile"
67
echo -e "\n$_funcname_ \"\${params[@]}\"\n" >> "$tmpfile"
69
# using "sudo -Si" prevents errors from any commands that cannot use sudo
70
ep | sudo -Si bash "$tmpfile"
71
ep | sudo -S rm -f "$tmpfile"
76
file="user-execute.sh"
77
echo "#!bin/bash" >> $file
78
echo "# generated by power installer" >> $file
80
echo 'source "/usr/share/power-installer/functions.sh"' >> $file
82
echo tmpname="'$tmpname'" >> $file # without quotes, they have been breaking the string, transfer $tmpname to script
83
echo 'sendfile="$tmpname"/send-success.sh' >> $file
86
echo "ppa_pkg() {" >> $file
87
echo ppa="'$ppa'" >> $file # without quotes, they have been breaking entire ppa list
88
echo pkg="'$pkg'" >> $file # without quotes, they have been breaking entire package list
89
echo 'if [ "$ppa" != "" ]; then' >> $file
91
# another quotes around ppa variable to prevent fail from "deb ..." repositories
92
echo ppa='"$ppa"' >> $file
94
echo 'for all in "$ppa"; do' >> $file
95
echo 'if [ "$installed" = "true" ]; then' >> $file
96
echo 'ep | sudo -S add-apt-repository -y --remove "$all"' >> $file
98
echo 'ep | sudo -S add-apt-repository -y "$all"' >> $file
101
echo 'ep | sudo -S apt-get update' >> $file
102
echo 'if [ "$?" -eq "0" ]; then' >> $file
103
echo 'echo "export PPASUCCESS=1" >> $sendfile' >> $file
105
echo 'echo "export PPASUCCESS=0" >> $sendfile' >> $file
109
echo 'if [ "$pkg" != "" ]; then' >> $file
110
echo 'if [ "$installed" = "true" ]; then' >> $file
111
echo 'ep | sudo -S apt-get remove -y $pkg' >> $file
113
echo 'ep | sudo -S apt-get install -y $pkg' >> $file
115
echo 'if [ "$?" -eq "0" ]; then' >> $file
116
echo 'echo "export PKGSUCCESS=1" >> $sendfile' >> $file
118
echo 'echo "export PKGSUCCESS=0" >> $sendfile' >> $file
124
echo "execute() {" >> $file
125
echo 'if [ "$tmpname" = "" ]; then' >> $file
126
echo 'tmpname="/dev/null/"' >> $file
128
echo "input='$input'" >> $file
129
echo 'if [ "$input" = "" ]; then' >> $file
132
echo "link='$link'" >> $file
133
echo 'if [ "$link" = "true" ]; then' >> $file
134
echo 'cd $tmpname' >> $file
135
echo 'echo "export LINK=1" >> $sendfile' >> $file
136
echo "mkdir downloaded" >> $file
137
echo "cd downloaded" >> $file
138
echo 'ep | wget "$input"' >> $file # the file needs to be downloaded as sudo, otherwise it downloads with ".1" extension
139
echo "if ! ls * &>/dev/null; then" >> $file
140
echo "cd .." >> $file
141
echo 'echo "export LINKSUCCESS=0" >> $sendfile' >> $file
142
echo "cd downloaded" >> $file
144
echo "cd .." >> $file
147
echo 'echo "export LINK=0" >> $sendfile' >> $file
148
echo 'cd $tmpname' >> $file
150
# confirm: echo "y" every 2 seconds
151
echo "confirm() {" >> $file
152
echo "while true; do" >> $file
153
echo "sleep 2" >> $file
154
echo 'echo "y"' >> $file
158
# put commands in the file (function)
159
# since we are on root account we need to export standard HOME and USER variables
160
echo "cmd() {" >> $file
161
echo "HOME=$HOME" >> $file
162
echo 'cd $HOME/' >> $file
163
echo "USER=$USER" >> $file
164
echo "$input" >> $file
167
# echo "y" (yes) and execute commands
168
echo "confirm | cmd" >> $file
170
echo 'if [ "$?" -eq "0" ]; then' >> $file
171
echo 'echo "export SUCCESS=1" >> $sendfile' >> $file
173
echo 'echo "export SUCCESS=0" >> $sendfile' >> $file
174
echo "killall zenity >/dev/null 2>&1" >> $file
180
source $file # using source instead of bash can load all variables to this file
182
# execute all functions
183
main_pass "ep | exesudo ppa_pkg; ep | exesudo execute"
185
# workaround for recognizing files
186
if [ "$link" = "true" ]; then
187
cd "$tmpname/downloaded/"
189
fullpath="$tmpname/downloaded/$dfile"
191
general_path="/usr/share/power-installer/general.sh"
193
if [ "$option" = "1" ]; then
196
elif [ "$option" = "2" ]; then
197
bash $general_path "$fullpath" "true" "false" "false" "false"
199
elif [ "$option" = "3" ]; then
200
bash $general_path "$fullpath" "false" "true" "false" "false"
202
elif [ "$option" = "4" ]; then
203
bash $general_path "$fullpath" "false" "false" "true" "false"
207
if [ "$option" = "0" ]; then
211
if [ "$EXT" == "deb" ]; then
213
debresult="$(echo '$?')"
217
if [ "$debresult" = "0" ]; then
220
sudo -S apt-get install -y -f
222
if [ "$?" -eq "0" ]; then
230
elif [ "$EXT" == "sh" ]; then
231
script_launch "bash $dfile"
237
elif [ "$EXT" == "run" ]; then
238
script_launch "sudo -S bash $dfile"
245
elif [ "$EXT" == "py" ]; then
246
script_launch "python $dfile"
254
allconst="$shconstant$runconstant$pyconstant"
255
if [[ $allconst == *1* ]]; then
261
echo -e "\nUSER SESSION: CLOSE\n"
263
# notify without sudo using external file
264
if [ -f "$sendfile" ]; then
267
if [ "$installed" = "true" ]; then
269
methodpkg="$methodppa"
272
methodpkg="installed"
275
if [ "$LINK" = "1" ]; then
276
if [ "$LINKSUCCESS" = "1" ]; then
277
notify-send "Power Installer" "The $type (linked) file has been $method successfully!" $endmsg
279
notify-send "Power Installer" "Something went wrong. Correct the link and try again." $errmsg
281
elif [ "$input" != "" ]; then
282
if [ "$SUCCESS" = "1" ]; then
283
notify-send "Power Installer" "All commands have been executed successfully!" $endmsg
285
notify-send "Power Installer" "Something went wrong. Check the syntax of your commands and try again." $errmsg
289
if [ "$ppa" != "" ]; then
290
if [ "$PPASUCCESS" = "1" ]; then
291
notify-send "Power Installer" "Succesfully $methodppa PPA's: $ppa!" $endmsg
293
notify-send "Power Installer" "Something went wrong. Check the syntax of repostiory and try again." $errmsg
297
if [ "$pkg" != "" ]; then
298
if [ "$PKGSUCCESS" = "1" ]; then
299
notify-send "Power Installer" "Succesfully $methodpkg packages: $pkg!" $endmsg
301
notify-send "Power Installer" "Something went wrong. Check name of the package and try again." $errmsg
305
notify-send "Power Installer" "Sorry, but I couldn't detect status of executed commands!" $errmsg
309
# remove tmp directory