update installer
This commit is contained in:
parent
eb9d95b5b1
commit
9828a19f8c
|
@ -6,6 +6,7 @@
|
|||
<string>WALNUT</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/bin/node</string>
|
||||
<string>/usr/local/bin/walnut</string>
|
||||
<string>--config</string>
|
||||
<string>/etc/walnut/walnut.yml</string>
|
||||
|
|
|
@ -27,7 +27,7 @@ Group=www-data
|
|||
|
||||
# Set a sane working directory, sane flags, and specify how to reload the config file
|
||||
WorkingDirectory=/srv/www
|
||||
ExecStart=/usr/local/bin/walnut --config=/etc/walnut/walnut.yml
|
||||
ExecStart=/usr/local/bin/node /usr/local/bin/walnut --config=/etc/walnut/walnut.yml
|
||||
ExecReload=/bin/kill -USR1 $MAINPID
|
||||
|
||||
# Limit the number of file descriptors and processes; see `man systemd.exec` for more limit settings.
|
||||
|
@ -46,7 +46,7 @@ ProtectSystem=full
|
|||
# … except TLS/SSL, ACME, and Let's Encrypt certificates
|
||||
# and /var/log/, because we want a place where logs can go.
|
||||
# This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
|
||||
ReadWriteDirectories=/etc/walnut /etc/acme /etc/letsencrypt /etc/ssl /var/log/walnut /var/walnut /opt/walnut /srv/www
|
||||
ReadWriteDirectories=/etc/walnut /var/log/walnut /var/walnut /opt/walnut /srv/www
|
||||
|
||||
# Note: in v231 and above ReadWritePaths has been renamed to ReadWriteDirectories
|
||||
; ReadWritePaths=/etc/walnut /var/log/walnut
|
||||
|
|
221
install.sh
221
install.sh
|
@ -1,35 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "no install yet"
|
||||
exit 1
|
||||
set -e
|
||||
set -u
|
||||
|
||||
sudo mkdir -p /srv/walnut/{core,lib,etc,config,node_modules}
|
||||
ln -sf ../node_modules /srv/walnut/core/node_modules
|
||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.consumer
|
||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
|
||||
sudo mkdir -p /srv/walnut/packages/{api,pages,services}
|
||||
sudo chown -R $(whoami):$(whoami) /srv/walnut
|
||||
|
||||
#git clone git@git.daplie.com:Daplie/walnut.js.git
|
||||
#git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core
|
||||
|
||||
pushd /srv/walnut/core
|
||||
npm install
|
||||
popd
|
||||
|
||||
mv /srv/walnut/core/node_modules /srv/walnut
|
||||
|
||||
echo -n "Enter an email address to use for LetsEncrypt and press [ENTER]: "
|
||||
read LE_EMAIL
|
||||
node -e "
|
||||
'use strict';
|
||||
|
||||
require('fs').writeFileSync('/srv/walnut/config.letsencrypt.json', JSON.stringify({
|
||||
configDir: '/srv/walnut/letsencrypt'
|
||||
, email: '$LE_EMAIL'
|
||||
, agreeTos: true
|
||||
}, null, ' '));
|
||||
"
|
||||
# something or other about android and tmux using PREFIX
|
||||
#: "${PREFIX:=''}"
|
||||
MY_ROOT=""
|
||||
if [ -z "${PREFIX-}" ]; then
|
||||
MY_ROOT=""
|
||||
else
|
||||
MY_ROOT="$PREFIX"
|
||||
fi
|
||||
# Not every platform has or needs sudo, gotta save them O(1)s...
|
||||
sudo_cmd=""
|
||||
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
||||
|
||||
###############################
|
||||
# #
|
||||
|
@ -40,39 +24,20 @@ node -e "
|
|||
|
||||
# See https://git.daplie.com/Daplie/daplie-snippets/blob/master/bash/http-get.sh
|
||||
|
||||
http_curl_opts="-fsSL"
|
||||
http_wget_opts="--quiet"
|
||||
|
||||
http_bin=""
|
||||
http_get=""
|
||||
http_opts=""
|
||||
http_out=""
|
||||
|
||||
detect_http_bin()
|
||||
detect_http_get()
|
||||
{
|
||||
if type -p curl >/dev/null 2>&1; then
|
||||
http_bin="curl"
|
||||
http_opts="$http_curl_opts"
|
||||
http_get="curl"
|
||||
http_opts="-fsSL"
|
||||
http_out="-o"
|
||||
#curl -fsSL "$url" -o "$PREFIX/tmp/$pkg"
|
||||
elif type -p wget >/dev/null 2>&1; then
|
||||
http_bin="wget"
|
||||
http_opts="$http_wget_opts"
|
||||
http_get="wget"
|
||||
http_opts="--quiet"
|
||||
http_out="-O"
|
||||
#wget --quiet "$url" -O "$PREFIX/tmp/$pkg"
|
||||
else
|
||||
echo "Aborted, could not find curl or wget"
|
||||
return 7
|
||||
fi
|
||||
}
|
||||
|
||||
http_get()
|
||||
{
|
||||
if [ -e "$2" ]; then
|
||||
rsync -a "$2" "$1"
|
||||
elif type -p curl >/dev/null 2>&1; then
|
||||
$http_bin $http_curl_opts $http_out "$2" "$1"
|
||||
elif type -p wget >/dev/null 2>&1; then
|
||||
$http_bin $http_wget_opts $http_out "$2" "$1"
|
||||
else
|
||||
echo "Aborted, could not find curl or wget"
|
||||
return 7
|
||||
|
@ -81,7 +46,7 @@ http_get()
|
|||
|
||||
dap_dl()
|
||||
{
|
||||
$http_bin $http_opts $http_out "$2" "$1"
|
||||
$http_get $http_opts $http_out "$2" "$1"
|
||||
}
|
||||
|
||||
dap_dl_bash()
|
||||
|
@ -89,57 +54,46 @@ dap_dl_bash()
|
|||
dap_url=$1
|
||||
#dap_args=$2
|
||||
rm -rf dap-tmp-runner.sh
|
||||
$http_bin $http_opts $http_out dap-tmp-runner.sh "$dap_url"; bash dap-tmp-runner.sh; rm dap-tmp-runner.sh
|
||||
$http_get $http_opts $http_out dap-tmp-runner.sh "$dap_url"; bash dap-tmp-runner.sh; rm dap-tmp-runner.sh
|
||||
}
|
||||
|
||||
detect_http_bin
|
||||
detect_http_get
|
||||
|
||||
## END HTTP_GET ##
|
||||
|
||||
#################################
|
||||
|
||||
|
||||
###################
|
||||
# #
|
||||
# linux and osx system services #
|
||||
# Install service #
|
||||
# #
|
||||
#################################
|
||||
|
||||
# Use $PREFIX for compatibility with Termux on Android
|
||||
|
||||
# Not every platform has or needs sudo
|
||||
sudo_cmd=""
|
||||
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
||||
|
||||
my_app_name=goldilocks
|
||||
my_app_pkg_name=com.daplie.goldilocks.web
|
||||
my_app_dir=$(mktemp -d)
|
||||
installer_base="https://git.daplie.com/Daplie/goldilocks.js/raw/master" # add "/dist" as needed
|
||||
|
||||
my_app_systemd_service="etc/systemd/system/${my_app_name}.service"
|
||||
my_app_systemd_tmpfiles="etc/tmpfiles.d/${my_app_name}.conf"
|
||||
my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist"
|
||||
my_app_upstart_service="etc/init/${my_app_pkg_name}.conf"
|
||||
###################
|
||||
|
||||
install_for_systemd()
|
||||
{
|
||||
echo ""
|
||||
echo "Installing as systemd service"
|
||||
echo ""
|
||||
mkdir -p $(dirname "$my_app_dir/$my_app_systemd_service")
|
||||
dap_dl "$installer_base/$my_app_systemd_service" "$my_app_dir/$my_app_systemd_service"
|
||||
$sudo_cmd mv "$my_app_dir/$my_app_systemd_service" "$MY_ROOT/$my_app_systemd_service"
|
||||
$sudo_cmd chown -R root:root "$MY_ROOT/$my_app_systemd_service"
|
||||
$sudo_cmd chmod 644 "$MY_ROOT/$my_app_systemd_service"
|
||||
|
||||
dap_dl "$installer_base/$my_app_system_service" "$my_app_dir/$my_app_system_service"
|
||||
$sudo_cmd mv "$my_app_dir/$my_app_system_service" "$PREFIX/$my_app_system_service"
|
||||
$sudo_cmd chown -R root:root "$PREFIX/$my_app_system_service"
|
||||
$sudo_cmd chmod 644 "$PREFIX/$my_app_system_service"
|
||||
|
||||
dap_dl "$installer_base/$my_app_system_tmpfiles" "$my_app_dir/$my_app_system_tmpfiles"
|
||||
$sudo_cmd mv "$my_app_dir/$my_app_system_tmpfiles" "$PREFIX/$my_app_system_tmpfiles"
|
||||
$sudo_cmd chown -R root:root "$PREFIX/$my_app_system_tmpfiles"
|
||||
$sudo_cmd chmod 644 "$PREFIX/$my_app_system_tmpfiles"
|
||||
mkdir -p $(dirname "$my_app_dir/$my_app_systemd_tmpfiles")
|
||||
dap_dl "$installer_base/$my_app_systemd_tmpfiles" "$my_app_dir/$my_app_systemd_tmpfiles"
|
||||
$sudo_cmd mv "$my_app_dir/$my_app_systemd_tmpfiles" "$MY_ROOT/$my_app_systemd_tmpfiles"
|
||||
$sudo_cmd chown -R root:root "$MY_ROOT/$my_app_systemd_tmpfiles"
|
||||
$sudo_cmd chmod 644 "$MY_ROOT/$my_app_systemd_tmpfiles"
|
||||
|
||||
$sudo_cmd systemctl stop "${my_app_name}.service" >/dev/null 2>/dev/null
|
||||
$sudo_cmd systemctl daemon-reload
|
||||
$sudo_cmd systemctl start "${my_app_name}.service"
|
||||
$sudo_cmd systemctl enable "${my_app_name}.service"
|
||||
|
||||
echo "$my_app_name started with systemctl"
|
||||
echo "$my_app_name started with systemctl, check its status like so"
|
||||
echo " $sudo_cmd systemctl status $my_app_name"
|
||||
echo " $sudo_cmd journalctl -xe -u goldilocks"
|
||||
}
|
||||
|
||||
install_for_launchd()
|
||||
|
@ -147,36 +101,38 @@ install_for_launchd()
|
|||
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" "$PREFIX/$my_app_launchd_service"
|
||||
$sudo_cmd chown root:wheel "$PREFIX/$my_app_launchd_service"
|
||||
$sudo_cmd chmod 0644 "$PREFIX/$my_app_launchd_service"
|
||||
$sudo_cmd launchctl unload -w "$PREFIX/$my_app_launchd_service" >/dev/null 2>/dev/null
|
||||
$sudo_cmd launchctl load -w "$PREFIX/$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"
|
||||
}
|
||||
|
||||
install_for_upstart()
|
||||
install_etc_config()
|
||||
{
|
||||
echo ""
|
||||
echo "Installing as upstart service"
|
||||
echo ""
|
||||
if [ ! -e "$MY_ROOT/$my_app_etc_config" ]; then
|
||||
$sudo_cmd mkdir -p $(dirname "$MY_ROOT/$my_app_etc_config")
|
||||
mkdir -p $(dirname "$my_app_dir/$my_app_etc_config")
|
||||
dap_dl "$installer_base/$my_app_etc_config" "$my_app_dir/$my_app_etc_config"
|
||||
$sudo_cmd mv "$my_app_dir/$my_app_etc_config" "$MY_ROOT/$my_app_etc_config"
|
||||
fi
|
||||
|
||||
dap_dl "$installer_base/$my_app_upstart_service" "$my_app_dir/$my_app_upstart_service"
|
||||
$sudo_cmd mv "$my_app_dir/$my_app_upstart_service" "$PREFIX/$my_app_upstart_service"
|
||||
$sudo_cmd chown root:wheel "$PREFIX/$my_app_upstart_service"
|
||||
$sudo_cmd chmod 0644 "$PREFIX/$my_app_upstart_service"
|
||||
|
||||
echo "$my_app_name started with upstart"
|
||||
$sudo_cmd chown -R www-data:www-data $(dirname "$MY_ROOT/$my_app_etc_config")
|
||||
$sudo_cmd chmod 775 $(dirname "$MY_ROOT/$my_app_etc_config")
|
||||
$sudo_cmd chmod 664 "$MY_ROOT/$my_app_etc_config"
|
||||
}
|
||||
|
||||
install_service()
|
||||
{
|
||||
install_etc_config
|
||||
|
||||
installable=""
|
||||
if [ -d "$PREFIX/etc/systemd/system" ]; then
|
||||
if [ -d "$MY_ROOT/etc/systemd/system" ]; then
|
||||
install_for_systemd
|
||||
installable="true"
|
||||
fi
|
||||
|
@ -184,10 +140,6 @@ install_service()
|
|||
install_for_launchd
|
||||
installable="true"
|
||||
fi
|
||||
if [ -d "$PREFIX/etc/init" ]; then
|
||||
install_for_upstart
|
||||
installable="true"
|
||||
fi
|
||||
if [ -z "$installable" ]; then
|
||||
echo ""
|
||||
echo "Unknown system service init type. You must install as a system service manually."
|
||||
|
@ -196,4 +148,59 @@ install_service()
|
|||
fi
|
||||
}
|
||||
|
||||
## END SERVICE_INSTALL ##
|
||||
|
||||
# Create dirs, set perms
|
||||
create_skeleton()
|
||||
{
|
||||
$sudo_cmd mkdir -p /srv/www
|
||||
$sudo_cmd mkdir -p /var/log/$my_app_name
|
||||
$sudo_cmd mkdir -p /etc/$my_app_name
|
||||
$sudo_cmd mkdir -p /var/$my_app_name
|
||||
$sudo_cmd mkdir -p /srv/$my_app_name
|
||||
$sudo_cmd mkdir -p /opt/$my_app_name
|
||||
}
|
||||
|
||||
# Unistall
|
||||
install_uninstaller()
|
||||
{
|
||||
dap_dl "https://git.daplie.com/Daplie/walnut.js/raw/master/uninstall.sh" "./walnut-uninstall"
|
||||
$sudo_cmd chmod 755 "./walnut-uninstall"
|
||||
$sudo_cmd chown root:root "./walnut-uninstall"
|
||||
$sudo_cmd mv "./walnut-uninstall" "/usr/local/bin/uninstall-walnut"
|
||||
}
|
||||
|
||||
|
||||
# Dependencies
|
||||
dap_dl_bash "https://git.daplie.com/coolaj86/node-install-script/raw/master/setup-min.sh"
|
||||
|
||||
# Install
|
||||
# npm install -g 'git+https://git@git.daplie.com/Daplie/walnut.js.git#fs-nosql'
|
||||
|
||||
my_app_name=walnut
|
||||
my_app_pkg_name=com.daplie.walnut.web
|
||||
my_app_dir=$(mktemp -d)
|
||||
installer_base="https://git.daplie.com/Daplie/walnut.js/raw/master/dist"
|
||||
|
||||
my_app_etc_config="etc/${my_app_name}/${my_app_name}.yml"
|
||||
my_app_systemd_service="etc/systemd/system/${my_app_name}.service"
|
||||
my_app_systemd_tmpfiles="etc/tmpfiles.d/${my_app_name}.conf"
|
||||
my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist"
|
||||
|
||||
# Install
|
||||
#git clone git@git.daplie.com:Daplie/walnut.js.git
|
||||
#git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core
|
||||
sudo mkdir -p /srv/walnut/{core,lib,etc,config,node_modules}
|
||||
ln -sf ../node_modules /srv/walnut/core/node_modules
|
||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.consumer
|
||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
|
||||
sudo mkdir -p /srv/walnut/packages/{api,pages,services}
|
||||
sudo chown -R $(whoami):$(whoami) /srv/walnut
|
||||
|
||||
pushd /srv/walnut/core
|
||||
npm install
|
||||
popd
|
||||
|
||||
create_skeleton
|
||||
install_uninstaller
|
||||
install_service
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
|
||||
# something or other about android and tmux using PREFIX
|
||||
#: "${PREFIX:=''}"
|
||||
MY_ROOT=""
|
||||
if [ -z "${PREFIX-}" ]; then
|
||||
MY_ROOT=""
|
||||
else
|
||||
MY_ROOT="$PREFIX"
|
||||
fi
|
||||
# Not every platform has or needs sudo, gotta save them O(1)s...
|
||||
sudo_cmd=""
|
||||
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
||||
|
||||
# you don't want any oopsies when an rm -rf is involved...
|
||||
set -e
|
||||
set -u
|
||||
|
||||
my_app_name=walnut
|
||||
my_app_pkg_name=com.daplie.$my_app_name.web
|
||||
|
||||
my_app_etc_config="etc/${my_app_name}/${my_app_name}.yml"
|
||||
my_app_systemd_service="etc/systemd/system/${my_app_name}.service"
|
||||
my_app_systemd_tmpfiles="etc/tmpfiles.d/${my_app_name}.conf"
|
||||
my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist"
|
||||
my_app_upstart_service="etc/init.d/${my_app_name}.conf"
|
||||
|
||||
|
||||
$sudo_cmd rm -f /usr/local/bin/$my_app_name
|
||||
$sudo_cmd rm -rf /usr/local/lib/node_modules/$my_app_name
|
||||
$sudo_cmd rm -f /usr/local/bin/uninstall-$my_app_name
|
||||
|
||||
$sudo_cmd rm -f "$MY_ROOT/$my_app_etc_config"
|
||||
$sudo_cmd rmdir -p $(dirname "$MY_ROOT/$my_app_etc_config") 2>/dev/null || true
|
||||
$sudo_cmd rm -f "$MY_ROOT/$my_app_systemd_service"
|
||||
$sudo_cmd rm -f "$MY_ROOT/$my_app_systemd_tmpfiles"
|
||||
$sudo_cmd rm -f "$MY_ROOT/$my_app_launchd_service"
|
||||
$sudo_cmd rm -f "$MY_ROOT/$my_app_upstart_service"
|
||||
|
||||
$sudo_cmd rm -rf /opt/$my_app_name
|
||||
$sudo_cmd rm -rf /var/log/$my_app_name
|
||||
|
||||
# TODO flag for --purge
|
||||
#rm -rf /etc/$my_app_name
|
||||
|
||||
# TODO trap uninstall function
|
||||
|
||||
echo "uninstall complete: $my_app_name"
|
Loading…
Reference in New Issue