Skip to content

Instantly share code, notes, and snippets.

@hami9x
Last active October 1, 2018 09:03
Show Gist options
  • Save hami9x/b0ab42745ef7f14361deae94562e1531 to your computer and use it in GitHub Desktop.
Save hami9x/b0ab42745ef7f14361deae94562e1531 to your computer and use it in GitHub Desktop.
Script to install Ubuntu 16.04 with node, caddy, postgres, redis, etc.
# install node
if [ -z $WITHOUT_NODE ]; then
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
apt install -y nodejs
npm i -g pm2 yarn http-server
fi
# install utilities
if [ -z $WITHOUT_UTILS ]; then
apt install htop
fi
if [ -z $WITHOUT_CADDY ]; then
source <(curl -s https://gist.github.com/youshi32/b0ab42745ef7f14361deae94562e1531/raw/0c778fe75215f0e84c20170e3774607dc2939967/install_caddy.sh)
fi
if [ -n $WITH_PG ]; then
source <(curl -s https://gist.github.com/youshi32/b0ab42745ef7f14361deae94562e1531/raw/2c580db6f1fd59c46259a65c54704e235f57ae1e/install_postgres.sh)
fi
if [ -n $WITH_REDIS ]; then
source <(curl -s https://gist.github.com/clzola/2b98f0b128d94811e43f86412dc375a1/raw/995efb596e09fd08e24a9b3bdc8555f5034f9bf9/install-redis.sh)
fi
mkdir -p /usr/local/bin
curl -L https://github.com/chilons/misc/blob/master/ubuntu/caddy?raw=true -o /usr/local/bin/caddy
chown root:root /usr/local/bin/caddy
chmod 755 /usr/local/bin/caddy
setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
groupadd -g 33 www-data
useradd \
-g www-data --no-user-group \
--home-dir /var/www --no-create-home \
--shell /usr/sbin/nologin \
--system --uid 33 www-data
sudo mkdir /var/www
sudo chown www-data:www-data /var/www
sudo chmod 755 /var/www
mkdir /etc/caddy
chown -R root:root /etc/caddy
mkdir /etc/ssl/caddy
chown -R root:www-data /etc/ssl/caddy
chmod 0770 /etc/ssl/caddy
cat << EOF > /etc/caddy/Caddyfile
localhost:80 {
gzip
proxy /test 127.0.0.1:1000 {
}
header / Access-Control-Allow-Origin *
}
EOF
chown root:root /etc/caddy/Caddyfile
chmod 644 /etc/caddy/Caddyfile
curl -L https://raw.githubusercontent.com/mholt/caddy/master/dist/init/linux-systemd/caddy.service -o /etc/systemd/system/caddy.service
chown root:root /etc/systemd/system/caddy.service
chmod 644 /etc/systemd/system/caddy.service
systemctl daemon-reload
systemctl enable caddy.service
systemctl start caddy.service
#!/bin/bash
export GO_VERSION=1.10
export GO_DOWNLOAD_URL=https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz
export GOPATH=/usr/local/lib/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
sudo mkdir ${GOPATH}
sudo chown ${USER} -R ${GOPATH}
sudo apt update --fix-missing && apt upgrade -y
sudo apt install --no-install-recommends -y gcc
wget "$GO_DOWNLOAD_URL" -O golang.tar.gz
tar -zxvf golang.tar.gz
sudo mv go ${GOROOT}
go version
cat << EOF >> ~/.bashrc
export GOPATH=/usr/local/lib/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
EOF
echo "installed go, please restart your terminal or reload your .bashrc"
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
#/usr/bin/env bash
add-apt-repository 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
sudo apt-key add -
apt-get update
apt-get install -y postgresql-10
systemctl enable postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment