diff --git a/stpkg b/stpkg index fb661962c5318e2715f122e80de1e91dc2e8d3f6..526376ff9cda160ea1821dd74f4a87f1ed5af538 100755 --- a/stpkg +++ b/stpkg @@ -1,9 +1,14 @@ #!/bin/bash -STPKG_CONF_FILE=~/config/stpkg.sh +STPKG_CONF_FILE=~/.config/stpkg.sh BASE_DIR="$PWD" DISPLAY_DEPS_NOTES="yes" +# Detect install +if [ "x$1" = "x-install" ]; then + INSTALL="yes" +fi + if [ "x$STPKG_COLORS" = "x" ]; then STPKG_COLORS="yes" error() { __red "$*\n" >/dev/stderr; } @@ -28,6 +33,11 @@ else alias __bold=echo fi +die() { + error $* + exit 1 +} + # Source conf file, may have the sshfs hook [ -f $STPKG_CONF_FILE ] && source $STPKG_CONF_FILE @@ -97,11 +107,6 @@ EOF exit 0 } -die() { - error $* - exit 1 -} - require() { local __cmd=`which $1` [ $? -ne 0 ] && die "Failed to find the '$1' command" @@ -120,6 +125,7 @@ default_index() { \"packs\": [ \"scalar-privacy_pam.json\" ] }" } +# Be paranoid require column require uuidgen require convert @@ -161,26 +167,39 @@ __install() { # Create the ~/config/stpkg.sh [ ! -d ~/config ] && mkdir ~/config - echo "STPKG_BASE=$BASE_DIR" > $STPKG_CONF_FILE - echo "STPKG_HOMESERV='matrix.org'" >> $STPKG_CONF_FILE - echo "STPKG_TOKEN=''" >> $STPKG_CONF_FILE +cat > $STPKG_CONF_FILE << EOF +if [ ! "x\$INSTALL" = "xyes" ]; then +STPKG_BASE="$BASE_DIR" +STPKG_HOMESERV='matrix.org' +STPKG_TOKEN='' +STPKG_COLORS='yes' +STPKG_NO_MSG='no' +EOF chmod 00600 $STPKG_CONF_FILE # Set install dir. Oh boi, tricky things going around here because we # handle the sshfs ourself. if [ ! "x$SSHFS" = "x" ]; then + info "Detected a sshfs install" [ "x$MNT" = "x" ] && die "You must specify a mount point with '-local /mount/pount' when using the '-sshfs' option" local STPKG_INSTALL=$1 STPKG_INSTALL=$MNT${STPKG_INSTALL:="/html/stickerpicker/"} # The sshfs hook - echo "STPKG_INSTALL=$STPKG_INSTALL" >> $STPKG_CONF_FILE - echo "[ ! -d \"$MNT\" ] && mkdir -p \"$MNT\" || die 'Failed to recreate mount point'" >> $STPKG_CONF_FILE - echo "[ ! -d \"\$STPKG_INSTALL\" ] && sshfs $SSHFS:~/ $MNT" >> $STPKG_CONF_FILE - echo "[ ! -d \"\$STPKG_INSTALL\" ] && die 'Failed to mount $SSHFS:~/ to $MNT, sshfs problems?'" >> $STPKG_CONF_FILE +cat >> $STPKG_CONF_FILE << EOF +STPKG_SSHFS='yes' +STPKG_INSTALL="$STPKG_INSTALL" +mountpoint $MNT >/dev/null 2>&1 +if [ \$? -ne 0 -a ! "x\$INSTALL" = "xyes" ]; then +[ ! -d "\$STPKG_INSTALL" ] && { sshfs $SSHFS: $MNT || die "Failed to mount $SSHFS:~/ to $MNT"; } +[ ! -d "\$STPKG_INSTALL" ] && die 'Failed to mount $SSHFS:~/ to $MNT, sshfs problems?' +fi +EOF # Do the sshfs hook - sshfs $SSHFS:~/ $MNT + mountpoint $MNT >/dev/null 2>&1 + [ $? -eq 0 ] && die "The '$MNT' folder is already a mountpoint" + sshfs $SSHFS: $MNT || die "Failed to mount $SSHFS:~/ to $MNT" else local STPKG_INSTALL=$1 STPKG_INSTALL=${STPKG_INSTALL:="~/html/stickerpicker/"} @@ -202,7 +221,8 @@ __install() { default_index > $STPKG_INSTALL/web/packs/index.json || die "Failed to create default index.json file" - info "You may edit the $STPKG_CONF_FILE to setup your home server and token" + echo "fi" >> $STPKG_CONF_FILE + info "You may edit the $STPKG_CONF_FILE to setup your home server and token (variable STPKG_TOKEN)" } if [ "x$1" = "x-install" ]; then [ "x$STPKG_NO_MSG" = "xyes" ] \ @@ -223,7 +243,7 @@ if [ ! -d "$STPKG_INSTALL" ]; then error "STPKG_INSTALL folder ($STPKG_INSTALL) doesn't exist. Did you use the install script?" usage fi -info "Use STPKG_INSTALL: $STPKG_INSTALL" +info "Use STPKG_INSTALL: $STPKG_INSTALL`[ "x$STPKG_SSHFS" = "xyes" ] && echo ' (this is an sshfs install)'`" if [ "x$STPKG_BASE" = "x" ]; then die "The STPKG_BASE env var is mendatory, it must point to the sticker repo." \