-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
204 lines (180 loc) · 5.48 KB
/
install.sh
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/sh
alias() {
sudo mkdir /etc/nebula/
sudo mkdir /etc/nebula/core/
sudo mkdir /etc/nebula/core/logreader/
sudo mv ./.nebula /etc/nebula/
sudo mkdir -p /opt/nebula/bin/
sudo mv ./nebula /opt/nebula/bin/
sudo chmod +x /opt/nebula/bin/*
if ! grep -F "[FoxServers Nebula]" /etc/bash.bashrc; then
sudo /usr/bin/bash -c 'echo "#[FoxServers Nebula]
. /etc/nebula/.nebula" >> /etc/bash.bashrc'
else
echo "Already installed aliases for nebula"
fi
}
cleanup_download() {
sudo rm -rf /tmp/nebula/{*,.*}
}
cleanup_git_extras() {
sudo rm -rf /opt/nebula/*LICENSE
sudo rm -rf /opt/nebula/*README.md
}
create_folders() {
echo "Creating folder structure for app..."
sudo mkdir /opt/nebula/
sudo mkdir /opt/nebula/bin/
sudo mkdir /opt/nebula/core/
sudo mkdir /opt/nebula/logs/
sudo mkdir /opt/nebula/extensions/
echo "Creating folder structure for servers..."
sudo mkdir /srv/nebula/
echo "Done!"
}
init_python() {
echo "Initializing python for nebula core"
sudo python3 -m venv /opt/nebula/.venv
echo "Installing requirements..."
find /opt/nebula/ -type f -name "*requirements.txt" -exec sudo /opt/nebula/.venv/bin/pip install -r {} ';'
echo "Done!"
}
core_apt_install() {
echo "Updating apt packages..."
sudo apt update -y
sudo apt upgrade -y
echo "Installing samba..."
sudo apt install samba -y
echo "Installing python..."
sudo apt install python3 -y
sudo apt install python3-pip -y
sudo apt install python3-venv -y
echo "Installing docker-compose..."
sudo apt install docker-compose -y
echo "Done!"
}
get_core() {
core_apt_install
echo "Downloading Core..."
cd /tmp/nebula/
sudo curl -o nebula-core.tar.gz -L `curl -s https://api.github.com/repos/FoxServers/nebula-core/releases/latest | grep -oP '"tarball_url": "\K(.*)(?=")'`
echo "Installing Core..."
sudo tar -zvxf nebula-core.tar.gz --directory /opt/nebula/core/ --strip-components=1
cleanup_download
echo "Fixing permissions..."
sudo chmod +x /opt/nebula/core/bin/*
sudo chmod +x /opt/nebula/core/scripts/*
sudo chmod -x /opt/nebula/core/services/*.service
echo "Done!"
}
access_apt_install() {
echo "Updating apt packages..."
sudo apt update -y
sudo apt upgrade -y
echo "Installing python..."
sudo apt install python3 -y
sudo apt install python3-pip -y
sudo apt install python3-venv -y
echo "Done!"
}
get_access() {
access_apt_install
echo "Downloading Access..."
cd /tmp/nebula/
sudo curl -o nebula-access.tar.gz -L `curl -s https://api.github.com/repos/FoxServers/nebula-access/releases/latest | grep -oP '"tarball_url": "\K(.*)(?=")'`
echo "Installing Access..."
sudo mkdir -p /opt/nebula/extensions/access/
sudo tar -zvxf nebula-access.tar.gz --directory /opt/nebula/extensions/access/ --strip-components=1
cleanup_download
echo "Fixing permissions..."
sudo chmod +x /opt/nebula/extensions/access/bin/*
sudo chmod -x /opt/nebula/extensions/access/services/*.service
echo "Done!"
}
install_services() {
echo "Installing services..."
find /opt/nebula/ -type f -name "*.service" -exec sudo mv {} /etc/systemd/system/ ';'
find /etc/systemd/system/ -type f -name "nebula*.service" -exec sudo systemctl enable {} ';'
sudo systemctl daemon-reload
echo "Done!"
}
smb_pass() {
CURRENT_USER=$(whoami)
sudo adduser "$CURRENT_USER" smb
read -p "Enter your name [$CURRENT_USER]: " USER
USER="${USER:-$CURRENT_USER}"
echo "User $USER was selected..."
sudo smbpasswd -a "$USER"
echo "Updating folder permissions..."
sudo chmod -R g+rwx /srv/nebula/
sudo chown "$USER":smb /srv/nebula/
}
smb() {
echo "Backing up smb config..."
sudo cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak
echo "Creating server folder..."
sudo mkdir -p /srv/nebula/
sudo chmod a+rwx /srv/nebula/
echo "Editing smb config to include new folder..."
if ! grep -F "[FoxServers Nebula]" /etc/samba/smb.conf; then
sudo /usr/bin/bash -c 'echo "[FoxServers Nebula]
path = /srv/nebula
browseable = yes
guest ok = no
writeable = yes
read only = no
valid users = @smb" >> /etc/samba/smb.conf'
fi
echo "Updating firewall settings..."
sudo ufw allow samba
echo "Creating smb user..."
sudo addgroup smb && smb_pass
echo "Restarting smb service..."
sudo service smbd restart
echo "Done!"
}
# Check if yes flag has been passed to install all first-party extensions
case $1 in
-y|-Y)
yes=1
;;
*)
yes=0
;;
esac
# Prepare download location
sudo mkdir -p /tmp/nebula/ || cleanup_download
alias # Moves nebula alias to bashrc
cd /tmp/nebula/
# Build empty directories
create_folders
# Move config.json into nebula
sudo mv ./config.json /opt/nebula/
# Install Core (Not Optional)
get_core
# Install Access (Optional)
if [ $yes -eq 1 ]; then
get_access
else
read -p "Install Nebula Access Extension? (y/N): " access
access="${access:-N}"
case $access in
y|Y|-y|-Y)
get_access
;;
*)
echo "Skipping Access install..."
;;
esac
fi
### Add first-party extension installs below this line ###
### Add first party extension installs above this line ###
# Finish Installs
install_services
# Install python dependencies
init_python
# Create smb folder
smb
# Run cleanup scripts
cleanup_download
cleanup_git_extras