tools- collection of tools for supernets sysadmins |
git clone git://git.acid.vegas/tools.git |
Log | Files | Refs | Archive |
services (2553B)
1 #!/bin/sh 2 # SuperNETs tool for Anope services - Developed by acidvegas (https://git.acid.vegas/supertools) 3 # requires cmake 4 5 ANOPE=$HOME/services 6 SOURCE=$HOME/services.source 7 8 for pkg in curl git jq make; do 9 if ! command -v $pkg > /dev/null; then 10 echo "error: missing required package '$pkg'" 11 exit 1 12 fi 13 done 14 15 case "$1" in 16 check) 17 CURRENT=$($ANOPE/bin/services -v | cut -d' ' -f1 | cut -d'-' -f2) 18 LATEST=$(curl -s https://api.github.com/repos/anope/anope/releases/latest | jq -r '.tag_name') 19 if [ "$CURRENT" != "$LATEST" ]; then 20 echo "new version available: $LATEST" 21 fi 22 ;; 23 24 deploy) 25 git clone --depth 1 https://github.com/supernets/anope.git "$SOURCE" 26 cd "$SOURCE" && ./Config -nointro -quick && cd build && make && make install && cd $HOME && rm -rf "$SOURCE" 27 if command -v crontab > /dev/null; then 28 (crontab -l; echo "*/5 * * * * $HOME/services/data/services.chk >/dev/null 2>&1") | crontab - 29 (crontab -l; echo "@reboot $HOME/services/bin/services") | crontab - 30 elif command -v systemctl > /dev/null; then 31 printf "[Unit]\nDescription=Anope Check Timer\n\n[Timer]\nOnBootSec=1min\nOnUnitActiveSec=5min\n\n[Install]\nWantedBy=timers.target" > "$HOME/.config/systemd/user/anope.timer" 32 printf "[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" 33 systemctl --user enable anope.timer && systemctl --user start anope.timer 34 else 35 echo "warning: cron/systemd not found on system! (reboot/restart timers not set)" 36 fi 37 for param in host port password seed; do 38 read -p "$param = " VALUE 39 sed -i "s/$param = \"REDACTED\"/$param = \"$VALUE\"/g" "$ANOPE/conf/services.conf" 40 done 41 $ANOPE/bin/services 42 ;; 43 44 update) 45 BACKUP="$ANOPE.backup" 46 mkdir "$BACKUP" && cp "$ANOPE/conf/services.conf" "$BACKUP" && cp "$ANOPE/data/anope.db" "$BACKUP" 47 pkill -9 services && rm -rf "$ANOPE" 48 git clone --depth 1 https://github.com/supernets/anope.git "$SOURCE" 49 cd "$SOURCE" && ./Config -nointro -quick && cd build && make && make install && cd $HOME && rm -rf "$SOURCE" 50 mv "$BACKUP/services.conf" "$ANOPE/conf/" 51 mv "$BACKUP/anope.db" "$ANOPE/data" 52 $ANOPE/bin/services 53 ;; 54 55 *) 56 echo "Usage: $0 {check|deploy|update}" 57 ;; 58 esac