WIP simpler installer

This commit is contained in:
AJ ONeal 2017-11-06 17:30:14 -07:00
parent 34ce5ed4ee
commit e0fe188846
6 changed files with 42 additions and 44 deletions

View File

@ -4,6 +4,7 @@ set -e
set -u set -u
source ./installer/sudo-cmd.sh source ./installer/sudo-cmd.sh
source ./installer/http-get.sh
### IMPORTANT ### ### IMPORTANT ###
### VERSION ### ### VERSION ###
@ -29,16 +30,17 @@ installer_base="https://git.daplie.com/Daplie/goldilocks.js/raw/$my_app_ver"
echo "Installing to $my_app_dir (will be moved after install)" echo "Installing to $my_app_dir (will be moved after install)"
mkdir -p $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks mkdir -p $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
git clone $git_base $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks git clone $git_base $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
mkdir -p $my_app_dir/opt/$my_app_name/{lib,bin,etc} pushd $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
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" git checkout $my_app_ver
popd
mkdir -p "$my_app_dir/opt/$my_app_name"/{lib,bin,etc}
mkdir -p "$my_app_dir/etc/$my_app_name"
chmod 775 "$my_app_dir/etc/$my_app_name" chmod 775 "$my_app_dir/etc/$my_app_name"
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"
chmod 664 "$my_app_dir/etc/$my_app_name/$my_app_name.example.yml" 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/srv/www
mkdir -p $my_app_dir/var/www mkdir -p $my_app_dir/var/www
mkdir -p $my_app_dir/var/log/$my_app_name mkdir -p $my_app_dir/var/log/$my_app_name
pushd $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks
git checkout $my_app_ver
popd
@ -47,6 +49,7 @@ popd
# #
echo $NODE_VERSION > /tmp/NODEJS_VER echo $NODE_VERSION > /tmp/NODEJS_VER
export NODE_PATH=$my_app_dir/opt/goldilocks/lib/node_modules export NODE_PATH=$my_app_dir/opt/goldilocks/lib/node_modules
export PATH=$PATH:$my_app_dir/opt/goldilocks/bin/
export NPM_CONFIG_PREFIX=$my_app_dir/opt/goldilocks export NPM_CONFIG_PREFIX=$my_app_dir/opt/goldilocks
http_bash "https://git.coolaj86.com/coolaj86/node-installer.sh/raw/v1.1/install.sh" http_bash "https://git.coolaj86.com/coolaj86/node-installer.sh/raw/v1.1/install.sh"
my_npm="$NPM_CONFIG_PREFIX/bin/npm" my_npm="$NPM_CONFIG_PREFIX/bin/npm"
@ -78,6 +81,7 @@ pushd $my_app_dir/opt/goldilocks/lib/node_modules/goldilocks/packages/assets
pushd well-known pushd well-known
ln -snf ../oauth3.org/well-known/oauth3 ./oauth3 ln -snf ../oauth3.org/well-known/oauth3 ./oauth3
popd popd
echo "installed dependencies"
popd popd
@ -93,7 +97,7 @@ echo "User $my_user Group $my_group"
$sudo_cmd chown -R $my_user:$my_group $my_app_dir $sudo_cmd chown -R $my_user:$my_group $my_app_dir
rsync -av $my_app_dir/ $my_root/ rsync -av $my_app_dir/ $my_root/
rsync -av --ignore-existing $my_app_dir/etc/goldilocks/goldilocks.yml $my_root/etc/goldilocks/goldilocks.yml rsync -av --ignore-existing $my_app_dist/etc/goldilocks/goldilocks.yml $my_root/etc/goldilocks/goldilocks.yml
source ./installer/install-system-service.sh source ./installer/install-system-service.sh
# Change to admin perms # Change to admin perms

View File

@ -2,19 +2,16 @@ set -u
my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist" my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist"
install_for_launchd() echo ""
{ echo "Installing as launchd service"
echo "" echo ""
echo "Installing as launchd service"
echo ""
# See http://www.launchd.info/
mkdir -p $(dirname "$my_app_dir/$my_app_launchd_service")
dap_dl "$installer_base/$my_app_launchd_service" "$my_app_dir/$my_app_launchd_service"
$sudo_cmd mv "$my_app_dir/$my_app_launchd_service" "$my_root/$my_app_launchd_service"
$sudo_cmd chown root:wheel "$my_root/$my_app_launchd_service"
$sudo_cmd chmod 0644 "$my_root/$my_app_launchd_service"
$sudo_cmd launchctl unload -w "$my_root/$my_app_launchd_service" >/dev/null 2>/dev/null
$sudo_cmd launchctl load -w "$my_root/$my_app_launchd_service"
echo "$my_app_name started with launchd" # See http://www.launchd.info/
} safe_copy_config "$my_app_dist/$my_app_launchd_service" "$my_root/$my_app_launchd_service"
$sudo_cmd chown root:wheel "$my_root/$my_app_launchd_service"
$sudo_cmd launchctl unload -w "$my_root/$my_app_launchd_service" >/dev/null 2>/dev/null
$sudo_cmd launchctl load -w "$my_root/$my_app_launchd_service"
echo "$my_app_name started with launchd"

View File

@ -3,21 +3,18 @@ set -u
my_app_systemd_service="etc/systemd/system/${my_app_name}.service" my_app_systemd_service="etc/systemd/system/${my_app_name}.service"
my_app_systemd_tmpfiles="etc/tmpfiles.d/${my_app_name}.conf" my_app_systemd_tmpfiles="etc/tmpfiles.d/${my_app_name}.conf"
install_for_systemd() echo ""
{ echo "Installing as systemd service"
echo "" echo ""
echo "Installing as systemd service"
echo ""
safe_copy_config "$my_app_dist/$my_app_systemd_service" "$my_root/$my_app_systemd_service" safe_copy_config "$my_app_dist/$my_app_systemd_service" "$my_root/$my_app_systemd_service"
safe_copy_config "$my_app_dist/$my_app_systemd_tmpfiles" "$my_root/$my_app_systemd_tmpfiles" safe_copy_config "$my_app_dist/$my_app_systemd_tmpfiles" "$my_root/$my_app_systemd_tmpfiles"
$sudo_cmd systemctl stop "${my_app_name}.service" >/dev/null 2>/dev/null $sudo_cmd systemctl stop "${my_app_name}.service" >/dev/null 2>/dev/null
$sudo_cmd systemctl daemon-reload $sudo_cmd systemctl daemon-reload
$sudo_cmd systemctl start "${my_app_name}.service" $sudo_cmd systemctl start "${my_app_name}.service"
$sudo_cmd systemctl enable "${my_app_name}.service" $sudo_cmd systemctl enable "${my_app_name}.service"
echo "$my_app_name started with systemctl, check its status like so:" echo "$my_app_name started with systemctl, check its status like so:"
echo " $sudo_cmd systemctl status $my_app_name" echo " $sudo_cmd systemctl status $my_app_name"
echo " $sudo_cmd journalctl -xe -u $my_app_name" echo " $sudo_cmd journalctl -xe -u $my_app_name"
}

View File

@ -2,7 +2,7 @@ safe_copy_config()
{ {
src=$1 src=$1
dst=$2 dst=$2
mkdir -p $(dirname "$dst") $sudo_cmd mkdir -p $(dirname "$dst")
if [ -f "$dst" ]; then if [ -f "$dst" ]; then
$sudo_cmd rsync -av "$src" "$dst.latest" $sudo_cmd rsync -av "$src" "$dst.latest"
# TODO edit config file with $my_user and $my_group # TODO edit config file with $my_user and $my_group
@ -22,11 +22,11 @@ safe_copy_config()
installable="" installable=""
if [ -d "$my_root/etc/systemd/system" ]; then if [ -d "$my_root/etc/systemd/system" ]; then
install_for_systemd source ./installer/install-for-systemd.sh
installable="true" installable="true"
fi fi
if [ -d "/Library/LaunchDaemons" ]; then if [ -d "/Library/LaunchDaemons" ]; then
install_for_launchd source ./installer/install-for-launchd.sh
installable="true" installable="true"
fi fi
if [ -z "$installable" ]; then if [ -z "$installable" ]; then
@ -35,5 +35,3 @@ if [ -z "$installable" ]; then
echo '(please file a bug with the output of "uname -a")' echo '(please file a bug with the output of "uname -a")'
echo "" echo ""
fi fi
install_service

View File

@ -1,5 +1,7 @@
if [ -n "$(type -p adduser)" ]; then if [ type -p adduser ]; then
$sudo_cmd adduser --home /opt/$my_app_name --gecos '' --disabled-password $my_app_name if [ -z "$(cat /etc/passwd | grep $my_app_name)" ]; then
$sudo_cmd adduser --home /opt/$my_app_name --gecos '' --disabled-password $my_app_name
fi
my_user=$my_app_name my_user=$my_app_name
my_group=$my_app_name my_group=$my_app_name
elif [ -n "$(cat /etc/passwd | grep www-data:)" ]; then elif [ -n "$(cat /etc/passwd | grep www-data:)" ]; then

View File

@ -1,5 +1,5 @@
# Not every platform has or needs sudo, gotta save them O(1)s... # Not every platform has or needs sudo, gotta save them O(1)s...
sudo_cmd="" sudo_cmd=""
if [ -n "$(type -p sudo)" ]; then if [ type -p sudo ]; then
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo" ((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
fi fi