forge (2664B)
1 #!/usr/bin/env bash 2 # 3 # ████ 4 # ░██░ █████ 5 # ██████ ██████ ██████ ██░░░██ █████ 6 # ░░░██░ ██░░░░██░░██░░█░██ ░██ ██░░░██ 7 # ░██ ░██ ░██ ░██ ░ ░░██████░███████ 8 # ░██ ░██ ░██ ░██ ░░░░░██░██░░░░ 9 # ░██ ░░██████ ░███ █████ ░░██████ 10 # ░░ ░░░░░░ ░░░ ░░░░░ ░░░░░░ 11 # 12 # author ▓▒ pyratebeard <root@pyratebeard.net> 13 # code ▓▒ https://git.pyratebeard.net/setup 14 # usage ▓▒ curl -L https://s.rum.sh/forge > forge && chmod +x forge && ./forge 15 16 # ▓▓▒░ vars 17 EMAIL="root@pyratebeard.net" 18 19 # ▓▓▒░ functions 20 function _echo() { printf "\n╓───── %s \n╙────────────────────────────────────── ─ ─ \n" "$1"; } 21 22 [ "$(id -u)" -ne 0 ] && { 23 _echo "got root?" >&2 24 exit 1 25 } 26 27 mkdir -p /run/forge 28 29 # ▓▓▒░ vault 30 _echo "enter domain" 31 [ $# -eq 1 ] && DOMAIN="tilde.gdn" || read DOMAIN 32 echo "$(hostname -s).${DOMAIN}" > /etc/hostname 33 34 # ▓▓▒░ locale 35 _echo "setting up locales" 36 locale-gen "en_US.UTF-8" 37 localectl set-locale en_US.UTF-8 38 dpkg-reconfigure -f noninteractive locales 39 systemctl daemon-reload 40 41 # ▓▓▒░ packages 42 _echo "installing runtime deps" 43 apt-get update && apt-get install -y ansible curl git sudo unzip 44 45 # ▓▓▒░ install collection for bitwarden lookup 46 ansible-galaxy collection install community.general 47 48 # ▓▓▒░ bitwarden 49 _echo "bitwarden setup" 50 curl -sL -o /run/forge/bw.zip "https://vault.bitwarden.com/download/?app=cli&platform=linux" && \ 51 unzip -d /usr/local/bin /run/forge/bw.zip 52 export BW_SESSION=$(bw login --apikey) 53 54 # ▓▓▒░ pull play 55 _echo "cloning repo" 56 git clone git://git.pyratebeard.net/setup.git /run/forge/setup && \ 57 pushd /run/forge/setup 58 59 _echo "let's play" 60 ansible-playbook playbook.yml 61 62 _echo "forge complete" 63 LIP=$(ip a s $(ip r | grep default | grep -oP '(?<=dev )[^ ]*') | awk '/inet\ / {print $2}' | awk -F/ '{print $1}') 64 RIP=$(dig -4 ip @dns.toys | awk '/^ip./ {print $NF}' | tr -d '"') 65 echo "local addr: $LIP" 66 echo "remote addr: $RIP" 67 68 _echo "cleanup" 69 bw logout 70 rm -rf /usr/local/bin/bw &>/dev/null 71 srm -drvl /usr/dwarf/.config/Bitwarden\ CLI &>/dev/null 72 srm -drvl /etc/ssh/hostca-* &>/dev/null 73 srm -dvrl /run/forge/ &>/dev/null 74 srm -dvrl "$0" &>/dev/null 75 reboot