-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
159 lines (120 loc) · 3 KB
/
script.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
#!/bin/bash
set -eu
trap cleanup EXIT
#
# Wait for internet connection
wait_internet() {
echo "Waiting for network connection."
while [ 1 ]; do
if ping -q -c 1 -W 1 8.8.8.8 > /dev/null 2>&1; then
break;
fi
sleep 1
done
}
#
# Install initial dependencies
install_dependencies() {
# Update System
sudo apt-get update
# Install basic system packages
sudo apt-get -yq install zip php-cli curl git
# remove apache2 if already installed
sudo apt-get -yq --purge remove apache2
# Install nginx
sudo apt-get -yq install nginx
# remove index.nginx-debian.html
rm -f /var/www/html/*
}
#
# Install composer
install_composer() {
#
# install composer
sudo curl -sS https://getcomposer.org/installer | sudo php
# remove the 2.* version
sudo rm -f composer.phar
# download v1.10.19
sudo wget https://getcomposer.org/download/1.10.19/composer.phar
# add execute bit and move into place
sudo chmod +x composer.phar
sudo mv composer.phar /usr/local/bin/composer
# remove link
sudo rm -f /usr/bin/composer
sudo ln -s /usr/local/bin/composer /usr/bin/composer
}
#
# Install project with composer
install_project_git() {
# make webroot and move into it
mkdir -p /var/www/html && cd /var/www/html
# clone the repo
git clone [email protected]:wightsystems/conext.git .
# setup project
bash ./.api/files/setup.sh
}
#
# Install lxd
install_lxd() {
# remove apt based LXD
sudo apt-get -y remove lxd
#
sudo apt-get -y install zfsutils-linux
#
export PATH=/usr/bin:/bin:/snap/bin:$PATH
#
set -eo pipefail
# install snapd
sudo apt-get -y install snapd
# install lxd snap package
sudo snap install lxd
#
ln -s /snap/bin/lxc /usr/bin/lxc
#
sudo lxd waitready
# initialise lxd (make sure you allow lxd over network - or the console wont work)
sudo lxd init --auto --network-address 0.0.0.0 --network-port 8443 --storage-backend=dir
# check lxd group is added
if [ ! $(getent group lxd) ]; then
addgroup lxd
fi
# add www-data to lxd group (seeded by nginx)
sudo usermod -a -G lxd www-data
}
#
# Add www-data to sudoers so can run lxc commands
write_sudoers() {
#
cp /etc/sudoers /etc/sudoers.bak
cp /etc/sudoers /etc/sudoers.tmp
#
chmod 0640 /etc/sudoers.tmp
#
echo -e "\nwww-data ALL=(ALL:ALL) NOPASSWD: /usr/bin/lxc\nwww-data ALL=(ALL:ALL) NOPASSWD: /snap/bin/lxc\n" >> /etc/sudoers.tmp
#
chmod 0440 /etc/sudoers.tmp
#
mv /etc/sudoers.tmp /etc/sudoers
}
#
##
cleanup() {
#
rm -f script.sh
}
#
# Main
main() {
# Check is root user
if [[ $EUID -ne 0 ]]; then
echo "This project must be install with root user."
sudo su
fi
wait_internet
install_dependencies
install_lxd
write_sudoers
install_composer
install_project_git
}
main