This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathinstaller.sh
executable file
·623 lines (559 loc) · 17.3 KB
/
installer.sh
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
#!/bin/bash
# INFO: Please use Bash to run this Installer
#
# Bing-Desktop-Wallpaper-Changer
# BDWC Installer Copyright (C) 2017~ NKS (nks15)
#
#### Starts Startup task.
#### INFO: DO NOT EDIT!
####
## Variable definition
NAME=bing-desktop-wallpaper-changer
UPNAME=Bing-Desktop-Wallpaper-Changer
STNAME=BDWC
TERMNAME=bingwallpaper
LINKTO=/usr/bin
AUTOSTART=$HOME/.config/autostart
## BDWC variable definition
BDWC_LICENSE=$PWD/LICENSE
BDWC_README=$PWD/README.md
## BDWC Installer variable definition
INSTALLER_VERSION="v3.3.1-release"
INSTALLER_FULL_NAME="$STNAME Installer $INSTALLER_VERSION"
INSTALLER_NAME="$STNAME Installer"
INSTALLER_ICONS="$(ls $PWD/icon | sed 's/.svg//g' | sed -n -e '$!H;${H;g;s/\n/ /gp;}') None"
# For security reasons, Developer Mode has to be disabled automatically
INSTALLER_DEVELOPER_MODE=false
# Required to be installed in order to run main.py
# This list was in 'requirements.txt' before we merged into the Installer
INSTALLER_NEEDED_REQUIREMENTS="python-lxml python-bs4 python-gi python-gi-cairo"
# The system's Package Manager
# This is a dummy value and will make errors if not refreshed, so use detect_package_mgr later!
PACKAGE_MANAGER=unknown
# The Operating System
# This is a dummy value and will make errors if not refreshed, so use detect_os later!
OS=unknown
DISTRIBUTION=unknown
####
#### Ends Startup task.
####
#### Starts definition.
####
info_license() {
# Prints license
if [ "$1" != "--no-warning" ]; then
echo "!!!! WE DO NOT RECOMMEND VIEWING LICENSE IN HERE !!!!"
echo "!!!! PLEASE USE 'installer.sh --version' INSTEAD !!!!"
echo ""
fi
cat $BDWC_LICENSE
}
info_readme() {
# Prints readme
echo "!!!! WE DO NOT RECOMMEND VIEWING README IN HERE !!!!"
echo "!!!! PLEASE VIEW FROM THE GITHUB WEBSITE INSTEAD !!!!"
echo ""
cat $BDWC_README
}
info_main() {
# Prints main information
echo ""
echo "$UPNAME"
echo "$INSTALLER_FULL_NAME"
echo ""
echo "GitHub: <https://github.com/UtkarshGpta/bing-desktop-wallpaper-changer>"
echo "Contributors: <https://github.com/UtkarshGpta/bing-desktop-wallpaper-changer/network/members>"
echo ""
echo ""
}
info_help() {
# Prints help about installer and tasks
echo "Usage: installer.sh [OPTION]..."
echo " installer.sh [OPTION=*]..."
echo ""
echo " --help display help about the Installer and tasks"
echo " --version display the Installer version"
echo " --license display LICENSE"
echo " --readme display README.md"
echo " --detect detect previous $UPNAME installation"
echo " --install install $UPNAME"
echo " --uninstall uninstall $UPNAME"
echo " --update update $UPNAME (needs git)"
echo " --execute run $UPNAME"
echo ""
echo " For developers:"
echo " --enable-devmode enables Developer Mode"
echo " --disable-devmode disables Developer Mode"
echo " --run-installer-command=* runs internal functions or shell commands"
echo ""
echo " * Note that Developer Mode is disabled automatically when the Installer starts (because of security reasons),"
echo " those who wish to run developer tasks will always have to put --enable-devmode in front of OPTION."
echo " For example, installer.sh --enable-devmode [DEVELOPER_OPTION/TASKS]"
echo ""
echo " * To directly run internal functions or shell commands, first you need to enable Developer Mode and use --run-installer-command."
echo " For example, installer.sh --enable-devmode --run-installer-command=[YOUR COMMAND]"
echo ""
echo " * For more information, please visit:"
echo " GitHub: <https://github.com/UtkarshGpta/bing-desktop-wallpaper-changer>"
echo ""
echo " * And you know what? #This_Installer_can_moo (Try to find the Easter Egg!)"
}
info_version() {
# Prints version info
echo "$INSTALLER_FULL_NAME"
echo "Installer Copyright (C) 2017~ NKS (nks15)"
echo ""
echo "$UPNAME"
info_license --no-warning
}
info_alert() {
# Prints alerts
echo "Installer: $1!"
echo "Try 'installer.sh $2' $3."
}
info_error() {
# Prints errors and exit
echo ""
echo "Installer: Error $1!"
exit 0
}
info_finish() {
# Prints finish text
echo ""
echo ""
echo "Finished!!"
echo ""
}
info_install() {
# Prints install text
echo ""
echo "Installing..."
echo ""
}
uninstall_main() {
# Completely removes/uninstalles Bing-Desktop-Wallpaper-Changer in this host system
if [ "$1" != "--no-echo-text" ]; then
echo "Completely removing Bing-Desktop-Wallpaper-Changer in $HOSTNAME..."
fi
sudo rm -rfv $HOME/$NAME
sudo rm -rfv /opt/$NAME
sudo rm -v $LINKTO/$TERMNAME
sudo rm -v $AUTOSTART/bdwc-autostart.desktop
sudo rm -v $AUTOSTART/bing-desktop-wallpaper-changer.desktop
sudo rm -v /usr/share/applications/bdwc-launcher.desktop
}
update_main() {
# Updates local BDWC using git
# method used: https://help.github.com/articles/syncing-a-fork/
#
# For Developers!
echo "Updating local $UPNAME..."
echo " Adding remote..."
git remote add upstream https://github.com/UtkarshGpta/bing-desktop-wallpaper-changer.git
echo " Added remote:"
git remote -v
echo " Fetching upstream repository..."
git fetch upstream
echo " Checkout local master branch..."
git checkout master
echo " Merging the changes..."
git merge upstream/master
# Finish
info_finish
echo "Now you can use 'installer.sh --install' to finish installing to $HOSTNAME"
}
detect_os() {
if [ "$1" == "--verbose" ]; then
echo "Detecting the Operating System..."
fi
# Detect the Operating System (In most cases, GNU/Linux)
OS=$(uname -o)
# Detect Linux distribution #####(BETA)#####
if [ $(cat /etc/issue | grep ' \n \l') != ""]; then
# /etc/issue method. will not work if the user modified it.
DISTRIBUTION=$(cat /etc/issue | sed 's|[\]||g' | sed -r 's|.{4}$||')
elif [ $(which lsb_release) != "" ]; then
# use lsb_release to find out the distro name.
DISTRIBUTION=$(lsb_release -d | sed 's|Description:||g' | sed 's|" "||g')
else
# Just say Linux [Kernel version] in order to prevent errors.
DISTRIBUTION="$(uname) $(uname -r)"
fi
if [ "$1" == "--verbose" ]; then
echo ""
echo "Operating System: $OS"
echo "Linux Distribution: $DISTRIBUTION"
fi
}
detect_package_mgr() {
# Detect the system's package manager
if [ "$1" == "--verbose" ]; then
echo "Detecting the Package manager..."
fi
if [ $(which apt-get) != "" ]; then
PACKAGE_MANAGER=apt-get
elif [ $(which pip) != "" ]; then
PACKAGE_MANAGER=pip
elif [ $(which yum) != "" ]; then
PACKAGE_MANAGER=yum
else
PACKAGE_MANAGER=unknown
fi
if [ "$1" == "--verbose" ]; then
echo ""
echo "Package manager: $PACKAGE_MANAGER"
fi
}
detect_previous_install() {
# Detect previous Bing-Desktop-Wallpaper-Changer installation
echo "Detecting previous installation..."
INSTALLER_IS_BDWC_INSTALLED_IN_A=$(ls $HOME | grep -i $NAME)
INSTALLER_IS_BDWC_INSTALLED_IN_B=$(ls /opt | grep -i $NAME)
INSTALLER_BDWC_INSTALLED=false
INSTALLER_BDWC_INSTALLED_PATH=""
if [ "$INSTALLER_IS_BDWC_INSTALLED_IN_A" != "" ]; then
INSTALLER_BDWC_INSTALLED=true
INSTALLER_BDWC_INSTALLED_PATH="$HOME/$NAME $INSTALLER_BDWC_INSTALLED_PATH"
elif [ "$INSTALLER_IS_BDWC_INSTALLED_IN_B" != "" ]; then
INSTALLER_BDWC_INSTALLED=true
INSTALLER_BDWC_INSTALLED_PATH="/opt/$NAME $INSTALLER_BDWC_INSTALLED_PATH"
fi
if [ "$INSTALLER_BDWC_INSTALLED" == "true" ]; then
echo " Detected previous installation in:"
echo " $INSTALLER_BDWC_INSTALLED_PATH"
if [ "$1" == "--remove-detected" ]; then
echo ""
echo " Removing previous installations in order to prevent conflicts..."
uninstall_main --no-echo-text
fi
fi
}
find_error() {
# Find errors and alerts them
if [ "$(ls | grep LICENSE)" == "" ]; then
info_error "1 (License file not found)"
elif [ "$(ls | grep bin)" == "" ]; then
info_error "2 (Binary folder not found)"
elif [ "$PACKAGE_MANAGER" == unknown ]; then
info_error "3 (Unknown package manager. Please report to GitHub!)"
elif [ "$OS" == unknown ]; then
info_error "4 (Unknown operating system. Please report to GitHub!)"
elif [ "$DISTRIBUTION" == unknown ]; then
info_error "5 (Unknown Linux distribution. Please report to GitHub!)"
fi
}
easter_egg() {
# Easter Egg!
# Any new ideas is welcome
# * "fortune | cowsay" looks good too
if [ "$PACKAGE_MANAGER" == apt-get ]; then
apt-get moo
else
echo "Moooooooooooooo"
echo "Any new Easter Egg ideas is welcome"
fi
}
ask_sudo() {
# Asks user to grant Superuser permission
echo "Asking root(sudo) privilege..."
echo " $INSTALLER_NAME needs Superuser permissions to continue and run this task."
echo " Don't worry! I will never use Superuser permissions to do bad things!"
echo ""
# Check if root permission is granted
sudo echo " Root privilege status:"
INSTALLER_SUDO_PRIVILEGE=$(sudo id -u)
if [ $INSTALLER_SUDO_PRIVILEGE == 0 ]; then
echo " #Root!, User id = $INSTALLER_SUDO_PRIVILEGE"
else
info_error "4 (Root permission not granted)"
fi
}
ask_config() {
echo ""
echo "Asking configuration data..."
echo ""
echo ""
# Installation path
echo "Where do you want to install $UPNAME?"
echo " * Entering 'opt' or pressing Enter or leaving this blank will install in /opt/$NAME (recommended)"
echo " * Entering 'home' will install in $HOME/$NAME"
echo -n " Install $UPNAME in (opt/home)? : "
read answer
if echo "$answer" | grep -iq "^home" ;then
INSTALLPATH=$HOME/$NAME
INSTALLPATH_SMALL=$HOME
else
INSTALLPATH=/opt/$NAME
INSTALLPATH_SMALL=/opt
fi
# Symlink
echo ""
echo "Should I create $NAME symlink to $LINKTO/$TERMNAME so you could easily execute it?"
echo -n " Create symlink for easy execution, e.g. in Terminal (y/n)? : "
read answer
if echo "$answer" | grep -iq "^y" ;then
PYSYMLINK=true
else
PYSYMLINK=false
fi
# Desktop launcher
echo ""
echo "Should I create $NAME desktop launcher to the Application List/Dock/Panel/Menu/etc?"
echo "If you do so, you can launch and execute $NAME very easily by clicking the desktop icon (like Firefox or System Settings)."
echo -n " Create desktop launcher for easy execution, e.g. on the Desktop (y/n)? : "
read answer
if echo "$answer" | grep -iq "^y" ;then
DESKTOP=true
else
DESKTOP=false
fi
# Login autostart
echo ""
echo "Should $NAME needs to autostart when you log in? (Add in Startup Application)"
echo -n " Add in Startup Application (y/n)? : "
read answer
if echo "$answer" | grep -iq "^y" ;then
STARTUP=true
else
STARTUP=false
fi
# Icon
echo ""
if [ $DESKTOP == true ]; then
echo "Choose the icon for the Notification and the Desktop launcher..."
else
echo "Choose the icon for the Notification..."
fi
echo " * Operating System: $OS | Linux Distribution: $DISTRIBUTION *"
echo ""
echo " %% Available Icons:$INSTALLER_ICONS %%"
echo ""
echo " ## PLEASE DO NOT PRESS ENTER or INPUT ANY UNNEEDED WORDS! ##"
echo " ## Please input the item you want in the exact form listed at (above) Available Icons. (Case sensitive!) ##"
echo " ## e.g. type *Bing* if you want Bing icon (recommended) or *None* to remove icon. ##"
echo ""
echo -n " Choose a Icon : "
read answer
ICON=$answer
# Check ICON value to see if it's correct
ICON_LIST=$(echo $INSTALLER_ICONS | sed 's/ /^?$*+!4#^/g')
ICON_INTEGRITY=$(echo $ICON_LIST | grep "$ICON")
if [ "$ICON" == "" ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
info_error "33 (Blank Icon value. Maybe you pressed the Enter key...)"
elif [ "$ICON_INTEGRITY" == "" ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
info_error "33-2 (Mistyped or incorrect Icon value. Please check what you have typed...)"
fi
}
install_packages() {
echo ""
echo "In order to prevent errors and run $UPNAME, we need to install some packages."
echo "Using $PACKAGE_MANAGER to install..."
echo ""
if [ $PACKAGE_MANAGER == apt-get ]; then
sudo $PACKAGE_MANAGER install $INSTALLER_NEEDED_REQUIREMENTS -y
else
sudo $PACKAGE_MANAGER install $INSTALLER_NEEDED_REQUIREMENTS
fi
}
install_system() {
echo ""
echo "Installing in $INSTALLPATH..."
if [ $INSTALLPATH_SMALL == $HOME ]; then
mkdir -v $INSTALLPATH
else
sudo mkdir -v $INSTALLPATH
fi
sudo cp -Rvf * $INSTALLPATH
# Restore main.py to original directory
sudo mv -vf $INSTALLPATH/bin/main.py $INSTALLPATH/main.py
}
install_set_files() {
echo ""
echo "Setting desktop files..."
if [ $PYSYMLINK == true ]; then
sudo sed -i "s|Exec=[/a-z/a-z]*|Exec=$LINKTO/$TERMNAME|g" "$INSTALLPATH/bin/bdwc-launcher.desktop"
sudo sed -i "s|Exec=[/a-z/a-z]*|Exec=$LINKTO/$TERMNAME|g" "$INSTALLPATH/bin/bdwc-autostart.desktop"
else
sudo sed -i "s|Exec=[/a-z/a-z]*|Exec=$INSTALLPATH/main.py|g" "$INSTALLPATH/bin/bdwc-launcher.desktop"
sudo sed -i "s|Exec=[/a-z/a-z]*|Exec=$INSTALLPATH/main.py|g" "$INSTALLPATH/bin/bdwc-autostart.desktop"
fi
echo "File setup done."
}
install_set_icon() {
echo ""
echo "Setting icons..."
if [ "$ICON" == "None" ]; then
echo "Icon set as $ICON"
sudo sed -i "s|app_notification = Notify.Notification.new(summary, str(body), icon)|app_notification = Notify.Notification.new(summary, str(body))|g" "$INSTALLPATH/main.py"
sudo sed -i "s|Icon=/dev/null||g" "$INSTALLPATH/bin/bdwc-launcher.desktop"
sudo sed -i "s|Icon=/dev/null||g" "$INSTALLPATH/bin/bdwc-autostart.desktop"
else
sudo cp -vf $INSTALLPATH/icon/$ICON.svg $INSTALLPATH/icon.svg && echo "Icon set as $ICON."
sudo sed -i "s|Icon=/dev/null|Icon=$INSTALLPATH/icon.svg|g" "$INSTALLPATH/bin/bdwc-launcher.desktop"
sudo sed -i "s|Icon=/dev/null|Icon=$INSTALLPATH/icon.svg|g" "$INSTALLPATH/bin/bdwc-autostart.desktop"
fi
}
install_symlink() {
if [ $PYSYMLINK == true ]; then
echo ""
echo "Creating symlink for easy execution..."
sudo rm -v $LINKTO/$TERMNAME
sudo ln -sv $INSTALLPATH/main.py $LINKTO/$TERMNAME
fi
}
install_add_desktop_launcher() {
if [ $DESKTOP == true ]; then
echo ""
echo "Adding $NAME Desktop Launcher..."
sudo mv -vf $INSTALLPATH/bin/bdwc-launcher.desktop /usr/share/applications/bdwc-launcher.desktop
sudo chmod +x /usr/share/applications/bdwc-launcher.desktop
fi
}
install_add_startup() {
if [ $STARTUP == true ]; then
echo ""
echo "Adding $NAME in Startup Application..."
sudo mkdir -pv $AUTOSTART
sudo cp -vf $INSTALLPATH/bin/bdwc-autostart.desktop $AUTOSTART/bdwc-autostart.desktop
fi
}
install_set_python_script() {
echo ""
echo "Setting scripts..."
sudo sed -i "s|/path/to/bing-desktop-wallpaper-changer|$INSTALLPATH|g" "$INSTALLPATH/main.py"
sudo sed -i "s|replace with the actual path to the bing-desktop-wallpaper-changer folder|setup done to $INSTALLPATH by $INSTALLER_FULL_NAME|g" "$INSTALLPATH/main.py"
}
install_remove_unneeded() {
# Clean up the locally installed BDWC
echo ""
echo "Removing unneeded things..."
sudo rm -rfv $INSTALLPATH/bin
sudo rm -rfv $INSTALLPATH/.git
sudo rm -v $INSTALLPATH/.gitignore
}
execute() {
echo ""
echo "Executing $NAME..."
if [ $PYSYMLINK == true ]; then
python $LINKTO/$TERMNAME
else
python $INSTALLPATH/main.py
fi
}
install_main() {
ask_sudo
echo ""
detect_previous_install --remove-detected
echo ""
ask_config
info_install
install_packages
install_system
install_set_files
install_set_icon
install_symlink
install_add_desktop_launcher
install_add_startup
install_set_python_script
install_remove_unneeded
execute
info_finish
}
####
#### Ends definition.
####
#### Starts normal tasks.
####
# Prints main info
info_main
# Detects package manager and operating system
# Environment detection is here (and not in install_main)
# because many tasks rely on this (like Easter Egg)
detect_os
detect_package_mgr
# Try to find errors
find_error
# Check if argument is smaller then 1
if [ "$#" -lt 1 ]; then
info_alert "no tasks to do" "--help" "for more information"
exit 0
fi
# Check arguments
for i in "$@"
do
case $i in
--help)
info_help
shift
;;
--version)
info_version
shift
;;
--license)
info_license
shift
;;
--readme)
info_readme
shift
;;
--detect)
detect_previous_install
shift
;;
--install)
install_main
shift
;;
--uninstall)
ask_sudo
echo ""
uninstall_main
shift
;;
--update)
update_main
shift
;;
--execute)
# Sets value
PYSYMLINK=true
# TODO: Find a good execute way that works on non-symlink location
execute
shift
;;
--enable-devmode)
INSTALLER_DEVELOPER_MODE=true
shift
;;
--disable-devmode)
INSTALLER_DEVELOPER_MODE=false
shift
;;
--run-installer-command=*)
FUNCTION_NAME="${i#*=}"
if [ $INSTALLER_DEVELOPER_MODE == true ]; then
echo "- Hello, Developer $USER on Host $HOSTNAME -"
echo "INSTALLER_DEVELOPER_MODE = $INSTALLER_DEVELOPER_MODE"
echo "FUNCTION_NAME (COMMAND) = $FUNCTION_NAME"
echo ""
$FUNCTION_NAME
else
info_alert "Developer Mode is disabled" "--enable-devmode" "to use developer tasks"
fi
shift
;;
*)
info_alert "unknown task" "--help" "for more information"
;;
esac
done
#### Ends normal tasks;
#
# BDWC Installer :)
#