use same bash fns for http_get as other daplie scripts

This commit is contained in:
AJ ONeal 2017-05-05 00:09:20 -06:00
parent e1804ca93f
commit b63ec34bc5
1 changed files with 27 additions and 8 deletions

View File

@ -22,13 +22,23 @@ caddy_features=""
caddy_user=www-data caddy_user=www-data
caddy_group=www-data caddy_group=www-data
install_path="/usr/local/bin" install_path="/usr/local/bin"
http_get=""
http_opts=""
http_out=""
caddy_bin="caddy" caddy_bin="caddy"
caddy_dl_ext=".tar.gz" caddy_dl_ext=".tar.gz"
###############################
# #
# http_get #
# boilerplate for curl / wget #
# #
###############################
# See https://git.daplie.com/Daplie/daplie-snippets/blob/master/bash/http-get.sh
http_get=""
http_opts=""
http_out=""
detect_http_get() detect_http_get()
{ {
if type -p curl >/dev/null 2>&1; then if type -p curl >/dev/null 2>&1; then
@ -47,6 +57,15 @@ detect_http_get()
fi fi
} }
dap_dl()
{
$http_get $http_opts $http_out "$2" "$1"
}
detect_http_get
## END HTTP_GET ##
detect_arch() detect_arch()
{ {
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; return 1' ERR trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; return 1' ERR
@ -248,7 +267,7 @@ download_caddy()
# Use $PREFIX for compatibility with Termux on Android # Use $PREFIX for compatibility with Termux on Android
rm -rf "$PREFIX/tmp/$caddy_pkg" "$PREFIX/tmp/$caddy_dir" rm -rf "$PREFIX/tmp/$caddy_pkg" "$PREFIX/tmp/$caddy_dir"
$http_get $http_opts "$caddy_url" $http_out "$PREFIX/tmp/$caddy_pkg" dap_dl "$caddy_url" "$PREFIX/tmp/$caddy_pkg"
echo "Extracting..." echo "Extracting..."
case "$caddy_pkg" in case "$caddy_pkg" in
@ -321,7 +340,7 @@ CADDY_EOF
$sudo_cmd chmod 755 $PREFIX/srv/www/localhost $sudo_cmd chmod 755 $PREFIX/srv/www/localhost
if [ ! -f "$PREFIX/srv/www/localhost/index.html" ] || [ -z "$(cat $PREFIX/srv/www/localhost/index.html)" ]; then if [ ! -f "$PREFIX/srv/www/localhost/index.html" ] || [ -z "$(cat $PREFIX/srv/www/localhost/index.html)" ]; then
$http_get $http_opts "$caddy_localhost_index" $http_out $PREFIX/tmp/$caddy_dir/index.html dap_dl "$caddy_localhost_index" $PREFIX/tmp/$caddy_dir/index.html
$sudo_cmd mv $PREFIX/tmp/$caddy_dir/index.html $PREFIX/srv/www/localhost/ $sudo_cmd mv $PREFIX/tmp/$caddy_dir/index.html $PREFIX/srv/www/localhost/
$sudo_cmd chown -R $caddy_user:$caddy_group $PREFIX/srv/www/localhost/ $sudo_cmd chown -R $caddy_user:$caddy_group $PREFIX/srv/www/localhost/
$sudo_cmd chmod 664 $PREFIX/srv/www/localhost/index.html $sudo_cmd chmod 664 $PREFIX/srv/www/localhost/index.html
@ -359,12 +378,12 @@ CADDY_EOF
echo "" echo ""
echo "Installing as systemd service" echo "Installing as systemd service"
echo "" echo ""
$http_get $http_opts "$caddy_systemd_service" $http_out $PREFIX/tmp/$caddy_dir/caddy.service dap_dl "$caddy_systemd_service" $PREFIX/tmp/$caddy_dir/caddy.service
$sudo_cmd mv $PREFIX/tmp/$caddy_dir/caddy.service $PREFIX/etc/systemd/system/caddy.service $sudo_cmd mv $PREFIX/tmp/$caddy_dir/caddy.service $PREFIX/etc/systemd/system/caddy.service
$sudo_cmd chown -R root:root $PREFIX/etc/systemd/system/caddy.service $sudo_cmd chown -R root:root $PREFIX/etc/systemd/system/caddy.service
$sudo_cmd chmod 644 $PREFIX/etc/systemd/system/caddy.service $sudo_cmd chmod 644 $PREFIX/etc/systemd/system/caddy.service
$http_get $http_opts "$caddy_systemd_tmpfiles" $http_out $PREFIX/tmp/$caddy_dir/caddy.conf dap_dl "$caddy_systemd_tmpfiles" $PREFIX/tmp/$caddy_dir/caddy.conf
$sudo_cmd mv $PREFIX/tmp/$caddy_dir/caddy.conf $PREFIX/etc/tmpfiles.d/caddy.conf $sudo_cmd mv $PREFIX/tmp/$caddy_dir/caddy.conf $PREFIX/etc/tmpfiles.d/caddy.conf
$sudo_cmd chown -R root:root $PREFIX/etc/tmpfiles.d/caddy.conf $sudo_cmd chown -R root:root $PREFIX/etc/tmpfiles.d/caddy.conf
$sudo_cmd chmod 644 $PREFIX/etc/tmpfiles.d/caddy.conf $sudo_cmd chmod 644 $PREFIX/etc/tmpfiles.d/caddy.conf
@ -382,7 +401,7 @@ CADDY_EOF
echo "Installing as launchd service" echo "Installing as launchd service"
echo "" echo ""
# See http://www.launchd.info/ # See http://www.launchd.info/
$http_get $http_opts "$caddy_launchd_service" $http_out $PREFIX/tmp/$caddy_dir/com.caddyserver.web.plist dap_dl "$caddy_launchd_service" $PREFIX/tmp/$caddy_dir/com.caddyserver.web.plist
$sudo_cmd mv $PREFIX/tmp/$caddy_dir/com.caddyserver.web.plist /Library/LaunchAgents/com.caddyserver.web.plist $sudo_cmd mv $PREFIX/tmp/$caddy_dir/com.caddyserver.web.plist /Library/LaunchAgents/com.caddyserver.web.plist
$sudo_cmd chown root:wheel /Library/LaunchAgents/com.caddyserver.web.plist $sudo_cmd chown root:wheel /Library/LaunchAgents/com.caddyserver.web.plist
$sudo_cmd chmod 0644 /Library/LaunchAgents/com.caddyserver.web.plist $sudo_cmd chmod 0644 /Library/LaunchAgents/com.caddyserver.web.plist