-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·151 lines (134 loc) · 4.09 KB
/
setup.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
#!/bin/bash
set -e
PYTHON=python3
USER=$(whoami)
if [ "$USER" == "root" ]; then
USER=$1
if [ -z "$USER" ]; then
echo "Chrome is safer to run as normal user instead of 'root', so"
echo "run the script as a normal user (with sudo permission), "
echo "or specify the user: $0 <user>"
exit 1
fi
HOME=/home/$USER
else
SUDO=sudo
fi
function config() {
LOGDIR=/var/log/noip-renew/$USER
INSTDIR=/usr/local/bin
INSTEXE=$INSTDIR/noip-renew-$USER.sh
CRONJOB="0 1 * * * $INSTEXE $LOGDIR"
}
function install() {
OS=$(hostnamectl | grep -i "operating system")
echo "$OS"
case $OS in
*Arch?Linux*)
install_arch
;;
*)
install_debian
;;
esac
# Debian9 package 'python-selenium' does not work with chromedriver,
# Install from pip, which is newer
$SUDO $PYTHON -m pip install selenium
}
function install_arch(){
$SUDO pacman -Qi cronie > /dev/null || $SUDO pacman -S cronie
$SUDO pacman -Qi python > /dev/null || $SUDO pacman -S python
$SUDO pacman -Qi python-pip > /dev/null || $SUDO pacman -S python-pip
$SUDO pacman -Qi chromium > /dev/null || $SUDO pacman -S chromium
}
function install_debian(){
echo "Installing necessary packages..."
read -p 'Perform apt-get update? (y/n): ' update
if [ "${update^^}" = "Y" ]
then
$SUDO apt-get update
fi
$SUDO apt -y install chromium-chromedriver || \
$SUDO apt -y install chromium-driver || \
$SUDO apt -y install chromedriver
$SUDO apt -y install cron
#$SUDO apt -y install chromium-browser # Update Chromium Browser or script won't work.
$SUDO apt -y install $PYTHON-pip
}
function deploy() {
echo "Deploying the script..."
# Remove current installation first.
if ls $INSTDIR/*noip-renew* 1> /dev/null 2>&1; then
$SUDO rm $INSTDIR/*noip-renew*
fi
$SUDO mkdir -p $LOGDIR
$SUDO chown $USER $LOGDIR
$SUDO cp noip-renew.py $INSTDIR
$SUDO cp noip-renew-skd.sh $INSTDIR
$SUDO cp noip-renew.sh $INSTEXE
$SUDO chown $USER $INSTEXE
$SUDO chown $USER $INSTDIR/noip-renew-skd.sh
$SUDO chmod 700 $INSTEXE
noip
$SUDO crontab -u $USER -l | grep -v '/noip-renew*' | $SUDO crontab -u $USER -
($SUDO crontab -u $USER -l; echo "$CRONJOB") | $SUDO crontab -u $USER -
$SUDO sed -i 's/USER=/USER='$USER'/1' $INSTDIR/noip-renew-skd.sh
echo "Installation Complete."
echo "To change noip.com account details, please run setup.sh again."
echo "Logs can be found in '$LOGDIR'"
}
function noip() {
echo "Enter your No-IP Account details..."
read -p 'Username: ' uservar
read -sp 'Password: ' passvar
passvar=`echo -n $passvar | base64`
echo
$SUDO sed -i 's/USERNAME=".*"/USERNAME="'$uservar'"/1' $INSTEXE
$SUDO sed -i 's/PASSWORD=".*"/PASSWORD="'$passvar'"/1' $INSTEXE
}
function installer() {
config
install
deploy
}
function uninstall() {
$SUDO sed -i '/noip-renew/d' /etc/crontab
$SUDO rm $INSTDIR/*noip-renew*
read -p 'Do you want to remove all log files? (y/n): ' clearLogs
if [ "${clearLogs^^}" = "Y" ]
then
$SUDO rm -rf $LOGDIR
fi
}
PS3='Select an option: '
options=("Install/Repair Script" "Update noip.com account details" "Uninstall Script" "Exit setup.sh")
echo "No-IP Auto Renewal Script Setup."
select opt in "${options[@]}"
do
case $opt in
"Install/Repair Script")
installer
break
;;
"Update noip.com account details")
config
noip
echo "noip.com account settings updated."
break
;;
"Uninstall Script")
config
if ls $INSTDIR/*noip-renew* 1> /dev/null 2>&1; then
uninstall
echo "Script successfully uninstalled."
else
echo "Script is not installed."
fi
break
;;
"Exit setup.sh")
break
;;
*) echo "invalid option $REPLY";;
esac
done