forked from IDemixI/noip-renew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·137 lines (121 loc) · 3.72 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
#!/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
CRONJOB="30 0 * * * $USER $INSTEXE $LOGDIR"
}
function install() {
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
PYV=`python3 -c "import sys;t='{v[0]}{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";`
if [[ "$PYV" -lt "36" ]] || ! hash python3;
then
echo "This script requires Python version 3.6 or higher. Attempting to install..."
$SUDO apt-get -y install python3
fi
# Debian9 package 'python-selenium' does not work with chromedriver,
# Install from pip, which is newer
$SUDO apt -y install chromium-browser # Update Chromium Browser or script won't work.
$SUDO apt -y install $PYTHON-pip
$SUDO $PYTHON -m pip install selenium
}
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 sed -i '/noip-renew/d' /etc/crontab
echo "$CRONJOB" | $SUDO tee -a /etc/crontab
$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