tools/deploy/deploy-anope

40 lines
2.7 KiB
Bash
Executable File

#!/bin/sh
# SuperNETs tool for Anope deployment - Developed by acidvegas (https://git.acid.vegas/supertools)
ANOPE=$HOME/services
SOURCE=$HOME/services.source
[ $(command -v curl) ] && echo "error: missing required package 'curl'" && exit 1
[ $(command -v git) ] && echo "error: missing required package 'git'" && exit 1
[ $(command -v jq) ] && echo "error: missing required package 'jq'" && exit 1
[ $(command -v make) ] && echo "error: missing required package 'make'" && exit 1
if [ "$#" = '1' ]; then
if [ $1 = 'check' ]; then
CURRENT=$($ANOPE/bin/services -v | cut -d' ' -f1 | cut -d'-' -f2)
LATEST=$(curl -s https://api.github.com/repos/anope/anope/releases/latest | jq '.tag_name')
[ ! $CURRENT = $LATEST ] && echo "new version available: $LATEST"
elif [ $1 = 'deploy' ]; then
git clone --depth 1 https://github.com/supernets/anope.git $SOURCE
cd $SOURCE && $SOURCE/Config -nointro -quick && cd $SOURCE/build && make && make install && cd $HOME && rm -rf $SOURCE
if [ $(command -v crontab) ]; then
crontab -l | { cat; echo "*/5 * * * * $HOME/services/data/services.chk >/dev/null 2>&1"; } | crontab -
crontab -l | { cat; echo "@reboot $HOME/services/bin/services"; } | crontab -
elif [ $(command -v systemctl) ]; then
echo -e "[Unit]\nDescription=Anope Check Timer\n\n[Timer]\nOnBootSec=1min\nOnUnitActiveSec=5min\n\n[Install]\nWantedBy=timers.target" > $HOME/.config/systemd/user/anope.timer
echo -e "[Unit]\nDescription=Anope Check Service\n\n[Service]\nType=oneshot\nExecStart=$HOME/services/data/services.chk >/dev/null 2>&1" > $HOME/.config/systemd/user/anope.service
else
echo "warning: cron/systemd not found on system! (reboot/restart timers not set)"
fi
read -p "host = " HOST && sed -i 's/host = "REDACTED"/host = "$HOST"/g' $ANOPE/conf/services.conf
read -p "port = " PORT && sed -i 's/port = REDACTED/port = $PORT/g' $ANOPE/conf/services.conf
read -p "password = " PASSWORD && sed -i 's/password = "REDACTED"/password = "$PASSWORD"/g' $ANOPE/conf/services.conf
read -p "seed = " SEED && sed -i 's/seed = REDACTED/seed = $SEED/g' $ANOPE/conf/services.conf
$ANOPE/bin/services
elif [ $1 = 'update' ]; then
BACKUP=$ANOPE.backup
mkdir $BACKUP && cp $NAOPE/conf/services.conf $BACKUP && cp $ANOPE/data/anope.db $BACKUP
pkill -9 services && rm -rf $ANOPE
git clone --depth 1 https://github.com/supernets/anope.git $SOURCE
cd $SOURCE && $SOURCE/Config -nointro -quick && cd $SOURCE/build && make && make install && cd $HOME && rm -rf $SOURCE
mv $BACKUP/services.conf $ANOPE/conf/ && mv $BACKUP/anope.db $ANOPE/data
$ANOPE/bin/services
fi
fi