From ea6aaf98bab20746ab2358b99c378578524cdb91 Mon Sep 17 00:00:00 2001
From: Elliu <elliu@hashi.re>
Date: Sun, 14 Aug 2022 17:35:18 +0200
Subject: [PATCH] Manage all homeserver and token conf at the same time

Also allow change of stickerpicker repository.

This fixes `stpkg pack` accepting token with `-t` but not `stpkg edit`
---
 stpkg | 52 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/stpkg b/stpkg
index 33f1a00..26e0483 100755
--- a/stpkg
+++ b/stpkg
@@ -72,10 +72,6 @@ if [ "x$STPKG_NO_MSG" = "xyes" -a ! "x$1" = "x-install" -a ! "x$1" = "xupdate" ]
     info()  { return 0; }
 fi
 
-# Home server
-STPKG_HOMESERV=${STPKG_HOMESERV:="matrix.org"}
-STPKG_HOMESERV=`echo "$STPKG_HOMESERV" | iconv -c -t ascii//TRANSLIT | sed -e 's/^http:\/\/|^https:\/\///g' -e 's/^-+|-+$//g'`
-
 ########################
 # Some basic functions #
 ########################
@@ -90,15 +86,15 @@ usage() {
     echo `__bold "$BASE_NAME usage:"`
     local BASE_NAME=`__green "$BASE_NAME"`
 cat << EOF
-    $BASE_NAME -install [`__yellow "-sshfs 'username@server' -local mnt_point"`] [`__yellow "install_path"`]
+    $BASE_NAME -install [`__yellow "-sshfs 'username@server' -local mnt_point -pickerrepo 'foo@git.fr:stickerpicker.git'"`] [`__yellow "install_path"`]
     $BASE_NAME show
     $BASE_NAME help
     $BASE_NAME update
     $BASE_NAME list [`__yellow "-p -e -np"`] [`__yellow "bash_regex"`]
     $BASE_NAME add|del <`__yellow "pack"`>
     $BASE_NAME pack [`__yellow "-t token"`] [`__yellow "name"`] <`__yellow "pack_folder"`>
+    $BASE_NAME edit [`__yellow "-t token"`] <`__yellow "pack_name"`> add|del <`__yellow "sticker"`> [`__yellow "file"`]
     $BASE_NAME display [`__yellow "-dl folder"`] <`__yellow "pack_name"`> [`__yellow "sticker_regex"`]
-    $BASE_NAME edit <`__yellow "pack_name"`> add|del <`__yellow "sticker"`> [`__yellow "file"`]
 
 `__bold Flags:`
     `__yellow "-e"` / `__yellow "-ne"`    The pack is enabled / disabled
@@ -252,6 +248,10 @@ __install() {
     local PARSE_FLAGS=1
     while [ $PARSE_FLAGS -eq 1 ]; do
         case "$1" in
+            -pickerrepo)
+                STPKG_STICKER_REPO="$2"
+                shift 2
+                ;;
             -sshfs)
                 local SSHFS="$2"
                 shift 2
@@ -662,20 +662,6 @@ progress()       { echo 1>&2 -n "$*";       }
 progress_dot()   { progress '.';            }
 progress_reset() { echo 1>&2 -en "\r"; }
 __pack() {
-    validate_homeserv # Check if homeserv exists
-
-    # Get the token
-    if [ "x$1" = "x-t" ]; then
-        STPKG_TOKEN="$2"
-        shift 2
-    fi
-    if [ "x$STPKG_TOKEN" = "x" ]; then
-        read -sp "`__yellow 'Enter your access token:'`" STPKG_TOKEN
-        echo ''
-    fi
-
-    validate_token # Validate token, will exit if invalid
-
     # The pack source folder and the pack name
     if [ $# -eq 1 ]; then
         # The pack name is not specified
@@ -796,8 +782,30 @@ __do_command() {
             info "Using STPKG_INSTALL: $STPKG_INSTALL`[ "x$STPKG_SSHFS" = "xyes" ] && echo ' (this is an sshfs install)'`"
 
             [ "x$STPKG_BASE" = "x" ] && die \
-                "The STPKG_BASE env var is mendatory, it must point to the sticker repo. It should have been given by the install script"
-            ;;
+                "The STPKG_BASE env var is mandatory, it must point to the sticker repo. It should have been given by the install script"
+
+            STPKG_STICKER_REPO=${STPKG_STICKER_REPO:="https://github.com/maunium/stickerpicker.git"}
+            ;;&
+
+        edit|pack)
+            # Home server
+            STPKG_HOMESERV=${STPKG_HOMESERV:="matrix.org"}
+            STPKG_HOMESERV=`echo "$STPKG_HOMESERV" | iconv -c -t ascii//TRANSLIT | sed -e 's/^http:\/\/|^https:\/\///g' -e 's/^-+|-+$//g'`
+
+            validate_homeserv # Check if homeserv exists
+
+            # Get the token
+            if [ "x$1" = "x-t" ]; then
+                STPKG_TOKEN="$2"
+                shift 2
+            fi
+            if [ "x$STPKG_TOKEN" = "x" ]; then
+                read -sp "`__yellow 'Enter your access token:'`" STPKG_TOKEN
+                echo ''
+            fi
+
+            validate_token # Validate token, will exit if invalid
+            ;;&
 
         *)
             ;;
-- 
GitLab