Skip to content

Instantly share code, notes, and snippets.

@shouya
Last active November 2, 2015 08:25
Show Gist options
  • Save shouya/19c963b55d2ae0a516a8 to your computer and use it in GitHub Desktop.
Save shouya/19c963b55d2ae0a516a8 to your computer and use it in GitHub Desktop.
poi setup script
#!/bin/bash
#
# This script belongs to shouya/poi project
# \bash <(wget -O - https://gist.githubusercontent.com/shouya/19c963b55d2ae0a516a8/raw/poi.sh)
#
set -e
EXTRA_APPS=(
emacs
mosh
)
if [ "$UID" != 0 ]; then
echo Please run as root.
exit
fi
sleep 1 && read -p "press [enter] to continue..."
echo Asking for config
[ -z "$username" ] && read -e -p "linux user: " username
[ -z "$hostname" ] && read -e -p "host name: " hostname
[ -z "$pubkey" ] && read -e -p "ssh pubkey: " pubkey
[ -z "$repo" ] && read -e -p "git repository: " repo
userhome=/home/$username
echo Setting up hostname
echo "$hostname" > /etc/hostname
echo 127.0.0.1 "$hostname" >> /etc/hosts
echo Setting up user
useradd -m -U -s /bin/bash "$username"
usermod -a -G sudo "$username"
chage -d 0 "$username"
ssh_dir=$userhome/.ssh
userdo() {
sudo -H -u "$username" "$@"
}
userdo mkdir -p $ssh_dir
userdo chmod 700 $ssh_dir
userdo ssh-keygen -f $ssh_dir/id_rsa -t rsa -N '' &>/dev/null
echo Please copy the public key printed below
echo "-------------------"
cat $ssh_dir/id_rsa.pub
echo "-------------------"
echo And add it to your github account, then press enter
read
echo Configuring login
echo "$pubkey" > $ssh_dir/authorized_keys
chmod 600 $ssh_dir/authorized_keys
chown $user:$user $ssh_dir/authorized_keys
echo Disabling ssh password login
usermod -p $(openssl passwd -crypt $(openssl rand -base64 6)) root
echo <<EOF >> /etc/ssh/sshd_config
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
EOF
service ssh restart
echo Installing packages
apt-key adv --keyserver hkp://pgp.mit.edu:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
codename=$(sh -c 'eval `cat /etc/lsb-release` && echo $DISTRIB_CODENAME')
echo deb https://apt.dockerproject.org/repo ubuntu-$codename main \
>> /etc/apt/sources.list.d/docker.list
apt-get update
apt-cache policy docker-engine
apt-get install -y curl git docker-engine
docker_compose_version=1.4.2
curl -L "https://github.com/docker/compose/"`
`"releases/download/$docker_compose_version/"`
`"docker-compose-`uname -s`-`uname -m`" \
> /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
curl -L "https://raw.githubusercontent.com/docker/"`
`"compose/$(docker-compose --version | awk 'NR==1{print $NF}')"`
`"/contrib/completion/bash/docker-compose" \
> /etc/bash_completion.d/docker-compose
echo Pulling git repository
ssh-keyscan -H github.com | userdo tee -a $ssh_dir/known_hosts &>/dev/null
cd "$userhome"
userdo git clone "$repo" poi
cd poi
echo First build
service docker restart
docker-compose build .
docker-compose up `cat services`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment