From 37b600195cff4b90281798d77744c2cf0a453a66 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Wed, 28 Jul 2021 01:33:22 +0200 Subject: [PATCH] Installer --- README.md | 23 +-------- installer/ga_install.sh | 46 +++++++++++++++++ installer/ga_install_prereq.sh | 8 +++ installer/ga_setup.sh | 47 ++++++++++++++++++ installer/install.sh | 36 ++++++++++++++ installer/laravel-echo-server-install.sh | 13 +++++ installer/october_db_setup.sql | 9 ++++ installer/october_install_prereq.sh | 63 ++++++++++++++++++++++++ installer/october_setup.sh | 24 +++++++++ installer/subtest.htm | 25 ++++++++++ 10 files changed, 272 insertions(+), 22 deletions(-) create mode 100644 installer/ga_install.sh create mode 100644 installer/ga_install_prereq.sh create mode 100644 installer/ga_setup.sh create mode 100644 installer/install.sh create mode 100644 installer/laravel-echo-server-install.sh create mode 100644 installer/october_db_setup.sql create mode 100644 installer/october_install_prereq.sh create mode 100644 installer/october_setup.sh create mode 100644 installer/subtest.htm diff --git a/README.md b/README.md index d532ec2..882878b 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,3 @@ # Master -Add to ```repositories``` -``` -"ga.master": { - "type": "git", - "url": "https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-OctoberPlugins.git" -}, -"ga.graphql": { - "type": "git", - "url": "https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-GraphQL.git" -}, -"ga.schooling": { - "type": "git", - "url": "https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-Schooling.git" -}, -"ga.fleet": { - "type": "git", - "url": "https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-Fleet.git" -} -``` - -Require -```"germanairlinesva/master": "dev-master"``` +Run ```installer/installer.sh``` to install on a fresh Ubuntu 20.04 \ No newline at end of file diff --git a/installer/ga_install.sh b/installer/ga_install.sh new file mode 100644 index 0000000..37754e0 --- /dev/null +++ b/installer/ga_install.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +repos="{ + \"ga.master\": { + \"type\": \"git\", + \"url\": \"https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-OctoberPlugins.git\" + }, + \"ga.graphql\": { + \"type\": \"git\", + \"url\": \"https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-GraphQL.git\" + }, + \"ga.schooling\": { + \"type\": \"git\", + \"url\": \"https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-Schooling.git\" + }, + \"ga.fleet\": { + \"type\": \"git\", + \"url\": \"https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-Fleet.git\" + } +}" +require="{ + \"germanairlinesva/master\": \"dev-master\" +}" +tmp=$(mktemp) + +cd /var/www/ga + +whiptail --msgbox "Adding repositories and require" 7 35 +cp composer.json composer.json.bak +jq ".require += $require | .repositories += $repos" composer.json > "$tmp" && mv "$tmp" composer.json +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not add GermanAirlines specific repositories and require" + exit 1 +fi + +whiptail --msgbox "Updating dependecies and migrating" 7 38 +composer update +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not install GermanAirlines plugins" + exit 1 +fi +php artisan october:migrate +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not migrate GermanAirlines plugins" + exit 1 +fi diff --git a/installer/ga_install_prereq.sh b/installer/ga_install_prereq.sh new file mode 100644 index 0000000..5d974bb --- /dev/null +++ b/installer/ga_install_prereq.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +whiptail --msgbox "Installing GA Prerequisites" 7 31 +apt install npm git jq +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not install GermanAirlines specific prerequisites" + exit 1 +fi diff --git a/installer/ga_setup.sh b/installer/ga_setup.sh new file mode 100644 index 0000000..47d0aec --- /dev/null +++ b/installer/ga_setup.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +tmp=$(mktemp) + +cd /var/www/ga + +whiptail --msgbox "Configuring broadcaster and lighthouse" 7 44 +cp .env .env.bak +awk '/BROADCAST_DRIVER/{sub(/=.*/, "=redis"); print "LIGHTHOUSE_BROADCASTER=echo"; print "LIGHTHOUSE_CACHE_TTL=200"}{print $0}' .env > "$tmp" && mv "$tmp" .env +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not set GermanAirlines specific env variables" + exit 1 +fi + +cd config + +whiptail --msgbox "Adding BROADCAST_DRIVER env" 7 31 +cp broadcasting.php broadcasting.php.bak +sed "s/'default' => 'pusher',/'default' => env('BROADCAST_DRIVER', 'pusher'),/" broadcasting.php > "$tmp" && mv "$tmp" broadcasting.php +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not patch broadcasting config" + exit 1 +fi + +cd .. + +whiptail --msgbox "Linking graphs directory" 7 28 +mkdir graphql +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not add graphql directory" + exit 1 +fi +cd graphql +ln -s ../plugins/germanairlinesva/graphql/graphs +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not link graphs directory" + exit 1 +fi + +cd .. + +whiptail --msgbox "Setting ownership" 7 21 +chown www-data -R . +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not set ownership to www-data" + exit 1 +fi diff --git a/installer/install.sh b/installer/install.sh new file mode 100644 index 0000000..9af017f --- /dev/null +++ b/installer/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +./october_install_prereq.sh +if [ $? != 0 ]; then + exit 1 +fi + +whiptail --msgbox "Generating databases" 7 24 +mysql < ./october_db_setup.sql +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not create databases" + exit 1 +fi + +./october_setup.sh +if [ $? != 0 ]; then + exit 1 +fi + +./ga_install_prereq.sh +if [ $? != 0 ]; then + exit 1 +fi +./ga_install.sh +if [ $? != 0 ]; then + exit 1 +fi +./ga_setup.sh +if [ $? != 0 ]; then + exit 1 +fi + +./laravel-echo-server-install.sh +if [ $? != 0 ]; then + exit 1 +fi diff --git a/installer/laravel-echo-server-install.sh b/installer/laravel-echo-server-install.sh new file mode 100644 index 0000000..31d506f --- /dev/null +++ b/installer/laravel-echo-server-install.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +whiptail --msgbox "Installing laravel-echo-server" 7 34 +npm i -g laravel-echo-server +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not install laravel-echo-server" + exit 1 +fi +laravel-echo-server init +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not initialize laravel-echo-server" + exit 1 +fi diff --git a/installer/october_db_setup.sql b/installer/october_db_setup.sql new file mode 100644 index 0000000..04ad75b --- /dev/null +++ b/installer/october_db_setup.sql @@ -0,0 +1,9 @@ +create database october; +create database germanairlinesva_fleet; +create database germanairlinesva_schooling; + +create user 'october'@'localhost' identified by '1582'; + +grant all on *.* to 'october'@'localhost'; + +flush privileges; diff --git a/installer/october_install_prereq.sh b/installer/october_install_prereq.sh new file mode 100644 index 0000000..fd8dc6e --- /dev/null +++ b/installer/october_install_prereq.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +tmp=$(mktemp) + +whiptail --msgbox "Installing LAMP + Redis" 7 27 +apt install apache2 libapache2-mod-php php mysql-server mysql-client php-mysql redis php-redis php-ctype php-curl php-xml php-fileinfo php-gd php-json php-mbstring php-zip +if [ $? != 0 ]; then + echo -e "\033[0;31mapt failed to run" + exit 1 +fi +a2enmod rewrite +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not enable mod_rewrite" + exit 1 +fi +systemctl restart apache2 +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not restart apache2" + exit 1 +fi + +whiptail --msgbox "Enabling overwrites for host" 7 32 +cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak +awk '//{f=1}f{sub(/None/, "All")}/<\/Directory>/{f=0}{print $0}' /etc/apache2/apache2.conf > "$tmp" && mv "$tmp" /etc/apache2/apache2.conf +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not modify apache2 con exit 1 +fig" + exit 1 +fi + +whiptail --msgbox "Secure MySQL Installation" 7 29 +mysql_secure_installation +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not secure MySQL installation" + exit 1 +fi + +whiptail --msgbox "Installing Composer" 7 23 +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not download composer setup" + exit 1 +fi +php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not verify composer setup" + exit 1 +fi +php composer-setup.php +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not run composer setup" + exit 1 +fi +php -r "unlink('composer-setup.php');" +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not remove composer setup" + exit 1 +fi +mv composer.phar /usr/local/bin/composer +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not install composer" + exit 1 +fi diff --git a/installer/october_setup.sh b/installer/october_setup.sh new file mode 100644 index 0000000..2abfdca --- /dev/null +++ b/installer/october_setup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +cd /var/www + +whiptail --msgbox "Fetching October" 7 20 +composer create-project october/october ga +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not create project" + exit 1 +fi + +cd ga + +whiptail --msgbox "Installing October" 7 22 +php artisan october:install +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not install october" + exit 1 +fi +php artisan october:migrate +if [ $? != 0 ]; then + echo -e "\033[0;31mCould not run migration" + exit 1 +fi diff --git a/installer/subtest.htm b/installer/subtest.htm new file mode 100644 index 0000000..fa92677 --- /dev/null +++ b/installer/subtest.htm @@ -0,0 +1,25 @@ +title = "SubTest" +layout = "default" +url = "/subtest" +== +aircraft_type_id = 1; + $ac->home_airport_id = 1; + $ac->registration = "D-".$this->RandomString(4); + $ac->name = $this->RandomString(); + $ac->save(); + + \Nuwave\Lighthouse\Execution\Utils\Subscription::broadcast('aircraft', $ac); +} +?> +==