setup.sh 3.06 KB
Newer Older
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
#!/bin/bash
user="bdukes"
pass="bdukes"
email="briand@d3corp.com"
compname="DESKTOP-U526Q6KQ"
webpath="/mnt/c/Server"

#SETUP HOSTS FILE
#THIS SYMLINKS THE UBUNTU HOSTS FILE TO THE WINDOWS ONE SO ONLY HAVE TO ADD 1 ENTRY
rm /etc/hosts
ln -s /mnt/c/Windows/System32/drivers/etc/hosts /etc/hosts

#ADD COMPUTER NAME AND LOCALHOST TO HOSTS FILE
printf "127.0.1.1 $compname\n" >> /etc/hosts
printf "127.0.0.1 localhost\n" >> /etc/hosts

#INSTALL PACKAGES
apt-get -y install apache2 mysql-server-5.6 php5-mysql php5 libapache2-mod-php5 php5-mcrypt php5-curl curl php5-cli git

#INSTALL COMPOSER
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

#ENABLE MOD REWRITE
a2enmod rewrite

#ADD SERVER ROOT DIRECTORY TO APACHE.CONF FILE
printf "<Directory $webpath>\n\tOptions Indexes FollowSymLinks\n\tAllowOverride All\n\tRequire all granted\n</Directory>\n" >> /etc/apache2/apache2.conf

#ADD APACHE.CONF VARS
printf "ServerName localhost\n" >> /etc/apache2/apache2.conf
printf "AcceptFilter http none\n" >> /etc/apache2/apache2.conf

#WSL FIX
mkdir -p /run/lock

#SET APACHE TO RUN AS YOUR USER, THAT WAY THE OPS TOOL CAN DO COMPOSER UPDATE AS YOU
sed -i "s/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=$user/g" /etc/apache2/envvars
sed -i "s/export APACHE_RUN_GROUP=www-data/export APACHE_RUN_GROUP=$user/g" /etc/apache2/envvars

#SET APACHE PERMISSIONS FROM USER CHANGE
chown $user.$user /var/lock/apache2
chown $user.$user /var/log/apache2
chown -R $user.$user /var/log/apache2
chown -R $user.$user /var/lib/php5

#MAKE SURE COMPOSER HAS PROPER PERMISSIONS
chown -R $user.$user .composer
rm /home/$user/.composer/config.json

#THIS IS HACKY BUT ALLOWS SUDO COMMANDS TO BE RUN IN PHP EXEC WITHOUT NEEDING INPUT FOR PASSWORD
mkdir ~/.sudopass
echo "$pass" > ~/.sudopass/sudopass.secret
chown -R $user.$user ~/.sudopass

#ALLOWS AUTOSTART.SH SCRIPT TO WORK
printf "# Allow apache2 and mysql to start without a sudo password\n%%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service apache2 *\n%%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service mysql *\n" >> /etc/sudoers

#AUTOSTART.SH SCRIPT
printf "#!/bin/bash\nsudo service mysql start\nsudo service apache2 start\ncd ~\nbash" > /home/$user/autostart.sh
chmod +x /home/$user/autostart.sh
sudo chown $user.$user /home/$user/autostart.sh

#CLONE OPS TOOL AND SETUP CONFIG NEEDED FOR IT
cd $webpath && git clone https://git.d3corp.com/d3briand/localops.git Ops
sudo -H -u $user bash -c "cd $webpath/Ops && composer update"
printf "127.0.0.1 ops.dev\n" >> /etc/hosts
printf "<VirtualHost ops.dev:80>\nDocumentRoot $webpath/Ops/web\n</VirtualHost>" > /etc/apache2/sites-available/ops.dev.conf
a2ensite ops.dev

70
71
72
73
74
#CREATE OPS DB
service mysql start
mysql -u root -proot -e "CREATE DATABASE ops;"
mysql -u root -proot ops < $webpath/Ops/db.sql

75
76
77
#GENERATE SSH KEY
mkdir /home/$user/.ssh
chown -R $user.$user /home/$user/.ssh
78
ssh-keygen -f /home/$user/.ssh/id_rsa -t rsa -C "$email"
79
80
81
82
83
echo "setup finished\n"
echo "please paste this key into gitlab so the server can sync with it: "
cat ~/.ssh/id_rsa.pub

#YAY WE HOPEFULLY HAVE A SERVER WORKING