Cloud9 / C9 SDK - Bash script which installs Cloud9 SDK, with Apache2 (rewrite, headers enabled), PHP7, MariaDB, Git, Composer, nodejs, npm and start on boot crontab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set envioroment, for cloud-init | |
set -e | |
export DEBIAN_FRONTEND=noninteractive | |
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin' | |
export HOME='/root' | |
# upon launch wait for internet connection | |
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 | |
# Set working vars, change these to suit | |
# | |
# Application Name | |
appname="Cloud9 SDK" | |
webroot="/var/www/html" | |
timezone="Europe/London" | |
# | |
# Cloud9 SDK | |
c9user="admin" | |
c9pass="admin" | |
# | |
# Database - root | |
rootdbpass=$(date +%s%N | sha256sum | base64 | head -c 32 ; echo) | |
# | |
# Database - app | |
dbname="app" | |
dbuser="app" | |
dbpass=$(date +%s%N | sha256sum | base64 | head -c 32 ; echo) | |
# | |
# | |
installed=`date +%Y-%m-%d`; | |
# Apache2 | |
write_info() { | |
if ! echo " | |
============================== | |
= $appname | |
= | |
= Installed Date: $installed | |
= | |
= Cloud9 SDK Basic Auth Credentials | |
= - User: $c9user | |
= - Pass: $c9pass | |
= - Webroot: $webroot | |
= | |
= MariaDB (mysql) Credentials | |
= - Root Password: $rootdbpass | |
= - | |
= - Database: $dbname | |
= - User: $dbuser | |
= - Password: $dbpass | |
" > $webroot/../install-info.txt | |
then | |
echo "There was an error when creating install-info.txt" | |
exit; | |
else | |
echo "File install-info.txt created." | |
fi | |
} | |
# Setup & Install Dependencys | |
setup_system() { | |
# | |
# set timezone | |
echo $timezone > /etc/timezone | |
dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>/dev/null | |
# | |
# Update System | |
sudo apt-get update | |
sudo apt-get -yq upgrade | |
# | |
# Install system packages | |
sudo apt-get -yq install curl wget | |
sudo apt-get -yq install unzip | |
sudo apt-get -yq install nano | |
sudo apt-get -yq install htop | |
sudo apt-get -yq install git | |
} | |
# Apache2 | |
install_apache() { | |
# | |
# Install Apache2 | |
sudo apt-get -yq install apache2 | |
# | |
# Enable apache modules | |
sudo a2enmod headers | |
sudo a2enmod rewrite | |
sudo awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}' /etc/apache2/apache2.conf > tmp.conf && mv tmp.conf /etc/apache2/apache2.conf | |
# | |
# Restart apache2 | |
# | |
sudo service apache2 restart | |
# | |
# Empty the webroot | |
if [ -f /var/www/html/index.html ]; then | |
sudo rm /var/www/html/index.html | |
fi | |
} | |
# Install PHP | |
install_php() { | |
# | |
# Import distibution variables | |
. /etc/lsb-release | |
# | |
# Is PHP5? | |
if [ $DISTRIB_RELEASE = "12.04" ] || [ $DISTRIB_RELEASE = "14.04" ] || [ $DISTRIB_RELEASE = "15.04" ]; then | |
phpver="5" | |
fi | |
# | |
# Is PHP7? | |
if [ $DISTRIB_RELEASE = "16.04" ] || [ $DISTRIB_RELEASE = "16.10" ] || [ $DISTRIB_RELEASE = "17.04" ] || [ $DISTRIB_RELEASE = "17.10" ]; then | |
phpver="7" | |
fi | |
# | |
# Is PHP7.2? | |
if [ $DISTRIB_RELEASE = "18.04" ] || [ $DISTRIB_RELEASE = "18.10" ]; then | |
phpver="7.2" | |
fi | |
# | |
# Install PHP5 | |
if [ "$phpver" = "5" ]; then | |
# | |
echo "Installing PHP5.5.9" | |
sudo apt-get -yq install php5 php5-cli | |
sudo apt-get -yq install php5-{curl,gd,mcrypt,json,mysql,sqlite} | |
# | |
sudo apt-get -yq install libapache2-mod-php5 | |
# | |
# enable mods | |
sudo php5enmod mcrypt | |
fi | |
# | |
# Install PHP7 | |
if [ "$phpver" = "7" ]; then | |
# | |
echo "Installing PHP7.0" | |
sudo apt-get -yq install php7.0 php7.0-cli | |
sudo apt-get -yq install php7.0-{mbstring,curl,gd,mcrypt,json,xml,mysql,sqlite} | |
# | |
sudo apt-get -yq install libapache2-mod-php7.0 | |
fi | |
# | |
# Install PHP7.2 | |
if [ "$phpver" = "7.2" ]; then | |
# | |
echo "Installing PHP7.2" | |
sudo apt-get -yq install php7.2 php7.2-cli | |
sudo apt-get -yq install php7.2-{mbstring,curl,gd,json,xml,mysql,sqlite,sqlite3,opcache,zip} | |
# | |
sudo apt-get -yq install libapache2-mod-php7.2 | |
fi | |
} | |
# Install MariaDB | |
install_mariadb() { | |
# | |
# Preset Selections | |
sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $rootdbpass" | |
sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $rootdbpass" | |
# | |
# Install | |
sudo apt-get -yqq install mariadb-server | |
#sudo apt-get -yqq install libmariadbclient-dev | |
sudo apt-get -yqq install mariadb-client | |
# | |
sudo service mysql start | |
# | |
# Set root user password | |
sudo mysql -u root -p$rootdbpass -e "CREATE DATABASE $dbname /*\!40100 DEFAULT CHARACTER SET utf8 */;" | |
sudo mysql -u root -p$rootdbpass -e "CREATE USER $dbuser@'%' IDENTIFIED BY '$dbpass';" | |
sudo mysql -u root -p$rootdbpass -e "GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'%';" | |
sudo mysql -u root -p$rootdbpass -e "GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '$rootdbpass';" | |
sudo mysql -u root -p$rootdbpass -e "FLUSH PRIVILEGES;" | |
# | |
sudo service mysql restart | |
} | |
# Install composer (globally) | |
install_composer() { | |
# | |
# Install composer | |
sudo curl -sS https://getcomposer.org/installer | sudo php | |
sudo mv composer.phar /usr/local/bin/composer | |
sudo ln -s /usr/local/bin/composer /usr/bin/composer | |
} | |
# Install Node.js | |
install_nodejs() { | |
# | |
# Install nodejs | |
sudo apt -yq install nodejs nodejs-legacy npm | |
} | |
# Install Cloud9 SDK | |
install_cloud9() { | |
# | |
# Enter into parent webroot, as were going to install Cloud9 there | |
cd $webroot/.. | |
# | |
# Pull down cloud9 sdk | |
git clone git://github.com/c9/core.git .c9sdk --depth 1 | |
# | |
# Install cloud9 sdk | |
cd .c9sdk | |
./scripts/install-sdk.sh | |
# | |
# Add reboot cronjob to start c9 server. | |
crontab -l | { cat; echo "@reboot cd $webroot/../.c9sdk && ./server.js -p 8181 --listen 0.0.0.0 -a $c9user:$c9pass -w $webroot > /dev/null 2>&1"; } | crontab - | |
# | |
# Start Cloud9 SDK | |
#./server.js -p 8181 --listen 0.0.0.0 -a $c9user:$c9pass -w $webroot > /dev/null 2>&1 | |
} | |
# Install Application | |
#install_project() { | |
# # | |
# # Place install code here specific for the application | |
#} | |
# | |
# Main | |
# | |
main() { | |
# | |
setup_system | |
# | |
install_php | |
# | |
install_composer | |
# | |
install_apache | |
# | |
install_mariadb | |
# | |
install_nodejs | |
# | |
write_info | |
# | |
#install_project | |
# | |
install_cloud9 | |
echo "Install finished." | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment