-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.sh
executable file
·117 lines (100 loc) · 4.41 KB
/
setup.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
#!/bin/sh
# write commit hash
if [ "$COMMIT_HASH" ]; then
echo "$COMMIT_HASH" >/etc/release
fi
# disable filesystem checking (no e2fsprogs)
sed -i 's/1$/0/' /etc/fstab
echo tmpfs /tmp tmpfs nosuid,nodev,noatime 0 0 >> /etc/fstab
# setup networking
echo 'flashpointvm' >/etc/hostname
cat << 'EOF' >/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
hostname flashpointvm
EOF
# setup required repos
echo 'https://dl-cdn.alpinelinux.org/alpine/edge/main' >/etc/apk/repositories
echo 'https://dl-cdn.alpinelinux.org/alpine/edge/community' >>/etc/apk/repositories
echo 'https://dl-cdn.alpinelinux.org/alpine/edge/testing' >>/etc/apk/repositories
apk update
apk add apache2 apache2-proxy php-apache2 fuse unionfs-fuse sudo libarchive libgcc libstdc++
sed -i 's/DEFAULT menu.c32/DEFAULT virt/g' /boot/extlinux.conf # boot directly into alpine
# install dev dependencies
apk add fuse-dev build-base git libarchive-dev
# install php packages
apk add php-json php-openssl php-session php-pdo php-pdo_sqlite php-simplexml php-xml
wget -O/tmp/vendor.tar https://github.com/FlashpointProject/svcomposer/releases/download/18c0ebd/vendor.tar
tar -xvf /tmp/vendor.tar -C /var/www/localhost --exclude='vendor/silexlabs/amfphp/doc'
# Install fuse-archive - maybe better than avfs?
git clone https://github.com/google/fuse-archive.git /tmp/fuse-archive
cd /tmp/fuse-archive
mkdir -p '/usr/local/sbin'
g++ -O3 src/main.cc `pkg-config libarchive fuse --cflags --libs` -o /usr/local/sbin/fuse-archive
# install fuzzyfs
git clone https://github.com/XXLuigiMario/fuzzyfs.git /tmp/fuzzyfs
cd /tmp/fuzzyfs
make && make install
# setup htdocs
mkdir /root/base
git clone https://github.com/FlashpointProject/svroot.git /tmp/svroot
cd /tmp/svroot
find . -type f -not -path '*/.git*' -exec cp --parents {} /root/base \;
chmod -R 755 /root/base
rm /var/www/localhost/htdocs/index.html
# setup apache
rc-update add apache2 default # run apache2 on startup
echo 'apache ALL=(ALL) NOPASSWD: ALL' >>/etc/sudoers
cp /mnt/httpd.conf /etc/apache2/httpd.conf
cp /mnt/mime.types /etc/apache2/mime.types
# setup gamezip service
mkdir /root/.avfs
cp /mnt/gamezip /etc/init.d
rc-update add gamezip default
# modify apache2 service dependencies
sed -i 's/need/need gamezip/' /etc/init.d/apache2
sed -i 's/after.*/after */' /etc/init.d/apache2
# Remove disabled apache modules.
# Move to the right directory.
cd /usr/lib/apache2/
# First, get a list of uncommented modules. (Syntax explanation later.)
cat /etc/apache2/httpd.conf /etc/apache2/conf.d/*.conf | grep 'LoadModule.*so$' | grep -v \# | cut -d '/' -f2 > /root/uncommented_apache_mods.txt
# We get a list of disabled modules from the commented LoadModule lines in httpd.conf
# Format: "LoadModule some_module modules/mod_some.so" => Module is at /usr/lib/apache2/mod_some.so
# The grep translates to: anything, then 'LoadModule', then anything, then 'so' at the end of the line.
# We want the part after the slash. Then we check that it's not also somewhere else, uncommented.
for i in $(cat /etc/apache2/httpd.conf /etc/apache2/conf.d/*.conf | grep 'LoadModule.*so$' | grep \# | cut -d '/' -f2); do
# Check that the module isn't also loaded uncommented somewhere else. (Looking at you, mod_negotiation.)
if ! grep -qxFe "$i" /root/uncommented_apache_mods.txt; then
echo Deleting apache module: /usr/lib/apache2/"$i"
# Using -f turns off error messages if a file isn't found.
rm -f /usr/lib/apache2/"$i"
fi
done
# Remove unneeded kernel modules.
# First, get a list of the needed ones.
cp /mnt/needed_mods.txt /root/needed_mods.txt
# Move to the right directory. We don't know kernel version, so we have to use a wildcard.
# If there is more than one kernel installed, we're done for.
cd /lib/modules/*/kernel/
# For each currently-installed module, (syntax modified from https://askubuntu.com/a/830791)
for i in $(find . -type f); do
# Check if that module is not on the list of needed ones.
# Btw, my list of needed ones might not be the bare minimum. I just stopped removing modules when it broke.
if ! grep -qxFe "$i" /root/needed_mods.txt; then
# If it's not on the list, remove it, and echo a nice message.
echo "Deleting module: $i"
rm "$i"
fi
done
# build tools aren't needed anymore, remove them.
apk del build-base fuse-dev git libarchive-dev
# cleanup
rm /root/needed_mods.txt
rm /root/uncommented_apache_mods.txt
rm -rf /tmp/* /var/cache/apk/*
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
echo Done!