From 5fcecde56842db5137aa52fafb475e14864a3d7a Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sat, 26 Jun 2021 12:23:22 -0600 Subject: [PATCH] Install script --- install.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ jarvis.service | 15 ++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 install.sh create mode 100644 jarvis.service diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..778a67b --- /dev/null +++ b/install.sh @@ -0,0 +1,65 @@ +#!/bin/bash +if [ "$EUID" -ne 0 ]; then + sudo $0 + exit 0 +fi +echo Installing requirements... +if [ -f /etc/os-release ]; then + . /etc/os-release + VER=$VERSION_ID + ID=$ID +elif type lsb_release >/dev/null 2>&1; then + OS=$(lsb_release -si) + VER=$(lsb_release -sr) + ID=$ID +else + echo WARNING: Unknown OS. Please install tmux by hand. + echo This script may error during install. +fi + +if [ "$ID" -eq "ubuntu" ] || [ "$ID" -eq "debian" ]; then + apt update + apt install tmux python3 python3-pip -y +elif [ "$ID" -eq "arch" ] || [ "$ID" -eq "manjaro" ]; then + pacman -Sy tmux python python-pip +fi + +pip3 install -r requirements.txt + +if [ ! -d "/home/jarvis" ]; then + echo Creating user jarvis... + useradd -m jarvis +fi + +if [ ! -d "/home/jarvis/j.a.r.v.i.s." ]; then + echo Copying J.A.R.V.I.S. files... + mkdir -p /home/jarvis/j.a.r.v.i.s. + cp -r * /home/jarvis/j.a.r.v.i.s./ + chown -r jarvis:jarvis /home/jarvis/j.a.r.v.i.s. +fi + +echo Creating ssh config for updates... +sudo -u jarvis mkdir -p /home/jarvis/.ssh +sudo -u jarvis ssh-keygen -q -t ed25519 -n "j.a.r.v.i.s." -f /home/jarvis/.ssh/id_ed25519 +cat << 'EOF' >> /home/jarvis/.ssh/config +Host git.zevaryx.com + HostName git.zevaryx.com + Port 22 + User git + IdentityFile /home/jarvis/.ssh/id_ed25519 +EOF +chown jarvis:jarvis /home/jarvis/.ssh/config + +echo Give this key to your local admin: +cat /home/jarvis/.ssh/id_ed25519.pub + +if [ ! -f "/etc/systemd/system/jarvis.service" ]; then + echo Installing systemd service... + cp jarvis.service /etc/systemd/system/jarvis.service + systemctl daemon-reload +fi +echo Enabling J.A.R.V.I.S. +systemctl enable --now jarvis.service + +echo J.A.R.V.I.S. should now be online. +echo Connect to console using tmux -a jarvis diff --git a/jarvis.service b/jarvis.service new file mode 100644 index 0000000..7a4470c --- /dev/null +++ b/jarvis.service @@ -0,0 +1,15 @@ +[Unit] +Description=J.A.R.V.I.S. via tmux (detached) +Documentation=man:tmux(1) + +[Service] +User=jarvis +Group=jarvis +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/tmux new-session -d -s jarvis "/home/jarvis/j.a.r.v.i.s./run.py" +ExecStop=/usr/bin/tmux kill-server +KillMode = none + +[Install] +WantedBy=multiplexer.target