Index: scripts/start.sh =================================================================== diff -u -r763077dce249b1c3713611429ff0e26e27c4dff3 -r63c6fe7fab869eebdad66b970b3b3ab8e4c5e046 --- scripts/start.sh (.../start.sh) (revision 763077dce249b1c3713611429ff0e26e27c4dff3) +++ scripts/start.sh (.../start.sh) (revision 63c6fe7fab869eebdad66b970b3b3ab8e4c5e046) @@ -23,55 +23,120 @@ DEMO_SETUP=0 DEMO_SWITCH="-D" -SERVER_IP=$CloudSync_DRT_SERVER_IP +MANUFACTURING_SETUP=0 +MANUFACTURING_SWITCH="-E" #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" +SERVER_DRT_WS_QUALITY2="quality2" 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"*) + "$MANUFACTURING_SWITCH") + MANUFACTURING_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 + echo "Device IP Address : $DST_IP" + + if (( $DEMO_SETUP )); then + echo "Device operation Mode : Demo Mode" + else + echo "Device operation Mode : Normal Operation" + fi + + # if it is the update only we don't need the configuration + if (( $MANUFACTURING_SETUP )); then + echo "Device setup Mode : Manufacturing Setup" + + getServerIP + echo "DRT Server IP Address : $SERVER_IP" + + getServerWS + echo "DRT Server Environment: $SERVER_WS" + else + echo "Device setup Mode : Update Only" + SERVER_WS=$SERVER_DRT_WS_PRODUCT + fi + + # create the config.json file + local config_env_json="$SERVER_CONFIG_JSON_WS""_""$SERVER_WS"".""$SERVER_CONFIG_EXT" + local config_json="$SERVER_CONFIG_JSON" + echo "CloudSync config base : "$config_env_json + cp $config_env_json $config_json # copy the config for the selected environment to config.json + if [[ ! -e $config_json ]]; then + echo "The file $config_json cannot be created" + exit 0 + fi + + if (( $MANUFACTURING_SETUP )); then + # 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/" $config_json + #and modify the globals.sh + sed -i "s/$GLOBALS_CONFIG_LINE/$GLOBALS_CONFIG_MDFY$SERVER_IP/" $GLOBALS_FILE + fi +} + 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 "-E : Manufacturing setup mode" + echo " The Manufacturing setup will wipe device configuration, setup, registration," + echo " and nees a fresh configuration, and device registration on the cloud," + echo " therefore the -S and -W is mandatory." + 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 " - quality2" + echo " For example : -Wproduction" exit 0 fi } @@ -86,16 +151,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 @@ -117,14 +172,14 @@ ssh-keygen -N "" -f $SRC_FILE_SSHKEY 1>>$LOG_OUT_FILE 2>>$LOG_ERR_FILE return $? else - echo "Found ssh key " $SRC_FILE_SSHKEY_PUB + echo "Found ssh key :" $SRC_FILE_SSHKEY_PUB fi return 0 } function sshKeyCopy() { - echo "Registering the ssh key on the device $DST_IP" echo "Please wait ..." + echo "Registering the ssh key on the device $DST_IP" ssh-copy-id $SSH_PARAM -f -i $SRC_FILE_SSHKEY_PUB $DST_USER@$DST_IP 1>>$LOG_OUT_FILE 2>>$LOG_ERR_FILE if [ ! $? -eq 0 ]; then echo "Connection to host $DST_IP failed." | tee -a $LOG_OUT_FILE @@ -185,12 +240,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 (( $MANUFACTURING_SETUP )); then :; else return; fi echo_star_comment echo_star_message "Do you want to run in the Manufacturing Mode?" @@ -201,8 +251,8 @@ sshRun "echo $SETUP_ENABLE_MANUFACTURING_MODE > $SETUP_CONF_FILE" echo_star_message "Set the setup in manufacturing mode" else - sshRun "echo '' > $SETUP_CONF_FILE" - echo_star_message "Continuing the setup in normal mode" + echo_star_message "Abort the Manufacturing setup by user" + exit 0 fi } @@ -212,7 +262,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 +280,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 +292,38 @@ 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");; + "$SERVER_DRT_WS_QUALITY2");; + *) + 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 environment: " -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 +406,6 @@ } function main() { - displayHelp "$1" - - defaultIP "$1" - getDeviceIP setupLogs sshKeyGen @@ -337,18 +415,20 @@ manufacturingModePrompt wipe_device + setupDemoMode setupBootupScripts setupSettingsScripts setupConfigurations setupCloudSync setupFonts setupApplication - setupDemoMode } # running the main function +displayHelp "$1" setupParameters "$@" +setupPreparation main "$1" connect - exit 0 +