Skip to content

Instantly share code, notes, and snippets.

@alobato
Created June 5, 2018 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alobato/4d492e57112d3044fe5f96521f0bd360 to your computer and use it in GitHub Desktop.
Save alobato/4d492e57112d3044fe5f96521f0bd360 to your computer and use it in GitHub Desktop.
google_cloud_template.sh
#! /bin/bash
ln -sf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime
apt-get update
apt-get -y install build-essential
which nginx || apt-get -y install nginx
which mysql || (echo mysql-server-5.1 mysql-server/root_password password PASSWORD | debconf-set-selections \
&& echo mysql-server-5.1 mysql-server/root_password_again password PASSWORD | debconf-set-selections \
&& apt-get -y install mysql-server)
id -u deployer || (useradd -m -s /bin/bash deployer && echo "deployer ALL=(ALL) NOPASSWD: ALL" | EDITOR='tee -a' visudo)
runuser -l deployer -c 'cat /home/deployer/.ssh/id_rsa.pub ||(mkdir -p /home/deployer/.ssh && cd /home/deployer/.ssh && ssh-keygen -f id_rsa -t rsa -N "")'
runuser -l deployer -c 'cd /home/deployer && (/home/deployer/.nvm/versions/node/v9.11.1/bin/node -v || curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash)'
runuser -l deployer -c 'cd /home/deployer && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && (/home/deployer/.nvm/versions/node/v9.11.1/bin/node -v || nvm install 9.11.1) && (/home/deployer/.nvm/versions/node/v9.11.1/bin/pm2 -v || /home/deployer/.nvm/versions/node/v9.11.1/bin/npm install -g pm2)'
/usr/bin/nodes -v || ln -fs /home/deployer/.nvm/versions/node/v9.11.1/bin/node /usr/bin/node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment