-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·183 lines (167 loc) · 5.07 KB
/
install
File metadata and controls
executable file
·183 lines (167 loc) · 5.07 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
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
#!/bin/bash
#
# install - install BotControl and, if not already present, jq
DESTDIR="/usr/local/BotControl"
if [[ $EUID -eq 0 ]]
then
SUDO=
else
SUDO=sudo
fi
SCRIPT_PATH="$(
cd "$(dirname "$0")"
pwd -P
)"
have_real=$(type -p realpath)
[ "${have_real}" ] && SCRIPT_PATH="$(realpath $SCRIPT_PATH)"
have_git=$(type -p git)
install_package() {
pkg="$1"
printf "\nInstalling ${pkg}\n"
darwin=
mach=$(uname -m)
platform=$(uname -s)
[ "${platform}" == "Darwin" ] && darwin=1
if [ "${darwin}" ]; then
have_brew=$(type -p brew)
[ "${have_brew}" ] && brew install ${pkg} > /dev/null 2>&1
else
have_apt=$(type -p apt)
if [ "${have_apt}" ]; then
${SUDO} apt install ${pkg} > /dev/null 2>&1
else
have_pac=$(type -p pacman)
if [ "${have_pac}" ]; then
${SUDO} pacman -S ${pkg} > /dev/null 2>&1
else
have_apk=$(type -p apk)
if [ "${have_apk}" ]; then
${SUDO} apk add ${pkg} > /dev/null 2>&1
else
have_dnf=$(type -p dnf)
if [ "${have_dnf}" ]; then
${SUDO} dnf install ${pkg} > /dev/null 2>&1
else
have_xbps=$(type -p xbps-install)
if [ "${have_xbps}" ]; then
${SUDO} xbps-install -S ${pkg} > /dev/null 2>&1
else
have_zypp=$(type -p zypper)
[ "${have_zypp}" ] && {
${SUDO} zypper install ${pkg} > /dev/null 2>&1
}
fi
fi
fi
fi
fi
fi
}
cd "${SCRIPT_PATH}"
[ -f botctrl ] || {
if [ -d BotControl ]; then
if [ -x BotControl/install ]; then
exec BotControl/install
exit 0
else
echo "ERROR: cannot locate botctrl. Exiting."
exit 1
fi
else
if [ "${have_git}" ]; then
git clone https://github.com/slbotcontrol/BotControl.git
exec BotControl/install
exit 0
else
echo "ERROR: cannot locate botctrl or git. Exiting."
exit 1
fi
fi
}
[ -d /usr/local/bin ] || ${SUDO} mkdir -p /usr/local/bin
${SUDO} cp botctrl /usr/local/bin/botctrl
${SUDO} chmod 755 /usr/local/bin/botctrl
${SUDO} rm -f /usr/local/bin/lifebot
${SUDO} ln -s /usr/local/bin/botctrl /usr/local/bin/lifebot
${SUDO} rm -f /usr/local/bin/corrade
${SUDO} ln -s /usr/local/bin/botctrl /usr/local/bin/corrade
MANDIR="${HOME}/.local/share/man"
for manpage in man/*/*
do
[ "${manpage}" == "man/*/*" ] && continue
dtmp=$(dirname "${manpage}")
dirm=$(basename "${dtmp}")
[ -d "${MANDIR}/${dirm}" ] || mkdir -p "${MANDIR}/${dirm}"
cp ${manpage} "${MANDIR}/${dirm}"
done
[ -f "${MANDIR}/${dirm}/botctrl.1" ] && {
rm -f "${MANDIR}/${dirm}/lifebot.1"
ln -s "${MANDIR}/${dirm}/botctrl.1" "${MANDIR}/${dirm}/lifebot.1"
rm -f "${MANDIR}/${dirm}/corrade.1"
ln -s "${MANDIR}/${dirm}/botctrl.1" "${MANDIR}/${dirm}/corrade.1"
}
[ -d bin ] || {
echo "ERROR: cannot locate bin/"
}
user=$(id -u)
group=$(id -g)
[ -d ${DESTDIR}/log ] || ${SUDO} mkdir -p ${DESTDIR}/log
${SUDO} touch ${DESTDIR}/log/cron.log
${SUDO} chown -R ${user}:${group} ${DESTDIR}/log
for lbb in bin/*
do
[ -d "${lbb}" ] && continue
[ "${lbb}" == "bin/*" ] && continue
bas=$(basename "${lbb}")
${SUDO} cp "${lbb}" ${DESTDIR}
${SUDO} chmod 755 ${DESTDIR}/${bas}
done
for scr in ${DESTDIR}/*
do
[ -d "${scr}" ] && continue
[ "${scr}" == "${DESTDIR}/*" ] && continue
bas=$(basename "${scr}")
${SUDO} rm -f /usr/local/bin/${bas}
${SUDO} ln -s ${scr} /usr/local/bin/${bas}
done
[ -d ${DESTDIR}/lib ] || ${SUDO} mkdir -p ${DESTDIR}/lib
for fun in bin/lib/*
do
[ "${fun}" == "bin/lib/*" ] && continue
bas=$(basename "${fun}")
if [ -d "${fun}" ]; then
${SUDO} cp -a "${fun}" ${DESTDIR}/lib
${SUDO} chmod 755 ${DESTDIR}/lib/${bas}
${SUDO} chmod 644 ${DESTDIR}/lib/${bas}/*
else
${SUDO} cp "${fun}" ${DESTDIR}/lib
${SUDO} chmod 644 ${DESTDIR}/lib/${bas}
fi
done
[ -d ${DESTDIR}/examples ] || ${SUDO} mkdir -p ${DESTDIR}/examples
for exm in examples/*
do
[ "${exm}" == "examples/*" ] && continue
bas=$(basename "${exm}")
if [ -d "${exm}" ]; then
${SUDO} cp -a "${exm}" ${DESTDIR}/examples
${SUDO} chmod 755 ${DESTDIR}/examples/${bas}
${SUDO} chmod 755 ${DESTDIR}/examples/${bas}/*
else
${SUDO} cp "${exm}" ${DESTDIR}/examples
${SUDO} chmod 755 ${DESTDIR}/examples/${bas}
fi
done
have_jq=$(type -p jq)
[ "${have_jq}" ] || install_package jq
printf "\n\nInstallation of the botctrl command and associated scripts is complete.\n"
printf "\nAdd /usr/local/bin to your execution PATH if it is not already included.\n"
printf "\nConfigure botctrl by adding and editing the file ${HOME}/.botctrl"
printf "\n\tSee ${SCRIPT_PATH}/BotControl/example_dot_botctrl"
printf "\n\tfor a template to use for this file.\n"
printf "\nView the botctrl manual with the command 'man botctrl'.\n"
printf "\nView the botctrl usage message with the command 'botctrl -h'.\n"
printf "\nView botctrl example invocations with the command 'botctrl -e'.\n"
printf "\nSee botctrl example scripts in ${DESTDIR}/examples/.\n"
printf "\nSee ${SCRIPT_PATH}/BotControl/crontab.in"
printf "\nfor example crontab entries to schedule bot activities.\n\n"