goldilocks.js/install.sh

147 lines
4.4 KiB
Bash
Raw Normal View History

2017-05-05 05:43:39 +00:00
#!/bin/bash
2017-11-07 00:00:25 +00:00
set -e
set -u
2017-11-07 11:20:15 +00:00
my_tmp=$(mktemp -d)
2017-11-07 11:21:33 +00:00
my_app_name=goldilocks
my_app_pkg_name=com.daplie.goldilocks.web
2017-11-07 11:20:15 +00:00
2017-11-07 00:00:25 +00:00
### IMPORTANT ###
### VERSION ###
#my_app_ver="v1.1"
my_app_ver="installer-v2"
2017-11-07 11:09:01 +00:00
my_azp_oauth3_ver="v1.2"
2017-11-07 00:00:25 +00:00
export NODE_VERSION="v8.9.0"
#################
2017-11-07 11:09:01 +00:00
export NODE_PATH=$my_tmp/opt/$my_app_name/lib/node_modules
export PATH=$PATH:$my_tmp/opt/$my_app_name/bin/
export NPM_CONFIG_PREFIX=$my_tmp/opt/$my_app_name
my_npm="$NPM_CONFIG_PREFIX/bin/npm"
#################
2017-11-07 00:00:25 +00:00
2017-05-05 07:33:36 +00:00
2017-11-07 11:09:01 +00:00
my_app_dir=$my_tmp
my_app_dist=$my_tmp/opt/$my_app_name/lib/node_modules/$my_app_name/dist
2017-11-07 00:00:25 +00:00
git_base="https://git.daplie.com/Daplie/goldilocks.js.git"
installer_base="https://git.daplie.com/Daplie/goldilocks.js/raw/$my_app_ver"
#
# Install to tmp location, then move to /opt
#
2017-11-07 11:09:01 +00:00
echo "Installing to $my_tmp (will be moved after install)"
mkdir -p $my_tmp/opt/$my_app_name/lib/node_modules/$my_app_name
git clone $git_base $my_tmp/opt/$my_app_name/lib/node_modules/$my_app_name
pushd $my_tmp/opt/$my_app_name/lib/node_modules/$my_app_name
2017-11-07 00:30:14 +00:00
git checkout $my_app_ver
2017-11-07 00:00:25 +00:00
2017-11-07 11:09:01 +00:00
mkdir -p "$my_tmp/opt/$my_app_name"/{lib,bin,etc}
ln -s ../lib/node_modules/$my_app_name/bin/$my_app_name.js $my_tmp/opt/$my_app_name/bin/$my_app_name
ln -s ../lib/node_modules/$my_app_name/bin/$my_app_name.js $my_tmp/opt/$my_app_name/bin/$my_app_name.js
mkdir -p "$my_tmp/etc/$my_app_name"
chmod 775 "$my_tmp/etc/$my_app_name"
cat "$my_app_dist/etc/$my_app_name/$my_app_name.example.yml" > "$my_tmp/etc/$my_app_name/$my_app_name.example.yml"
chmod 664 "$my_tmp/etc/$my_app_name/$my_app_name.example.yml"
mkdir -p $my_tmp/srv/www
mkdir -p $my_tmp/var/www
mkdir -p $my_tmp/var/log/$my_app_name
2017-11-07 00:00:25 +00:00
2017-05-08 19:34:39 +00:00
2017-11-07 11:09:01 +00:00
#
# Helpers
#
source ./installer/sudo-cmd.sh
source ./installer/http-get.sh
2017-05-25 21:29:17 +00:00
2017-11-07 11:09:01 +00:00
#
# Dependencies
#
echo $NODE_VERSION > /tmp/NODEJS_VER
http_bash "https://git.coolaj86.com/coolaj86/node-installer.sh/raw/v1.1/install.sh"
$my_npm install -g npm@4
pushd $my_tmp/opt/$my_app_name/lib/node_modules/$my_app_name
$my_npm install
popd
pushd $my_tmp/opt/$my_app_name/lib/node_modules/$my_app_name/packages/assets
OAUTH3_GIT_URL="https://git.daplie.com/Oauth3/oauth3.js.git"
git clone ${OAUTH3_GIT_URL} oauth3.org || true
ln -s oauth3.org org.oauth3
pushd oauth3.org
git remote set-url origin ${OAUTH3_GIT_URL}
git checkout $my_azp_oauth3_ver
git pull
popd
mkdir -p jquery.com
ln -s jquery.com com.jquery
pushd jquery.com
http_get 'https://code.jquery.com/jquery-3.1.1.js' jquery-3.1.1.js
popd
mkdir -p google.com
ln -s google.com com.google
pushd google.com
http_get 'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js' angular.1.6.2.min.js
popd
mkdir -p well-known
ln -s well-known .well-known
pushd well-known
ln -snf ../oauth3.org/well-known/oauth3 ./oauth3
popd
echo "installed dependencies"
popd
2017-05-08 19:34:39 +00:00
2017-11-07 11:09:01 +00:00
#
# System Service
#
source ./installer/my-root.sh
echo "Pre-installation to $my_tmp complete, now installing to $my_root/ ..."
set +e
if type -p tree >/dev/null 2>/dev/null; then
#tree -I "node_modules|include|share" $my_tmp
tree -L 6 -I "include|share|npm" $my_tmp
else
ls $my_tmp
fi
set -e
source ./installer/my-user-my-group.sh
echo "User $my_user Group $my_group"
$sudo_cmd chown -R $my_user:$my_group $my_tmp
rsync -a $my_tmp/ $my_root/
rsync -a --ignore-existing $my_app_dist/etc/$my_app_name/$my_app_name.yml $my_root/etc/$my_app_name/$my_app_name.yml
source ./installer/install-system-service.sh
# Change to admin perms
$sudo_cmd chown -R $my_user:$my_group $my_root/opt/$my_app_name
$sudo_cmd chown -R $my_user:$my_group $my_root/var/www $my_root/srv/www
# make sure the files are all read/write for the owner and group, and then set
# the setuid and setgid bits so that any files/directories created inside these
# directories have the same owner and group.
$sudo_cmd chmod -R ug+rwX /opt/$my_app_name
find /opt/$my_app_name -type d -exec $sudo_cmd chmod ug+s {} \;
popd
2017-11-07 00:37:30 +00:00
2017-11-07 11:09:01 +00:00
rm -rf $my_tmp
2017-11-07 12:42:55 +00:00
echo ""
echo "$my_app_name installation complete!"
echo ""
echo "Restart: systemctl restart $my_app_name"
echo "Logs: journalctl -xefu $my_app_name"
echo "Config: /etc/$my_app_name/$my_app_name.yml"
echo ""
echo "Unistall: rm -rf /srv/$my_app_name/ /var/$my_app_name/ /etc/$my_app_name/ /opt/$my_app_name/ /var/log/$my_app_name/ /etc/systemd/system/$my_app_name.service"