Index: scripts/start.sh =================================================================== diff -u -r763077dce249b1c3713611429ff0e26e27c4dff3 -r3e5d7dc83d85c4727634d366938b40d20cfebc4e --- scripts/start.sh (.../start.sh) (revision 763077dce249b1c3713611429ff0e26e27c4dff3) +++ scripts/start.sh (.../start.sh) (revision 3e5d7dc83d85c4727634d366938b40d20cfebc4e) @@ -23,55 +23,115 @@ DEMO_SETUP=0 DEMO_SWITCH="-D" -SERVER_IP=$CloudSync_DRT_SERVER_IP +UPDATE_SETUP=0 +UPDATE_SWITCH="-U" #Update only setup + +SERVER_IP="" # $CloudSync_DRT_SERVER_IP +SERVER_WS="" SERVER_PORT="3000" -SERVER_SWITCH="-S" +SERVER_SWITCH_DRT_WS="-W" #DRT server workspace/environment +SERVER_SWITCH_DRT_IP="-S" #DRT server IP address SERVER_CONFIG_LINE=".*\"url_mft\".*" SERVER_CONFIG_BGN=" \"url_mft\": \"http:\/\/" SERVER_CONFIG_END=":$SERVER_PORT\"," -SERVER_CONFIG_FILE="./cloudsync/cloudsync/config/config.json" +SERVER_CONFIG_FILE="./cloudsync/cloudsync/config/config" +SERVER_CONFIG_EXT="json" +SERVER_CONFIG_JSON="$SERVER_CONFIG_FILE.$SERVER_CONFIG_EXT" +SERVER_CONFIG_JSON_WS="$SERVER_CONFIG_FILE" +SERVER_DRT_WS_PRODUCT="production" +SERVER_DRT_WS_STAGING="staging" +SERVER_DRT_WS_QUALITY="quality" GLOBALS_CONFIG_MDFY="CloudSync_DRT_SERVER_IP=" GLOBALS_CONFIG_LINE="CloudSync_DRT_SERVER_IP=.*" GLOBALS_FILE="./globals.sh" - # command line parameters detection function setupParameters() { + DST_IP="$1" for arg in "$@"; do case $arg in "$DEMO_SWITCH") DEMO_SETUP=1 - echo "Setup started for demo mode" ;; - "$SERVER_SWITCH"*) + "$UPDATE_SWITCH") + UPDATE_SETUP=1 + ;; + "$SERVER_SWITCH_DRT_IP"*) SERVER_IP="${arg:2}" - getServerIP - if [[ $SERVER_IP == $CloudSync_DRT_SERVER_IP ]]; then - # same as default and no need to update. - return - fi - #If the server IP is not given or is invalid will be asked to enter and the defualt Diality prefered will be suggested. - #If the server IP is valid and accepted then change the CloudSync conf file - sed -i "s/$SERVER_CONFIG_LINE/$SERVER_CONFIG_BGN$SERVER_IP$SERVER_CONFIG_END/" $SERVER_CONFIG_FILE - #and modify the globals.sh - sed -i "s/$GLOBALS_CONFIG_LINE/$GLOBALS_CONFIG_MDFY$SERVER_IP/" $GLOBALS_FILE - echo "DRT Server IP: $SERVER_IP" ;; + "$SERVER_SWITCH_DRT_WS"*) + SERVER_WS="${arg:2}" + ;; esac done } +function setupPreparation() { + getDeviceIP + if (( $DEMO_SETUP )); then + echo "Device operation Mode : Demo Mode" + else + echo "Device operation Mode : Normal Operation" + fi + echo "Device IP Address : $DST_IP" + + # if it is the update only we don't need the configuration + if (( $UPDATE_SETUP )); then + echo "Device setup Mode : Update Only" + return + fi + echo "Device setup Mode : Manufacturing Setup" + + getServerIP + echo "DRT Server IP Address : $SERVER_IP" + + getServerWS + echo "DRT Server Environment: $SERVER_WS" + + # create the conf file + local config_env_json="$SERVER_CONFIG_FILE" + local config_json="$SERVER_CONFIG_FILE" + + + # creat the config.json file + cp "$SERVER_CONFIG_JSON_WS""_""$SERVER_WS"".""$SERVER_CONFIG_EXT" $SERVER_CONFIG_JSON + if [[ ! -e $SERVER_CONFIG_JSON ]]; then + echo "The file $SERVER_CONFIG_JSON cannot be created" + exit 0 + fi + + # setting up the DRT Server IP address + #If the server IP is not given or is invalid will be asked to enter and the defualt Diality prefered will be suggested. + #If the server IP is valid and accepted then change the CloudSync conf file + sed -i "s/$SERVER_CONFIG_LINE/$SERVER_CONFIG_BGN$SERVER_IP$SERVER_CONFIG_END/" $SERVER_CONFIG_JSON + #and modify the globals.sh + sed -i "s/$GLOBALS_CONFIG_LINE/$GLOBALS_CONFIG_MDFY$SERVER_IP/" $GLOBALS_FILE +} + function displayHelp() { if [ "$1" = "-h" -o "$1" = "--help" ]; then echo -e "-h \t This help" - echo "usage start.sh [ [xxx.xxx.xxx.xxx] ] -D -S[[xxx.xxx.xxx.xxx]]" - echo "device IP : M ust always be the first parameter" - echo "-D : Indicating the system is going to be setup in Demo mode." - echo " The Demo application folder need to be copied to the update folder." - echo "-S : Shall include the server IP in complete IP format [xxx.xxx.xxx.xxx]" + echo "usage start.sh [ [xxx.xxx.xxx.xxx] ] -D [-S[xxx.xxx.xxx.xxx] -W]" + echo "device IP : The Device IP Address Under Setup" + echo " Must always be the first parameter" + echo "-D : Demo mode" + echo " Demo mode mode can be used to use the device as a demo unit." + echo " In this mode Application will not work with the actual hardware and will work in simulation mode." + echo " The Demo application folder need to be copied to the update folder manually." + echo "-U : Update mode" + echo " Update mode can only be used when the device is already registered," + echo " Therefore the -S and -W will be ignored." + echo "-S : The DRT Server IP address" + echo " Need to be entered fully in a valid IP format [xxx.xxx.xxx.xxx]" echo " There should be no space between -S and the server IP address" echo " For example : -S192.168.1.5" + echo "-W : The DRT Server Workspace/Environment:" + echo " Shall only include the server environment from the following list:" + echo " - production" + echo " - staging" + echo " - quality" + echo " For example : -Wproduction" exit 0 fi } @@ -86,16 +146,6 @@ fi } -function defaultIP() { - if [ -n "$1" ]; then - if [ ${#1} -gt $IP_SEG_MAX_LEN ]; then - DST_IP=$1 - else - DST_IP=$IP_EMT"$1" - fi - fi -} - function setupLogs() { local log_location=$LOG_LOCATION/$DST_IP mkdir -p $log_location @@ -185,12 +235,7 @@ } function manufacturingModePrompt() { -# I set to always enabled for now to always go to the manufacturing mode -# 1 - Even for normal setup start is moving files to /home/root, so the lockdown needs to run to move files. -# 2 - The UI still needs to be executed to decrypt the /var/configurations, otherwise the configurations can not be updated, -# and I don't have the ability to just decrypt and exit right now. -# Note: after the Cybersecurity release I will improve the user experience and will make it easier for manufacturing. -# CONTINUE="y" + if (( $UPDATE_SETUP )); then return; fi echo_star_comment echo_star_message "Do you want to run in the Manufacturing Mode?" @@ -212,7 +257,7 @@ if [ $? -eq 0 ]; then break else - read -p "Please enter the device Ip address: " -e -i "$IP_EMT" -r DST_IP + read -p "Please enter the device Ip address: " -e -i "" -r DST_IP validIP "$DST_IP" if [ $? -eq 0 ]; then break @@ -230,7 +275,7 @@ if [ $? -eq 0 ]; then break else - read -p "Please enter the server Ip address: " -e -i "$CloudSync_DRT_SERVER_IP" -r SERVER_IP + read -p "Please enter the server Ip address: " -e -i "" -r SERVER_IP validIP "$SERVER_IP" if [ $? -eq 0 ]; then break @@ -242,6 +287,39 @@ done } +function validWS() { + if [[ -z $SERVER_WS ]]; then return 1; fi + + case $SERVER_WS in + "$SERVER_DRT_WS_PRODUCT");; + "$SERVER_DRT_WS_STAGING");; + "$SERVER_DRT_WS_QUALITY");; + *) + echo "The entered server environment is not valid [$SERVER_WS]" + return 1 + esac + + return 0 +} + +function getServerWS() { + while true; do + validWS "$SERVER_WS" + if [ $? -eq 0 ]; then + break + else + read -p "Please enter the server Ip address: " -e -i "" -r SERVER_WS + validWS "$SERVER_WS" + if [ $? -eq 0 ]; then + break + else + echo "The entered server environment is not valid [$SERVER_WS]" + exitConfirm $? + fi + fi + done +} + function setupBootupScripts() { echo_dash_comment echo_dash_message "Installing bootup scripts" | tee -a $LOG_OUT_FILE @@ -324,10 +402,6 @@ } function main() { - displayHelp "$1" - - defaultIP "$1" - getDeviceIP setupLogs sshKeyGen @@ -347,8 +421,10 @@ } # running the main function +displayHelp "$1" setupParameters "$@" +setupPreparation main "$1" connect - exit 0 +