deno.land / x / esm@v135_2 / scripts / deploy.sh
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143#!/bin/bash
init="no"host="$1"if [ "$host" == "--init" ]; then init="yes" host="$2"fi
port="80"tlsPort="0"workDir="/etc/esmd"cacheUrl=""fsUrl=""dbUrl=""origin=""npmRegistry=""npmToken=""authSecret=""
if [ "$init" == "yes" ]; then echo "Server options:" read -p "? http server port (default is ${port}): " v if [ "$v" != "" ]; then port="$v" fi read -p "? https(autocert) server port (default is disabled): " v if [ "$v" != "" ]; then tlsPort="$v" fi read -p "? workDir (ensure you have the r/w permission of it, default is '${workDir}'): " v if [ "$v" != "" ]; then workDir="$v" fi read -p "? cache (default is 'memory:main'): " v if [ "$v" != "" ]; then cacheUrl="$v" fi read -p "? file storage (default is 'local:\$workDir/storage'): " v if [ "$v" != "" ]; then fsUrl="$v" fi read -p "? database (default is 'postdb:\$workDir/esm.db'): " v if [ "$v" != "" ]; then dbUrl="$v" fi read -p "? server origin (optional): " v if [ "$v" != "" ]; then origin="$v" fi read -p "? npm registry (optional): " v if [ "$v" != "" ]; then npmRegistry="$v" fi read -p "? private token for npm registry (optional): " v if [ "$v" != "" ]; then npmToken="$v" fi read -p "? auth secret (optional): " v if [ "$v" != "" ]; then authSecret="$v" fi echo "---"fi
if [ "$host" == "" ]; then read -p "? deploy to (domain or IP): " v if [ "$v" != "" ]; then host="$v" fifi
if [ "$host" == "" ]; then echo "missing host" exitfi
user="root"read -p "? login user (default is 'root'): " vif [ "$v" != "" ]; then user="$v"fi
sshPort="22"read -p "? ssh port (default is 22): " vif [ "$v" != "" ]; then sshPort="$v"fi
scriptsDir=$(dirname $0)sh $scriptsDir/build.sh
if [ "$?" != "0" ]; then exitfi
echo "--- uploading..."scp -P $sshPort $scriptsDir/esmd $user@$host:/tmp/esmdif [ "$?" != "0" ]; then rm -f $scriptsDir/esmd exitfi
echo "--- installing..."ssh -p $sshPort $user@$host << EOF SVVer=\$(supervisorctl version) if [ "\$?" != "0" ]; then echo "error: missing supervisor!" exit fi echo "supervisor \$SVVer" SVCF=/etc/supervisor/conf.d/esmd.conf writeSVConfLine () { echo "\$1" >> \$SVCF } supervisorctl stop esmd rm -f /usr/local/bin/esmd mv -f /tmp/esmd /usr/local/bin/esmd chmod +x /usr/local/bin/esmd if [ "$init" == "yes" ]; then echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p if [ -f \$SVCF ]; then rm -f \$SVCF fi mkdir -p /etc/esmd echo "{\"port\":${port},\"tlsPort\":${tlsPort},\"workDir\":\"${workDir}\",\"cache\":\"${cacheUrl}\",\"storage\":\"${fsUrl}\",\"database\":\"${dbUrl}\",\"origin\":\"${origin}\",\"npmRegistry\":\"${npmRegistry}\",\"npmToken\":\"${npmToken}\",\"authSecret\":\"${authSecret}\"}" >> /etc/esmd/config.json writeSVConfLine "[program:esmd]" writeSVConfLine "command=/usr/local/bin/esmd --config=/etc/esmd/config.json" writeSVConfLine "directory=/tmp" writeSVConfLine "user=$user" writeSVConfLine "autostart=true" writeSVConfLine "autorestart=true" supervisorctl reload else supervisorctl start esmd fiEOF
rm -f $scriptsDir/esmd
Version Info