Skip to content

Instantly share code, notes, and snippets.

@aubort
Last active June 4, 2020 06:57
Show Gist options
  • Save aubort/836888f8aaeeeff75024c87e9c9199f0 to your computer and use it in GitHub Desktop.
Save aubort/836888f8aaeeeff75024c87e9c9199f0 to your computer and use it in GitHub Desktop.
Install and Update all dependencies on a Cloud9 workspace to build a Static website with Hugo and host on Google App Engine
#!/bin/bash
# This script will update a new workspace created on Cloud9 IDE with the latest packages.
# In order to use it, create a update_workspace.sh file in your C9 Workspace and then make it executable using the command
# `touch update_workspace.sh && chmod +x update_workspace.sh`.
# Now you can open the updata_workspace.sh file and copy/paste this full script, save and close.
# Run the command `./update_workspace.sh` to execute the script.
#
# Alternatively you can use this command to download and make this script executable from github
# wget -O update_workspace.sh https://gist.githubusercontent.com/aubort/836888f8aaeeeff75024c87e9c9199f0/raw && chmod +x update_workspace.sh
#
# If you use the following command, it will automatically run the script after having created it
# wget -O update_workspace.sh https://gist.githubusercontent.com/aubort/836888f8aaeeeff75024c87e9c9199f0/raw && chmod +x update_workspace.sh && ./update_workspace.sh
# Variables declaration
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" # Google Cloud SDK
export GOLANG_PACKAGE="go1.8.1.linux-amd64.tar.gz" #Golang Package to install
#### Updating Golang to latest version ####
echo -e "\e[96mInstalling Golang\e[39m"
# Remove current version of Golang
sudo rm -rf /opt/go
# Download the latest version of Golang into /tmp/ directory
wget -P /tmp/ "https://storage.googleapis.com/golang/$GOLANG_PACKAGE"
# Install Go in the /opt/ directory
sudo tar -C /opt -xzf "/tmp/$GOLANG_PACKAGE"
# Remove the downloaded package from the /tmp directory
rm -rf "/tmp/$GOLANG_PACKAGE"
# Add the GOPATH definition to the profile
if ! grep -Fxq "export GOPATH=\$HOME/go" ~/.profile
then
echo "export GOPATH=\$HOME/go" >> ~/.profile
fi
# Add the GOPATH variable to the PATH, by adding a line to the .profile
if ! grep -Fxq "export PATH=\$PATH:\$GOPATH/bin" ~/.profile
then
echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
fi
# Reload .profile
source ~/.profile
#### Install Hugo using govendor ####
# for more details see here https://gohugo.io/overview/installing/
echo -e "\e[96mInstalling Hugo\e[39m"
# Install govendor
go get github.com/kardianos/govendor
# get Hugo
govendor get github.com/spf13/hugo
# Install Hugo
go install github.com/spf13/hugo
#### Install the Google Cloud SDK ####
# From Google's documentation https://cloud.google.com/sdk/downloads#apt-get
echo -e "\e[96mInstalling Google Cloud SDK\e[39m"
# Remove existing Google Cloud package to the source.list.d
sudo rm -rf /etc/apt/sources.list.d/google-cloud-sdk.list
# Add cloud SDK to the source
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
# Import the Google Cloud public key:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
# Update and install the Cloud SDK:
sudo apt-get update && sudo apt-get -y install google-cloud-sdk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment