From 4ec1f3b30ab12184f51de227186bf6d23c324963 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 5 Jun 2018 00:46:06 -0600 Subject: [PATCH] fix sudo_cmd whitespace, editor detection, other things... --- usr/share/install_helper.sh | 83 ++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/usr/share/install_helper.sh b/usr/share/install_helper.sh index 025651d..b8dbfa2 100644 --- a/usr/share/install_helper.sh +++ b/usr/share/install_helper.sh @@ -46,13 +46,29 @@ my_name="Telebit Remote" my_repo="telebit.js" my_root=${my_root:-} # todo better install script sudo_cmd="sudo" +sudo_cmde="sudo " exec 3<>/dev/tty read_cmd="read -u 3" # TODO detect if rsync is available and use rsync -a (more portable) rsync_cmd="cp -pPR" +my_edit=${EDITOR:-} +set +e +my_edit=$(type -p edit) +if [ -z "$my_edit" ]; then + my_edit=$(type -p nano) +fi +if [ -z "$my_edit" ]; then + my_edit=$(type -p vim) +fi +if [ -z "$my_edit" ]; then + my_edit=$(type -p vi) +fi +set -e + if [ "root" == $(whoami) ] || [ 0 == $(id -u) ]; then sudo_cmd=" " + sudo_cmde="" fi if [ -z "${my_email}" ]; then @@ -129,14 +145,14 @@ my_npm="$my_node $TELEBIT_PATH/bin/npm" my_tmp="$(mktemp -d)" mkdir -p $my_tmp -echo "$sudo_cmd mkdir -p '$TELEBIT_PATH'" +echo "${sudo_cmde}mkdir -p '$TELEBIT_PATH'" $sudo_cmd mkdir -p "$TELEBIT_PATH" $sudo_cmd mkdir -p "$TELEBIT_PATH/etc" $sudo_cmd mkdir -p "$TELEBIT_PATH/var/log" $sudo_cmd chown -R $(id -u -n):$(id -g -n) "$TELEBIT_PATH" -echo "$sudo_cmd mkdir -p '/etc/$my_app/'" -$sudo_cmd mkdir -p "/etc/$my_app/" -$sudo_cmd chown $(id -u -n):$(id -g -n) "/etc/$my_app/" +#echo "${sudo_cmde}mkdir -p '/etc/$my_app/'" +#$sudo_cmd mkdir -p "/etc/$my_app/" +#$sudo_cmd chown $(id -u -n):$(id -g -n) "/etc/$my_app/" #https://git.coolaj86.com/coolaj86/telebit.js.git #https://git.coolaj86.com/coolaj86/telebit.js/archive/:tree:.tar.gz @@ -170,14 +186,15 @@ cat << EOF > $TELEBIT_PATH/bin/$my_app #!/bin/bash $my_node $TELEBIT_PATH/bin/$my_bin EOF + chmod a+x $TELEBIT_PATH/bin/$my_app -echo "$sudo_cmd ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app" +echo "${sudo_cmde}ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app" $sudo_cmd ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app set +e if type -p setcap >/dev/null 2>&1; then #echo "Setting permissions to allow $my_app to run on port 80 and port 443 without sudo or root" - echo "$sudo_cmd setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node" + echo "${sudo_cmde}setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node" $sudo_cmd setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node fi set -e @@ -230,12 +247,12 @@ if [ ! -e "$my_config" ]; then cat $TELEBIT_PATH/usr/share/$my_app.tpl.yml >> "$my_config" fi -my_config_link="/etc/$my_app/$my_app.yml" -if [ ! -e "$my_config_link" ]; then - echo "$sudo_cmd ln -sf '$my_config' '$my_config_link'" - #$sudo_cmd mkdir -p /etc/$my_app - $sudo_cmd ln -sf "$my_config" "$my_config_link" -fi +#my_config_link="/etc/$my_app/$my_app.yml" +#if [ ! -e "$my_config_link" ]; then +# echo "${sudo_cmde}ln -sf '$my_config' '$my_config_link'" +# #$sudo_cmd mkdir -p /etc/$my_app +# $sudo_cmd ln -sf "$my_config" "$my_config_link" +#fi my_config="$HOME/.config/$my_app/$my_app.yml" mkdir -p "$(dirname $my_config)" @@ -254,8 +271,8 @@ if [ ! -e "$my_config" ]; then cat $TELEBIT_PATH/usr/share/$my_app.tpl.yml >> "$my_config" fi -echo "$sudo_cmd chown -R $my_user '$TELEBIT_PATH' '/etc/$my_app'" -$sudo_cmd chown -R $my_user "$TELEBIT_PATH" "/etc/$my_app" +echo "${sudo_cmde}chown -R $my_user '$TELEBIT_PATH'# '/etc/$my_app'" +$sudo_cmd chown -R $my_user "$TELEBIT_PATH"# "/etc/$my_app" # ~/.config/systemd/user/ # %h/.config/telebit/telebit.yml @@ -265,25 +282,25 @@ my_system_launcher="" if [ -d "/Library/LaunchDaemons" ]; then my_system_launcher="launchd" my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist" - echo "$sudo_cmd $rsync_cmd $TELEBIT_PATH/usr/share/dist/$my_app_launchd_service /$my_app_launchd_service" + echo "${sudo_cmde}$rsync_cmd $TELEBIT_PATH/usr/share/dist/$my_app_launchd_service /$my_app_launchd_service" $sudo_cmd $rsync_cmd "$TELEBIT_PATH/usr/share/dist/$my_app_launchd_service" "/$my_app_launchd_service" - echo "$sudo_cmd chown root:wheel $my_root/$my_app_launchd_service" + echo "${sudo_cmde}chown root:wheel $my_root/$my_app_launchd_service" $sudo_cmd chown root:wheel "$my_root/$my_app_launchd_service" - echo "$sudo_cmd launchctl unload -w $my_root/$my_app_launchd_service >/dev/null 2>/dev/null" + echo "${sudo_cmde}launchctl unload -w $my_root/$my_app_launchd_service >/dev/null 2>/dev/null" $sudo_cmd launchctl unload -w "$my_root/$my_app_launchd_service" >/dev/null 2>/dev/null - echo "$sudo_cmd launchctl load -w $my_root/$my_app_launchd_service" + echo "${sudo_cmde}launchctl load -w $my_root/$my_app_launchd_service" $sudo_cmd launchctl load -w "$my_root/$my_app_launchd_service" elif [ -d "$my_root/etc/systemd/system" ]; then my_system_launcher="systemd" - echo "$sudo_cmd $rsync_cmd $TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service /etc/systemd/system/$my_app.service" + echo "${sudo_cmde}$rsync_cmd $TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service /etc/systemd/system/$my_app.service" $sudo_cmd $rsync_cmd "$TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service" "/etc/systemd/system/$my_app.service" $sudo_cmd systemctl daemon-reload - echo "$sudo_cmd systemctl enable $my_app" + echo "${sudo_cmde}systemctl enable $my_app" $sudo_cmd systemctl enable $my_app - echo "$sudo_cmd systemctl start $my_app" + echo "${sudo_cmde}systemctl start $my_app" $sudo_cmd systemctl restart $my_app fi @@ -295,7 +312,7 @@ echo "==============================================" echo " Privacy Settings in Config" echo "==============================================" echo "" -echo "The example config file /etc/$my_app/$my_app.yml opts-in to" +echo "The default config file $TELEBIT_PATH/etc/$my_app.yml opts-in to" echo "contributing telemetrics and receiving infrequent relevant updates" echo "(probably once per quarter or less) such as important notes on" echo "a new release, an important API change, etc. No spam." @@ -315,33 +332,33 @@ if [ "systemd" == "$my_system_launcher" ]; then echo "Edit the config and restart, if desired:" echo "" - echo " $sudo_cmd edit /opt/$my_app/etc/$my_app.yml" - echo " $sudo_cmd systemctl restart $my_app" + echo " ${sudo_cmde}$my_edit $TELEBIT_PATH/etc/$my_app.yml" + echo " ${sudo_cmde}systemctl restart $my_app" echo "" echo "Or disabled the service and start manually:" echo "" - echo " $sudo_cmd systemctl stop $my_app" - echo " $sudo_cmd systemctl disable $my_app" - echo " $my_app --config /opt/$my_app/etc/$my_app.yml" + echo " ${sudo_cmde}systemctl stop $my_app" + echo " ${sudo_cmde}systemctl disable $my_app" + echo " $my_app --config $TELEBIT_PATH/etc/$my_app.yml" elif [ "launchd" == "$my_system_launcher" ]; then echo "Edit the config and restart, if desired:" echo "" - echo " $sudo_cmd edit /opt/$my_app/etc/$my_app.yml" - echo " $sudo_cmd launchctl unload $my_root/$my_app_launchd_service" - echo " $sudo_cmd launchctl load -w $my_root/$my_app_launchd_service" + echo " ${sudo_cmde}$my_edit $TELEBIT_PATH/etc/$my_app.yml" + echo " ${sudo_cmde}launchctl unload $my_root/$my_app_launchd_service" + echo " ${sudo_cmde}launchctl load -w $my_root/$my_app_launchd_service" echo "" echo "Or disabled the service and start manually:" echo "" - echo " $sudo_cmd launchctl unload -w $my_root/$my_app_launchd_service" - echo " $my_app --config /opt/$my_app/etc/$my_app.yml" + echo " ${sudo_cmde}launchctl unload -w $my_root/$my_app_launchd_service" + echo " $my_app --config $TELEBIT_PATH/etc/$my_app.yml" else echo "Edit the config, if desired:" echo "" - echo " $sudo_cmd edit $my_config" + echo " ${sudo_cmde}$my_edit $my_config" echo "" echo "Or disabled the service and start manually:" echo ""