-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·143 lines (116 loc) · 2.74 KB
/
install
File metadata and controls
executable file
·143 lines (116 loc) · 2.74 KB
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
#!/bin/bash
prg=`basename $0`
localCommand=install
declare -A folder=(
[bin]=/usr/sbin
[cfg]=/etc/noip
[systemd]=/etc/systemd/system
)
function info()
{
echo "INFO: $1"
}
function fail()
{
echo "ERROR: $1" 1>&2
exit 1
}
function usage() {
cat <<EOH
usage:
${prg} {[--install|-i|--uninstall|-u]}
--uninstall|-u : uninstall noip
--install|-i : install noip
EOH
}
function createFolders() {
for i in "${!folder[@]}"; do
mkdir -p ${folder[$i]}
done
}
function callerUserId() {
## identify user in a bash script called by sudo
## https://stackoverflow.com/questions/3522341/identify-user-in-a-bash-script-called-by-sudo/3522393
## Login name of the user who invoked sudo
## https://www.sudo.ws/man/sudo.man.html#SUDO_USER
local user=${SUDO_USER:-$(whoami)}
echo $user
}
function secureConfig() {
chown -R `callerUserId` ${folder[cfg]}
chmod -R 600 ${folder[cfg]}/*.netrc
}
function copyCfgFiles() {
for filepath in `ls etc/noip/*`; do
destFile=${folder[cfg]}/`basename $filepath`
[[ ! -e $destFile ]] && \
cp $filepath $destFile
done
}
function copyFiles() {
cp usr/sbin/* ${folder[bin]}
copyCfgFiles
cp -R etc/systemd/system/* ${folder[systemd]}
}
function install() {
rootCheck
createFolders
copyFiles
secureConfig
systemctl daemon-reload
postInstallInstructions
info "Done!"
}
function postInstallInstructions() {
cat <<END
DON'T FORGET to edit config file ${folder[cfg]}/noip.conf
Useful commands :
Start noip : sudo systemctl start noip
Check noip status and log : sudo systemctl status noip
Enable noip to start on boot : sudo systemctl enable noip
END
}
function removeUnmodifiedCfgFiles() {
for filepath in `ls etc/noip/*`; do
filename=`basename $filepath`
cmp $filepath ${folder[cfg]}/$filename > /dev/null 2>&1
bothEquals=$?
[[ -f ${folder[cfg]}/$filename && $bothEquals -eq 0 ]] && \
rm ${folder[cfg]}/$filename > /dev/null 2>&1
done
rmdir ${folder[cfg]} > /dev/null 2>&1
}
function uninstall() {
rootCheck
systemctl stop noip
systemctl disable noip
rm ${folder[bin]}/noip > /dev/null 2>&1
removeUnmodifiedCfgFiles
rm ${folder[systemd]}/noip.service > /dev/null 2>&1
systemctl daemon-reload
info "Done!"
}
function parseArgs() {
while [ $# -gt 0 ]; do
case "$1" in
--uninstall|-u)
localCommand=uninstall
;;
--install|-i)
localCommand=install
;;
*)
usage
exit 1
;;
esac
shift
done
}
function rootCheck() {
if [ "$EUID" -ne 0 ];then
fail "Please run as root"
fi
}
parseArgs $*
$localCommand