WIP installer
This commit is contained in:
parent
f8ce89c6e7
commit
41bf8559a8
177
install.sh
177
install.sh
|
@ -3,21 +3,20 @@
|
||||||
echo "no install yet"
|
echo "no install yet"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
sudo mkdir -p /srv/walnut/{certs,core,letsencrypt,lib,etc,config}
|
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.consumer
|
||||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
|
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
|
||||||
sudo mkdir -p /srv/walnut/packages/{api,pages,services}
|
sudo mkdir -p /srv/walnut/packages/{api,pages,services}
|
||||||
sudo chown -R $(whoami):$(whoami) /srv/walnut
|
sudo chown -R $(whoami):$(whoami) /srv/walnut
|
||||||
|
|
||||||
#git clone git@github.com:Daplie/walnut.git
|
#git clone git@git.daplie.com:Daplie/walnut.js.git
|
||||||
git clone https://github.com/Daplie/walnut.git /srv/walnut/core
|
#git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core
|
||||||
|
|
||||||
pushd /srv/walnut/core
|
pushd /srv/walnut/core
|
||||||
npm install
|
npm install
|
||||||
popd
|
popd
|
||||||
|
|
||||||
sudo rsync -a /srv/walnut/core/etc/init/walnut.conf /etc/init/walnut.conf
|
|
||||||
rsync -a /srv/walnut/core/etc/letsencrypt/ /srv/walnut/certs/
|
|
||||||
mv /srv/walnut/core/node_modules /srv/walnut
|
mv /srv/walnut/core/node_modules /srv/walnut
|
||||||
|
|
||||||
echo -n "Enter an email address to use for LetsEncrypt and press [ENTER]: "
|
echo -n "Enter an email address to use for LetsEncrypt and press [ENTER]: "
|
||||||
|
@ -32,5 +31,169 @@ node -e "
|
||||||
}, null, ' '));
|
}, null, ' '));
|
||||||
"
|
"
|
||||||
|
|
||||||
sudo service walnut stop
|
###############################
|
||||||
sudo service walnut start
|
# #
|
||||||
|
# http_get #
|
||||||
|
# boilerplate for curl / wget #
|
||||||
|
# #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
# 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_opts=""
|
||||||
|
http_out=""
|
||||||
|
|
||||||
|
detect_http_bin()
|
||||||
|
{
|
||||||
|
if type -p curl >/dev/null 2>&1; then
|
||||||
|
http_bin="curl"
|
||||||
|
http_opts="$http_curl_opts"
|
||||||
|
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_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
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
dap_dl()
|
||||||
|
{
|
||||||
|
$http_bin $http_opts $http_out "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
detect_http_bin
|
||||||
|
|
||||||
|
## END HTTP_GET ##
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# #
|
||||||
|
# linux and osx system services #
|
||||||
|
# #
|
||||||
|
#################################
|
||||||
|
|
||||||
|
# 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 ""
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
$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"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_for_launchd()
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "Installing as launchd service"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# See http://www.launchd.info/
|
||||||
|
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"
|
||||||
|
|
||||||
|
echo "$my_app_name started with launchd"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_for_upstart()
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "Installing as upstart service"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_service()
|
||||||
|
{
|
||||||
|
installable=""
|
||||||
|
if [ -d "$PREFIX/etc/systemd/system" ]; then
|
||||||
|
install_for_systemd
|
||||||
|
installable="true"
|
||||||
|
fi
|
||||||
|
if [ -d "/Library/LaunchDaemons" ]; then
|
||||||
|
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."
|
||||||
|
echo '(please file a bug with the output of "uname -a")'
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_service
|
||||||
|
|
Loading…
Reference in New Issue