Files
cloudron-box/scripts/initializeBaseUbuntuImage.sh
T

128 lines
2.6 KiB
Bash
Raw Normal View History

2014-07-03 17:10:53 -07:00
#!/bin/bash
set -v
2014-08-07 11:27:48 -07:00
set -e
USER_HOME=/home/yellowtent
2014-08-07 10:56:21 -07:00
SRCDIR=$USER_HOME/box
2014-07-03 17:10:53 -07:00
USER=yellowtent
echo "==== Create User $USER ===="
id $USER
if [[ $? -ne 0 ]]; then
rm -rf /home/$USER
useradd $USER -m
fi
2014-07-03 13:49:17 -07:00
2014-07-03 17:10:53 -07:00
# now exit on failure
2014-07-03 13:49:17 -07:00
set -e
echo "== Yellowtent base image preparation =="
export DEBIAN_FRONTEND=noninteractive
echo "==== Install project dependencies ===="
apt-get update
echo "==== Setup nodejs ===="
apt-get -y install nodejs npm
2014-07-03 17:10:53 -07:00
ln -sf /usr/bin/nodejs /usr/bin/node
2014-07-03 13:49:17 -07:00
echo "==== Setup git ===="
apt-get -y install git
echo "==== Setup docker ===="
# see http://idolstarastronomer.com/painless-docker.html
echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
apt-get update
apt-get -y install lxc-docker
ln -sf /usr/bin/docker.io /usr/local/bin/docker
# now add the user to the docker group
usermod $USER -a -G docker
2014-07-03 13:49:17 -07:00
echo "==== Setup nginx ===="
apt-get -y install nginx-full
service nginx stop
2014-07-10 22:51:34 -07:00
update-rc.d -f nginx remove
2014-07-03 13:49:17 -07:00
echo "==== Setup build-essential ===="
apt-get -y install build-essential
echo "==== Setup sqlite3 ===="
apt-get -y install sqlite3
echo "==== Setup supervisor ===="
apt-get -y install supervisor
2014-08-07 11:51:34 -07:00
service supervisor stop
update-rc.d -f supervisor remove
2014-07-03 13:49:17 -07:00
echo "== Box bootstrapping =="
echo "==== Cloning box repo ===="
2014-08-07 10:56:21 -07:00
if [ -d "$SRCDIR/.git" ]; then
echo "Updating the box repo"
2014-08-07 10:56:21 -07:00
cd $SRCDIR
2014-07-03 17:10:53 -07:00
git fetch
git reset --hard origin/master
else
echo "Cloning the box repo"
2014-08-07 10:56:21 -07:00
rm -rf $SRCDIR
mkdir -p $USER_HOME
cd $USER_HOME
2014-07-03 17:10:53 -07:00
git clone http://bootstrap:not4long@yellowtent.girish.in/yellowtent/box.git
cd box
2014-08-07 11:46:00 -07:00
git checkout -b master origin/master
2014-07-03 17:10:53 -07:00
fi
2014-07-31 17:48:30 -07:00
NPM_INSTALL="npm install --production"
rm -rf ./node_modules
eval $NPM_INSTALL
RET=$?
while [[ $RET -ne 0 ]]; do
echo "[EE] npm install failed, try again"
rm -rf ./node_modules
eval $NPM_INSTALL
RET=$?
done
2014-07-03 13:49:17 -07:00
echo "==== Make the user own his home ===="
2014-07-03 17:10:53 -07:00
chown $USER:$USER -R /home/$USER
2014-07-03 13:49:17 -07:00
echo "==== Install init script ===="
cat > /etc/init.d/bootstrap <<EOF
#!/bin/sh
2014-07-31 08:14:53 -07:00
LOG="/tmp/bootstrap"
2014-08-01 08:35:56 -07:00
exec 2>&1 1> \$LOG
echo "[II] Update to latest git revision..."
2014-08-07 10:56:21 -07:00
cd $SRCDIR
2014-08-07 11:23:54 -07:00
sudo -u $USER bash <<EOS
2014-07-31 08:14:53 -07:00
git fetch
git reset --hard origin/master
2014-08-07 11:23:54 -07:00
EOS
2014-08-01 08:35:56 -07:00
echo "[II] Done"
2014-07-31 08:14:53 -07:00
2014-08-01 08:35:56 -07:00
echo "[II] Run bootstrap script..."
2014-08-07 10:56:21 -07:00
/bin/bash $SRCDIR/scripts/bootstrap.sh https://appstore-dev.herokuapp.com
# /bin/bash $SRCDIR/scripts/bootstrap.sh https://nebulon.fwd.wf
2014-08-01 08:35:56 -07:00
echo "[II] Done"
2014-07-31 08:14:53 -07:00
2014-08-01 08:35:56 -07:00
echo "[II] Disable bootstrap init script"
2014-08-07 10:59:16 -07:00
update-rc.d bootstrap remove
2014-08-01 08:35:56 -07:00
echo "[II] Done"
2014-07-03 17:10:53 -07:00
EOF
chmod +x /etc/init.d/bootstrap
update-rc.d bootstrap defaults