Skip to content

Commit 24a0cce

Browse files
committed
.
0 parents  commit 24a0cce

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# LXD Control Panel
2+
3+
**This is a private deployment script, you must first have your SSH deployment key setup before installing.**
4+
5+
## :arrow_forward: Install
6+
7+
```
8+
wget https://raw.githubusercontent.com/deploy-script/lxd-control-panel/master/script.sh && bash script.sh
9+
```

script.sh

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
trap cleanup EXIT
6+
7+
#
8+
# Wait for internet connection
9+
wait_internet() {
10+
echo "Waiting for network connection."
11+
while [ 1 ]; do
12+
if ping -q -c 1 -W 1 8.8.8.8 > /dev/null 2>&1; then
13+
break;
14+
fi
15+
sleep 1
16+
done
17+
}
18+
19+
#
20+
# Install initial dependencies
21+
install_dependencies() {
22+
# Update System
23+
sudo apt-get update
24+
25+
# Install basic system packages
26+
sudo apt-get -yq install zip php-cli curl git
27+
28+
# remove apache2 if already installed
29+
sudo apt-get -yq --purge remove apache2
30+
31+
# Install nginx
32+
sudo apt-get -yq install nginx
33+
34+
# remove index.nginx-debian.html
35+
rm -f /var/www/html/*
36+
}
37+
38+
#
39+
# Install composer
40+
install_composer() {
41+
#
42+
# install composer
43+
sudo curl -sS https://getcomposer.org/installer | sudo php
44+
45+
# remove the 2.* version
46+
sudo rm -f composer.phar
47+
48+
# download v1.10.19
49+
sudo wget https://getcomposer.org/download/1.10.19/composer.phar
50+
51+
# add execute bit and move into place
52+
sudo chmod +x composer.phar
53+
sudo mv composer.phar /usr/local/bin/composer
54+
55+
# remove link
56+
sudo rm -f /usr/bin/composer
57+
sudo ln -s /usr/local/bin/composer /usr/bin/composer
58+
}
59+
60+
#
61+
# Install project with composer
62+
install_project_git() {
63+
# make webroot and move into it
64+
mkdir -p /var/www/html && cd /var/www/html
65+
66+
# clone the repo
67+
git clone [email protected]:wightsystems/conext.git .
68+
69+
# setup project
70+
bash ./.api/files/setup.sh
71+
}
72+
73+
#
74+
# Install lxd
75+
install_lxd() {
76+
# remove apt based LXD
77+
sudo apt-get -y remove lxd lxd-client
78+
#
79+
sudo apt-get -y install zfsutils-linux
80+
#
81+
export PATH=/usr/bin:/bin:/snap/bin:$PATH
82+
83+
#
84+
set -eo pipefail
85+
86+
# install snapd
87+
sudo apt-get -y install snapd
88+
89+
# install lxd snap package
90+
sudo snap install lxd
91+
92+
#
93+
ln -s /snap/bin/lxc /usr/bin/lxc
94+
95+
#
96+
sudo lxd waitready
97+
98+
# initialise lxd (make sure you allow lxd over network - or the console wont work)
99+
sudo lxd init --auto --network-address 0.0.0.0 --network-port 8443 --storage-backend=dir
100+
101+
# check lxd group is added
102+
if [ ! $(getent group lxd) ]; then
103+
addgroup lxd
104+
fi
105+
106+
# add www-data to lxd group (seeded by nginx)
107+
sudo usermod -a -G lxd www-data
108+
}
109+
110+
#
111+
# Add www-data to sudoers so can run lxc commands
112+
write_sudoers() {
113+
#
114+
cp /etc/sudoers /etc/sudoers.bak
115+
cp /etc/sudoers /etc/sudoers.tmp
116+
117+
#
118+
chmod 0640 /etc/sudoers.tmp
119+
120+
#
121+
echo -e "\nwww-data ALL=(ALL:ALL) NOPASSWD: /usr/bin/lxc\nwww-data ALL=(ALL:ALL) NOPASSWD: /snap/bin/lxc\n" >> /etc/sudoers.tmp
122+
123+
#
124+
chmod 0440 /etc/sudoers.tmp
125+
126+
#
127+
mv /etc/sudoers.tmp /etc/sudoers
128+
}
129+
130+
#
131+
##
132+
cleanup() {
133+
#
134+
rm -f script.sh
135+
}
136+
137+
#
138+
# Main
139+
main() {
140+
# Check is root user
141+
if [[ $EUID -ne 0 ]]; then
142+
echo "This project must be install with root user."
143+
sudo su
144+
fi
145+
146+
wait_internet
147+
148+
install_dependencies
149+
150+
install_lxd
151+
152+
write_sudoers
153+
154+
install_composer
155+
156+
install_project_git
157+
}
158+
159+
main

0 commit comments

Comments
 (0)