From 5a1f73702eec94ae5d4b0a630dcc49d23c874a0a Mon Sep 17 00:00:00 2001 From: David Houdek Date: Mon, 16 Oct 2023 15:51:04 +0200 Subject: [PATCH] Implemented derivation of location from $HOSTNAME and started implementing ssh cmd --- iottadd.sh | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/iottadd.sh b/iottadd.sh index 4a21bf6..cc25ef4 100755 --- a/iottadd.sh +++ b/iottadd.sh @@ -7,10 +7,7 @@ BLUE="\033[1;34m" RESET="\033[0m" usage() { - echo -e "${GREEN}Usage: iottadd.sh < -l | -r > < id > < pass > - - -l for usage on local machine - -r for usage on server (remote)${RESET}" + echo -e "${GREEN}Usage: iottadd.sh < id > < pass >${RESET}" } getConf() { @@ -24,7 +21,7 @@ getConf() { } -if [ -z "$3" ]; then +if [ -z "$2" ]; then echo -e "${RED}Not enough arguments!\n${RESET}" usage exit 2 @@ -33,31 +30,32 @@ fi ### MAIN PROGRAM ############################################################################# -if [[ $1 == "-l" ]]; then - # Used on local machine - echo -e "${RED}Not implemented${RESET}" -elif [[ $1 == "-r" ]]; then - # Used on server - echo -e "${GREEN}Running with: ID=${BLUE}${2}${GREEN} and PASS=${BLUE}${3}" - getConf +echo -e "${GREEN}Running with: ID=${BLUE}${1}${GREEN} and PASS=${BLUE}${2}" +getConf - if [ ! -w ./rawkey-generator.py ]; then - echo -e "${RED}You don't have rawkey-generator.py in the same folder or don't have execute permitions${CLEAR}" - exit 1 - fi +if [ ! -w ./rawkey-generator.py ]; then + echo -e "${RED}You don't have rawkey-generator.py in the same folder or don't have execute permitions${CLEAR}" + exit 1 +fi - RAWKEY="0x00"$(python ./rawkey-generator.py "${3}" "Sincoolka IoTT") +RAWKEY="0x00"$(python ./rawkey-generator.py "${2}" "Sincoolka IoTT") - echo -e "${GREEN}Generated raw key (pmk): ${BLUE}${RAWKEY}${CLEAR}" - getConf +echo -e "${GREEN}Generated raw key (pmk): ${BLUE}${RAWKEY}${CLEAR}" +getConf +if [ "$HOSTNAME" == "pride" ]; then + sshCmd="lust-db" +else + echo -en "${GREEN}Enter your username on server: ${PURPLE}" + read -p "" serverUser + echo -en "${RESET}" + sshCmd="-J ${serverUser}@pride.sin.cvut.cz ${serverUser}@lust-db" +fi + +ssh $sshCmd "psql sinis_test 'INSERT INTO nic_dpsk (psk, id_nic) VALUES ('${2}', '${1}');'" ############################################################################ -else - usage - -fi