Files
cloudron-box/scripts/bootstrap.sh
T

87 lines
2.3 KiB
Bash
Raw Normal View History

2014-07-31 08:14:53 -07:00
#!/bin/sh
set -e
echo "Box bootstrapping"
USER=yellowtent
2014-08-07 06:12:45 -07:00
SRCDIR=/home/$USER/box
2014-08-07 06:17:52 -07:00
BACKUP_DIR=/home/$USER/.yellowtent
2014-07-31 08:14:53 -07:00
# we get the appstore origin from the caller which is baked into the image
APP_SERVER_URL=$1
2014-07-31 08:14:53 -07:00
echo "==== Setup /etc/yellowtent ===="
mkdir -p /etc/yellowtent
echo "==== Sudoers file for app removal ===="
cat > /etc/sudoers.d/yellowtent <<EOF
2014-08-07 06:12:45 -07:00
Defaults!$SRCDIR/src/rmappdir.sh env_keep=HOME
$USER ALL=(root) NOPASSWD: $SRCDIR/src/rmappdir.sh
2014-07-31 08:14:53 -07:00
2014-08-07 06:12:45 -07:00
Defaults!$SRCDIR/src/reloadnginx.sh env_keep=HOME
$USER ALL=(root) NOPASSWD: $SRCDIR/src/reloadnginx.sh
2014-07-31 08:14:53 -07:00
EOF
echo "==== Setup yellowtent ===="
sudo -u $USER -H bash <<EOF
2014-08-07 06:12:45 -07:00
cd $SRCDIR
2014-08-01 08:35:56 -07:00
npm install --production
2014-08-07 11:31:17 -07:00
EOF
2014-07-31 08:14:53 -07:00
echo "==== Setup nginx ===="
2014-08-07 06:12:45 -07:00
cd $SRCDIR
2014-07-31 08:14:53 -07:00
killall nginx || echo "nginx not running" # condition makes killall not fatal to set -e
2014-08-07 06:22:12 -07:00
mkdir -p $BACKUP_DIR/nginx/applications
cp nginx/nginx.conf $BACKUP_DIR/nginx/nginx.conf
2014-08-07 11:55:53 -07:00
cp nginx/mime.types $BACKUP_DIR/nginx/mime.types
2014-08-20 00:34:02 -07:00
cp nginx/certificates.conf $BACKUP_DIR/nginx/certificates.conf
2014-08-07 06:22:12 -07:00
touch $BACKUP_DIR/nginx/naked_domain.conf
2014-07-31 08:14:53 -07:00
FQDN=`hostname -f`
sed -e "s/##ADMIN_FQDN##/admin-$FQDN/" -e "s|##SRCDIR##|$SRCDIR|" nginx/admin.conf_template > $BACKUP_DIR/nginx/applications/admin.conf
2014-07-31 08:14:53 -07:00
2014-08-20 01:54:39 -07:00
echo "==== Setup ssl certs ===="
CERTIFICATE_DIR=$BACKUP_DIR/nginx/cert
mkdir -p $CERTIFICATE_DIR
cd $CERTIFICATE_DIR
/bin/bash $SRCDIR/scripts/generate_certificate.sh US California 'San Francisco' Selfhost Cloudron `hostname -f` cert@selfhost.io .
tar xf cert.tar
chown $USER:$USER -R $BACKUP_DIR
2014-07-31 08:14:53 -07:00
echo "==== Setup supervisord ===="
supervisorctl shutdown || echo "supervisord not running"
rm -rf /etc/supervisor
mkdir -p /etc/supervisor
mkdir -p /etc/supervisor/conf.d
2014-08-07 06:12:45 -07:00
cp $SRCDIR/supervisor/supervisord.conf /etc/supervisor/
echo "Writing box supervisor config..."
2014-08-04 23:28:35 -07:00
cat > /etc/supervisor/conf.d/nginx.conf <<EOF
[program:nginx]
2014-08-07 17:00:18 -07:00
command=nginx -c $BACKUP_DIR/nginx/nginx.conf -p /var/log/nginx/
autostart=true
autorestart=true
2014-08-06 19:29:55 -07:00
redirect_stderr=true
EOF
echo "Done"
echo "Writing nginx supervisor config..."
2014-08-04 23:28:35 -07:00
cat > /etc/supervisor/conf.d/box.conf <<EOF
[program:box]
command=node app.js
autostart=true
autorestart=true
2014-08-05 11:34:07 -07:00
redirect_stderr=true
2014-08-07 06:12:45 -07:00
directory=$SRCDIR
user=yellowtent
2014-08-06 21:52:13 -07:00
environment=HOME="/home/yellowtent",USER="yellowtent",DEBUG="box*",APP_SERVER_URL=$APP_SERVER_URL
EOF
echo "Done"
2014-08-07 11:51:34 -07:00
update-rc.d supervisor defaults
2014-07-31 08:14:53 -07:00
/etc/init.d/supervisor start