fix sudo_cmd whitespace, editor detection, other things...

This commit is contained in:
AJ ONeal 2018-06-05 00:46:06 -06:00
parent 570c64f104
commit 4ec1f3b30a
1 changed files with 50 additions and 33 deletions

View File

@ -46,13 +46,29 @@ my_name="Telebit Remote"
my_repo="telebit.js" my_repo="telebit.js"
my_root=${my_root:-} # todo better install script my_root=${my_root:-} # todo better install script
sudo_cmd="sudo" sudo_cmd="sudo"
sudo_cmde="sudo "
exec 3<>/dev/tty exec 3<>/dev/tty
read_cmd="read -u 3" read_cmd="read -u 3"
# TODO detect if rsync is available and use rsync -a (more portable) # TODO detect if rsync is available and use rsync -a (more portable)
rsync_cmd="cp -pPR" 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 if [ "root" == $(whoami) ] || [ 0 == $(id -u) ]; then
sudo_cmd=" " sudo_cmd=" "
sudo_cmde=""
fi fi
if [ -z "${my_email}" ]; then if [ -z "${my_email}" ]; then
@ -129,14 +145,14 @@ my_npm="$my_node $TELEBIT_PATH/bin/npm"
my_tmp="$(mktemp -d)" my_tmp="$(mktemp -d)"
mkdir -p $my_tmp 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"
$sudo_cmd mkdir -p "$TELEBIT_PATH/etc" $sudo_cmd mkdir -p "$TELEBIT_PATH/etc"
$sudo_cmd mkdir -p "$TELEBIT_PATH/var/log" $sudo_cmd mkdir -p "$TELEBIT_PATH/var/log"
$sudo_cmd chown -R $(id -u -n):$(id -g -n) "$TELEBIT_PATH" $sudo_cmd chown -R $(id -u -n):$(id -g -n) "$TELEBIT_PATH"
echo "$sudo_cmd mkdir -p '/etc/$my_app/'" #echo "${sudo_cmde}mkdir -p '/etc/$my_app/'"
$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/" #$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.git
#https://git.coolaj86.com/coolaj86/telebit.js/archive/:tree:.tar.gz #https://git.coolaj86.com/coolaj86/telebit.js/archive/:tree:.tar.gz
@ -170,14 +186,15 @@ cat << EOF > $TELEBIT_PATH/bin/$my_app
#!/bin/bash #!/bin/bash
$my_node $TELEBIT_PATH/bin/$my_bin $my_node $TELEBIT_PATH/bin/$my_bin
EOF EOF
chmod a+x $TELEBIT_PATH/bin/$my_app 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 $sudo_cmd ln -sf $TELEBIT_PATH/bin/$my_app /usr/local/bin/$my_app
set +e set +e
if type -p setcap >/dev/null 2>&1; then 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 "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 $sudo_cmd setcap cap_net_bind_service=+ep $TELEBIT_PATH/bin/node
fi fi
set -e set -e
@ -230,12 +247,12 @@ if [ ! -e "$my_config" ]; then
cat $TELEBIT_PATH/usr/share/$my_app.tpl.yml >> "$my_config" cat $TELEBIT_PATH/usr/share/$my_app.tpl.yml >> "$my_config"
fi fi
my_config_link="/etc/$my_app/$my_app.yml" #my_config_link="/etc/$my_app/$my_app.yml"
if [ ! -e "$my_config_link" ]; then #if [ ! -e "$my_config_link" ]; then
echo "$sudo_cmd ln -sf '$my_config' '$my_config_link'" # echo "${sudo_cmde}ln -sf '$my_config' '$my_config_link'"
#$sudo_cmd mkdir -p /etc/$my_app # #$sudo_cmd mkdir -p /etc/$my_app
$sudo_cmd ln -sf "$my_config" "$my_config_link" # $sudo_cmd ln -sf "$my_config" "$my_config_link"
fi #fi
my_config="$HOME/.config/$my_app/$my_app.yml" my_config="$HOME/.config/$my_app/$my_app.yml"
mkdir -p "$(dirname $my_config)" 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" cat $TELEBIT_PATH/usr/share/$my_app.tpl.yml >> "$my_config"
fi fi
echo "$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" $sudo_cmd chown -R $my_user "$TELEBIT_PATH"# "/etc/$my_app"
# ~/.config/systemd/user/ # ~/.config/systemd/user/
# %h/.config/telebit/telebit.yml # %h/.config/telebit/telebit.yml
@ -265,25 +282,25 @@ my_system_launcher=""
if [ -d "/Library/LaunchDaemons" ]; then if [ -d "/Library/LaunchDaemons" ]; then
my_system_launcher="launchd" my_system_launcher="launchd"
my_app_launchd_service="Library/LaunchDaemons/${my_app_pkg_name}.plist" 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" $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" $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 $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" $sudo_cmd launchctl load -w "$my_root/$my_app_launchd_service"
elif [ -d "$my_root/etc/systemd/system" ]; then elif [ -d "$my_root/etc/systemd/system" ]; then
my_system_launcher="systemd" 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 $rsync_cmd "$TELEBIT_PATH/usr/share/dist/etc/systemd/system/$my_app.service" "/etc/systemd/system/$my_app.service"
$sudo_cmd systemctl daemon-reload $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 $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 $sudo_cmd systemctl restart $my_app
fi fi
@ -295,7 +312,7 @@ echo "=============================================="
echo " Privacy Settings in Config" echo " Privacy Settings in Config"
echo "==============================================" echo "=============================================="
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 "contributing telemetrics and receiving infrequent relevant updates"
echo "(probably once per quarter or less) such as important notes on" echo "(probably once per quarter or less) such as important notes on"
echo "a new release, an important API change, etc. No spam." 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 "Edit the config and restart, if desired:"
echo "" echo ""
echo " $sudo_cmd edit /opt/$my_app/etc/$my_app.yml" echo " ${sudo_cmde}$my_edit $TELEBIT_PATH/etc/$my_app.yml"
echo " $sudo_cmd systemctl restart $my_app" echo " ${sudo_cmde}systemctl restart $my_app"
echo "" echo ""
echo "Or disabled the service and start manually:" echo "Or disabled the service and start manually:"
echo "" echo ""
echo " $sudo_cmd systemctl stop $my_app" echo " ${sudo_cmde}systemctl stop $my_app"
echo " $sudo_cmd systemctl disable $my_app" echo " ${sudo_cmde}systemctl disable $my_app"
echo " $my_app --config /opt/$my_app/etc/$my_app.yml" echo " $my_app --config $TELEBIT_PATH/etc/$my_app.yml"
elif [ "launchd" == "$my_system_launcher" ]; then elif [ "launchd" == "$my_system_launcher" ]; then
echo "Edit the config and restart, if desired:" echo "Edit the config and restart, if desired:"
echo "" echo ""
echo " $sudo_cmd edit /opt/$my_app/etc/$my_app.yml" echo " ${sudo_cmde}$my_edit $TELEBIT_PATH/etc/$my_app.yml"
echo " $sudo_cmd launchctl unload $my_root/$my_app_launchd_service" echo " ${sudo_cmde}launchctl unload $my_root/$my_app_launchd_service"
echo " $sudo_cmd launchctl load -w $my_root/$my_app_launchd_service" echo " ${sudo_cmde}launchctl load -w $my_root/$my_app_launchd_service"
echo "" echo ""
echo "Or disabled the service and start manually:" echo "Or disabled the service and start manually:"
echo "" echo ""
echo " $sudo_cmd launchctl unload -w $my_root/$my_app_launchd_service" echo " ${sudo_cmde}launchctl unload -w $my_root/$my_app_launchd_service"
echo " $my_app --config /opt/$my_app/etc/$my_app.yml" echo " $my_app --config $TELEBIT_PATH/etc/$my_app.yml"
else else
echo "Edit the config, if desired:" echo "Edit the config, if desired:"
echo "" echo ""
echo " $sudo_cmd edit $my_config" echo " ${sudo_cmde}$my_edit $my_config"
echo "" echo ""
echo "Or disabled the service and start manually:" echo "Or disabled the service and start manually:"
echo "" echo ""