2015-07-20 00:09:47 -07:00
#!/bin/bash
set -eu -o pipefail
readonly SETUP_WEBSITE_DIR = "/home/yellowtent/setup/website"
script_dir = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2016-12-29 19:17:31 -08:00
readonly box_src_dir = " $( realpath ${ script_dir } /..) "
2015-07-20 00:09:47 -07:00
readonly DATA_DIR = "/home/yellowtent/data"
2015-07-28 16:21:45 -07:00
readonly ADMIN_LOCATION = "my" # keep this in sync with constants.js
2015-07-20 00:09:47 -07:00
echo "Setting up nginx update page"
source " ${ script_dir } /argparser.sh " " $@ " # this injects the arg_* variables used below
2015-07-28 16:21:45 -07:00
# keep this is sync with config.js appFqdn()
admin_fqdn = $( [ [ " ${ arg_is_custom_domain } " = = "true" ] ] && echo " ${ ADMIN_LOCATION } . ${ arg_fqdn } " || echo " ${ ADMIN_LOCATION } - ${ arg_fqdn } " )
admin_origin = " https:// ${ admin_fqdn } "
2015-07-20 00:09:47 -07:00
# copy the website
rm -rf " ${ SETUP_WEBSITE_DIR } " && mkdir -p " ${ SETUP_WEBSITE_DIR } "
cp -r " ${ script_dir } /splash/website/ " * " ${ SETUP_WEBSITE_DIR } "
# create nginx config
2016-05-24 13:31:15 -07:00
readonly current_infra = $( node -e " console.log(require(' ${ script_dir } /../src/infra_version.js').version); " )
existing_infra = "none"
2016-05-30 19:45:59 -07:00
[ [ -f " ${ DATA_DIR } /INFRA_VERSION " ] ] && existing_infra = $( node -e " console.log(JSON.parse(require('fs').readFileSync(' ${ DATA_DIR } /INFRA_VERSION', 'utf8')).version); " )
2016-07-05 22:04:24 -05:00
if [ [ " ${ arg_retire_reason } " != "" || " ${ existing_infra } " != " ${ current_infra } " ] ] ; then
echo " Showing progress bar on all subdomains in retired mode or infra update. retire: ${ arg_retire_reason } existing: ${ existing_infra } current: ${ current_infra } "
2015-07-20 00:09:47 -07:00
rm -f ${ DATA_DIR } /nginx/applications/*
2016-12-29 19:17:31 -08:00
${ box_src_dir } /node_modules/.bin/ejs-cli -f " ${ script_dir } /start/nginx/appconfig.ejs " \
2016-07-14 14:01:25 +02:00
-O " { \"vhost\": \"~^(.+)\$\", \"adminOrigin\": \" ${ admin_origin } \", \"endpoint\": \"splash\", \"sourceDir\": \" ${ SETUP_WEBSITE_DIR } \", \"certFilePath\": \"cert/host.cert\", \"keyFilePath\": \"cert/host.key\", \"xFrameOptions\": \"SAMEORIGIN\" } " > " ${ DATA_DIR } /nginx/applications/admin.conf "
2015-07-20 00:09:47 -07:00
else
2016-05-30 19:45:59 -07:00
echo "Show progress bar only on admin domain for normal update"
2016-12-29 19:17:31 -08:00
${ box_src_dir } /node_modules/.bin/ejs-cli -f " ${ script_dir } /start/nginx/appconfig.ejs " \
2016-07-14 14:01:25 +02:00
-O " { \"vhost\": \" ${ admin_fqdn } \", \"adminOrigin\": \" ${ admin_origin } \", \"endpoint\": \"splash\", \"sourceDir\": \" ${ SETUP_WEBSITE_DIR } \", \"certFilePath\": \"cert/host.cert\", \"keyFilePath\": \"cert/host.key\", \"xFrameOptions\": \"SAMEORIGIN\" } " > " ${ DATA_DIR } /nginx/applications/admin.conf "
2015-07-20 00:09:47 -07:00
fi
2016-07-05 22:04:24 -05:00
if [ [ " ${ arg_retire_reason } " = = "migrate" ] ] ; then
2016-07-06 16:25:39 -05:00
echo " { \"migrate\": { \"percent\": \"10\", \"message\": \"Migrating cloudron. This could take up to 15 minutes.\", \"info\": ${ arg_retire_info } }, \"backup\": null, \"apiServerOrigin\": \" ${ arg_api_server_origin } \" } " > " ${ SETUP_WEBSITE_DIR } /progress.json "
2016-06-29 23:24:00 -05:00
else
echo '{ "update": { "percent": "10", "message": "Updating cloudron software" }, "backup": null }' > " ${ SETUP_WEBSITE_DIR } /progress.json "
fi
2015-07-20 00:09:47 -07:00
nginx -s reload