-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrap.sh
More file actions
99 lines (79 loc) · 3.1 KB
/
strap.sh
File metadata and controls
99 lines (79 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Bootstrap Install Script For Cactive™️ Managed VPS'
# Ensure we are running as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Update system apt list
echo "Updating apt list"
apt update -y > /dev/null
# Upgrade existing packages
echo "Upgrading existing packages"
apt upgrade -y > /dev/null
# Install required packages
echo "Installing required packages via apt"
apt install build-essential git gnupg python3 imagemagick nginx certbot python3-certbot-nginx neofetch figlet zsh -y > /dev/null
# Perform basic system configuration
echo "Performing basic system configuration"
# Request name of server
echo "What is the name of this server? (Amazon naming scheme)"
read -p "Server Name: " servername
# Request connections token
echo "What is the connections token for this server?"
read -p "Connections Token: " connectionstoken
# Request github username
echo "Github credentials to associate with this machine"
read -p "Username: " githubuser
read -p "Token: " githubtoken
git config --global user.name "$servername"
git config --global user.email "$servername@cactive.network"
git config --global credential.helper store
echo "https://$githubuser:$githubtoken@github.com" > ~/.git-credentials
# Set hostname
hostnamectl set-hostname $servername
# Set timezone
timedatectl set-timezone Australia/Melbourne
# Remove /etc/motd if it exists
if [ -f /etc/motd ]; then
rm /etc/motd
# Todo: Remove pam motd
fi
# Configure motd
if [ -f /opt ]; then
mkdir /opt
fi
mkdir /opt/meta
touch /opt/meta/ssh_motd
curl -s http://www.figlet.org/fonts/ogre.flf > /usr/share/figlet/ogre.flf
echo "\n-----------------------------------------------------------------------------\n" > /opt/meta/ssh_motd
figlet -f ogre $servername >> /opt/meta/ssh_motd
echo "\n-----------------------------------------------------------------------------\n" >> /opt/meta/ssh_motd
echo "This service is provided by Cactive.\n" >> /opt/meta/ssh_motd
echo "All actions performed on this machine are monitored, and misuse will be penalized.\n\n" >> /opt/meta/ssh_motd
sed -i 's/#Banner/Banner \/opt\/meta\/ssh_motd #/' /etc/ssh/sshd_config
sed -i 's/#PrintMotd/PrintMotd yes #/' /etc/ssh/sshd_config
# Install Node.js
echo "Installing Node.js"
curl -fsSL https://deb.nodesource.com/setup_19.x | bash - &&\
apt-get install -y nodejs
# Install Node.js packages
echo "Installing Node.js packages"
npm install -g pm2 > /dev/null && pm2 startup > /dev/null
npm install -g typescript > /dev/null
# Configure auth
echo "Configuring auth"
git clone https://github.com/CactiveNetwork/auth/ /opt/auth
cd /opt/auth
npm i -D > /dev/null && tsc -p . > /dev/null && npm link
cat "\nLOGIN_TOKEN=$connectionstoken\nVPS_NAME=$servername\n$SOCKET_LOCATION=wss://auth.cactive.network" > .env
cat "\nauth required pam_exec.so stdout log=/var/log/auth.log /opt/auth/auth" > /etc/pam.d/sshd
cd /tmp/bootstrap
git clone https://github.com/CactiveNetwork/bootstrap /tmp/bootstrap
cd /tmp/bootstrap
npm i > /dev/null
# Start rich bootstrap
node ./rich.js $githubtoken
# Restart processes
echo "Restarting processes"
systemctl restart sshd