goldilocks.js/install.sh

114 lines
3.5 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
source ./installer/sudo-cmd.sh
2017-11-07 00:30:14 +00:00
source ./installer/http-get.sh
2017-11-07 00:00:25 +00:00
### IMPORTANT ###
### VERSION ###
#my_app_ver="v1.1"
my_app_ver="installer-v2"
export NODE_VERSION="v8.9.0"
#################
2017-05-05 07:33:36 +00:00
my_app_name=goldilocks
my_app_pkg_name=com.daplie.goldilocks.web
my_app_dir=$(mktemp -d)
2017-11-07 00:00:25 +00:00
my_app_dist=$my_app_dir/opt/goldilocks/lib/node_modules/goldilocks/dist
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
#
echo "Installing to $my_app_dir (will be moved after install)"
mkdir -p $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
git clone $git_base $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
2017-11-07 00:30:14 +00:00
pushd $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
git checkout $my_app_ver
popd
mkdir -p "$my_app_dir/opt/$my_app_name"/{lib,bin,etc}
2017-11-07 00:34:35 +00:00
ln -s ../lib/node_modules/$my_app_name/bin/$my_app_name.js $my_app_dir/bin/goldilocks
ln -s ../lib/node_modules/$my_app_name/bin/$my_app_name.js $my_app_dir/bin/goldilocks.js
2017-11-07 00:30:14 +00:00
mkdir -p "$my_app_dir/etc/$my_app_name"
2017-11-07 00:00:25 +00:00
chmod 775 "$my_app_dir/etc/$my_app_name"
2017-11-07 00:30:14 +00:00
cat "$my_app_dist/etc/$my_app_name/$my_app_name.example.yml" > "$my_app_dir/etc/$my_app_name/$my_app_name.example.yml"
2017-11-07 00:00:25 +00:00
chmod 664 "$my_app_dir/etc/$my_app_name/$my_app_name.example.yml"
mkdir -p $my_app_dir/srv/www
mkdir -p $my_app_dir/var/www
mkdir -p $my_app_dir/var/log/$my_app_name
2017-05-08 19:34:39 +00:00
2017-11-07 00:00:25 +00:00
#
# Dependencies
#
echo $NODE_VERSION > /tmp/NODEJS_VER
export NODE_PATH=$my_app_dir/opt/goldilocks/lib/node_modules
2017-11-07 00:30:14 +00:00
export PATH=$PATH:$my_app_dir/opt/goldilocks/bin/
2017-11-07 00:00:25 +00:00
export NPM_CONFIG_PREFIX=$my_app_dir/opt/goldilocks
http_bash "https://git.coolaj86.com/coolaj86/node-installer.sh/raw/v1.1/install.sh"
my_npm="$NPM_CONFIG_PREFIX/bin/npm"
$my_npm install -g npm@4
pushd $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks/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 v1.2
git pull
popd
ln -s jquery.com com.jquery
mkdir -p jquery.com
pushd jquery.com
http_get 'https://code.jquery.com/jquery-3.1.1.js' jquery-3.1.1.js
popd
ln -s google.com com.google
mkdir -p google.com
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
ln -s well-known .well-known
mkdir -p well-known
pushd well-known
ln -snf ../oauth3.org/well-known/oauth3 ./oauth3
popd
2017-11-07 00:30:14 +00:00
echo "installed dependencies"
2017-11-07 00:00:25 +00:00
popd
2017-05-08 19:34:39 +00:00
2017-05-25 21:29:17 +00:00
2017-11-07 00:00:25 +00:00
#
# System Service
#
source ./installer/my-root.sh
echo "Pre-installation to $my_app_dir complete, now installing to $my_root/"
2017-11-07 00:00:25 +00:00
source ./installer/my-user-my-group.sh
echo "User $my_user Group $my_group"
2017-11-07 00:00:25 +00:00
$sudo_cmd chown -R $my_user:$my_group $my_app_dir
rsync -av $my_app_dir/ $my_root/
2017-11-07 00:30:14 +00:00
rsync -av --ignore-existing $my_app_dist/etc/goldilocks/goldilocks.yml $my_root/etc/goldilocks/goldilocks.yml
2017-11-07 00:00:25 +00:00
source ./installer/install-system-service.sh
# Change to admin perms
2017-11-07 00:00:25 +00:00
$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
2017-05-08 19:34:39 +00:00
# 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.
2017-11-07 00:00:25 +00:00
$sudo_cmd chmod -R ug+rwX /opt/$my_app_name
find /opt/$my_app_name -type d -exec $sudo_cmd chmod ug+s {} \;