diff --git a/src/commands/auth/login.sh b/src/commands/auth/login.sh index 7940996..ca3a891 100644 --- a/src/commands/auth/login.sh +++ b/src/commands/auth/login.sh @@ -13,7 +13,7 @@ wx-login(){ elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]] then ORG=cwchristerw - elif [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .org) ]] + elif [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .org) != "null" ]] then ORG=$(cat $HOME/.warengroup/config.json | jq -r .org) else diff --git a/src/functions/start.sh b/src/functions/start.sh index 0a51d0b..3e6f843 100644 --- a/src/functions/start.sh +++ b/src/functions/start.sh @@ -1,19 +1,15 @@ wx-start(){ wx-header "Warén CLI" h1 - if [[ $USER != "root" && $USER != "local" ]] + mkdir -p $HOME/.warengroup &> /dev/null + + if [[ ! -f "$HOME/.warengroup/config.json" || $(cat $HOME/.warengroup/config.json | jq -e . >/dev/null 2>&1 | echo ${PIPESTATUS[1]}) -gt 0 ]] then - mkdir -p $HOME/.warengroup &> /dev/null - touch $HOME/.warengroup/config.json &> /dev/null - - if [[ ! -f "$HOME/.warengroup/config.json" || $(cat $HOME/.warengroup/config.json | jq -e . >/dev/null 2>&1 | echo ${PIPESTATUS[1]}) -gt 0 ]] - then - echo '{}' | jq > $HOME/.warengroup/config.json - fi - - mkdir -p $HOME/.ssh/keys - chmod 700 -R $HOME/.ssh/keys - mkdir -p $HOME/.ssh/multiplex - chmod 700 -R $HOME/.ssh/multiplex + echo '{}' | jq > $HOME/.warengroup/config.json fi + + mkdir -p $HOME/.ssh/keys + chmod 700 -R $HOME/.ssh/keys + mkdir -p $HOME/.ssh/multiplex + chmod 700 -R $HOME/.ssh/multiplex } diff --git a/src/functions/stop.sh b/src/functions/stop.sh index e2c0c4a..0010bf4 100644 --- a/src/functions/stop.sh +++ b/src/functions/stop.sh @@ -5,5 +5,10 @@ wx-stop (){ wx-install --auto + if [[ $USERNAME != $USER && $USERNAME != $SUDO_USER && $USERNAME != $LOGNAME ]] + then + wx-logout + fi + exit 1 } diff --git a/wx b/wx index 80ffdf6..6a5f476 100755 --- a/wx +++ b/wx @@ -64,21 +64,17 @@ wx-restricted(){ wx-start(){ wx-header "Warén CLI" h1 - if [[ $USER != "root" && $USER != "local" ]] + mkdir -p $HOME/.warengroup &> /dev/null + + if [[ ! -f "$HOME/.warengroup/config.json" || $(cat $HOME/.warengroup/config.json | jq -e . >/dev/null 2>&1 | echo ${PIPESTATUS[1]}) -gt 0 ]] then - mkdir -p $HOME/.warengroup &> /dev/null - touch $HOME/.warengroup/config.json &> /dev/null - - if [[ ! -f "$HOME/.warengroup/config.json" || $(cat $HOME/.warengroup/config.json | jq -e . >/dev/null 2>&1 | echo ${PIPESTATUS[1]}) -gt 0 ]] - then - echo '{}' | jq > $HOME/.warengroup/config.json - fi - - mkdir -p $HOME/.ssh/keys - chmod 700 -R $HOME/.ssh/keys - mkdir -p $HOME/.ssh/multiplex - chmod 700 -R $HOME/.ssh/multiplex + echo '{}' | jq > $HOME/.warengroup/config.json fi + + mkdir -p $HOME/.ssh/keys + chmod 700 -R $HOME/.ssh/keys + mkdir -p $HOME/.ssh/multiplex + chmod 700 -R $HOME/.ssh/multiplex } wx-stop (){ @@ -88,6 +84,11 @@ wx-stop (){ wx-install --auto + if [[ $USERNAME != $USER && $USERNAME != $SUDO_USER && $USERNAME != $LOGNAME ]] + then + wx-logout + fi + exit 1 } @@ -244,7 +245,7 @@ wx-login(){ elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]] then ORG=cwchristerw - elif [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .org) ]] + elif [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .org) != "null" ]] then ORG=$(cat $HOME/.warengroup/config.json | jq -r .org) else