diff --git a/bin/install.sh b/bin/install.sh index 94d701d..902ec09 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -6,6 +6,9 @@ export PATH LANG="en_US.UTF-8" export LANG +MYPATH="/opt/bgpblist" +export MYPATH + if [ -s "/etc/os-release" ]; then . /etc/os-release if [ ${ID} != "debian" -a ${ID} != "ubuntu" ]; then @@ -34,16 +37,45 @@ export DEBIAN_FRONTEND trap "dpkg --configure -a" 1 2 3 9 11 15 echo "## installing tools" -ls -al /opt/bgpblist/ >/dev/null && exit 1 +ls -al ${MYPATH} >/dev/null && exit 1 apt-get -q -y install git iproute2 php-cli wget curl | grep -v -e "is already the newest version" +function sd_restart () { + systemctl restart bgpblacklist.service +} + +function sd_enable () { + systemctl enable bgpblacklist.service +} + +function sd_d_reload () { + systemctl daemon-reload +} + +function sd_copyunit () { + cp ${MYPATH}/etc/systemd/bgpblacklist.service /etc/systemd/system/bgpblacklist.service +} + +function bl_copy_conf () { + if [ ! -s ${MYPATH}/etc/config.ini ]; then + cp ${MYPATH}/etc/default/config.ini ${MYPATH}/etc/config.ini + fi +} + +function git_clone () { + git clone https://git.funil.de/sinuspl/bgpblist ${MYPATH} + if [ $? -gt 0 ]; then + echo "ERROR: could not clone" + exit 1 + fi +} + echo "## installing service" -mkdir -p /opt/bgpblist/ -git clone https://git.funil.de/sinuspl/bgpblist /opt/bgpblist || exit 1 -cp /opt/bgpblist/etc/default/config.ini /opt/bgpblist/etc/config.ini -cp /opt/bgpblist/etc/systemd/bgpblacklist.service /etc/systemd/system/bgpblacklist.service -systemctl daemon-reload -systemctl enable bgpblacklist.service -systemctl start bgpblacklist.service +mkdir -p ${MYPATH} +bl_copy_conf +sd_copyunit +sd_d_reload +sd_enable +sd_restart echo "*** DONE ***" diff --git a/bin/update.sh b/bin/update.sh index 5a318ad..1a56a9e 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -7,6 +7,7 @@ LANG="en_US.UTF-8" export LANG MYPATH="/opt/bgpblist" +export MYPATH MYUSER=$(whoami) if [ ${MYUSER} != "root" ]; then @@ -15,8 +16,20 @@ if [ ${MYUSER} != "root" ]; then exit 1 fi +function sd_restart () { + systemctl restart bgpblacklist.service +} + +function sd_d_reload () { + systemctl daemon-reload +} + +function sd_copyunit () { + cp ${MYPATH}/etc/systemd/bgpblacklist.service /etc/systemd/system/bgpblacklist.service +} + echo "*** START ***" cd ${MYPATH} 2>/dev/null \ - && ( git pull; cp /opt/bgpblist/etc/systemd/bgpblacklist.service /etc/systemd/system/bgpblacklist.service; systemctl daemon-reload; systemctl restart bgpblacklist.service ) \ + && ( git pull; sd_copyunit; sd_d_reload; sd_restart ) \ || ( echo "ERROR: could not change to dir" ) echo "*** DONE ***"