Index: scripts/globals.sh =================================================================== diff -u -rccddb9de7bc94036e130e034b1de67dca00e028d -rfaf41ef2ba015523623205a84ceb12473f57f022 --- scripts/globals.sh (.../globals.sh) (revision ccddb9de7bc94036e130e034b1de67dca00e028d) +++ scripts/globals.sh (.../globals.sh) (revision faf41ef2ba015523623205a84ceb12473f57f022) @@ -42,6 +42,12 @@ LOG_OUT_FILE="" LOG_ERR_FILE="" +LOG_BASE=$SDCARD_MNT +LOG_LOC_LOG=log +LOG_LOC_ERR=service +EXT_GZIP=gz +EXT_PEND=u + ERR_MISSING_FOLDER=101 ERR_MISSING_FILE=102 ERR_CONNECTION=103 @@ -53,12 +59,14 @@ ERR_SCP_FAIL=110 ERR_INVALID_IP=111 ERR_SD_CARD=112 +ERR_LOGBACKUP_PATH=113 SRC_FILE_SSHKEY="$HOME/.ssh/id_rsa" SRC_FILE_SSHKEY_PUB=$SRC_FILE_SSHKEY.pub SRC_PATH_SCRIPTS="scripts" SRC_PATH_CONFIG="settings" SRC_PATH_CLOUDSYNC="cloudsync" +SRC_PATH_DRYDEMO="dry-demo" SRC_PATH_FONTS="fonts" DST_IP="" @@ -67,6 +75,7 @@ DST_PATH_HOME="/home/$DST_USER" DST_PATH_SCRIPTS="/home/$DST_USER/scripts" DST_PATH_CLOUDSYNC="/home/$DST_USER/cloudsync" +DST_PATH_DRYDEMO="/home/$DST_USER/dry-demo" DST_PATH_FONTS="/usr/share/fonts/truetype" POSTLOG=/tmp/post.log @@ -82,7 +91,7 @@ POSTMSG_BLUETOOTH="Bluetooth" POSTMSG_SHASUM="App shasum" POSTMSG_CLOUDSYNC="CloudSync" -POSTMSG_CLOUDSYNC_RUNNING="CloudSync app IS running" +POSTMSG_SETTINGSCRC="SettingsCRC" TDCTL_NTP_USED=$FALSE TDCTL_RTC_LOCL=$TRUE @@ -106,24 +115,57 @@ SETUP_ENABLE_MANUFACTURING_MODE="ManufacturingMode" SETUP_ENABLE_UpdatingING_MODE="UpdatingMode" -APPLICATION_PARAMS="&" +# Log cli options +# x: enable long name (IMPORTANT: removed for the impact on Test Protocols, and timeline) +# y: enable upload +# z: enable compression +APPLICATION_PARAMS_DEFAULT="-yz" +APPLICATION_PARAMS="" -CloudSync_DRT_SERVER_IP=172.31.99.117 +CloudSync_DRT_SERVER_IP="" CloudSync_DRT_SERVER_PORT=80 CLOUD_USER=cloud CLOUD_HOME=/home/$CLOUD_USER DENALI_USER=denali DENALI_HOME=/home/$DENALI_USER +DEMO_USER=root +DEMO_HOME=/home/$DEMO_USER +SETTING_CONF_FOLDER_PATH=/var/configurations +SETTINGS_CRC_FILE_PATH=$DENALI_HOME/settings.crc + +CLOUDSYNC_CONFIG_SRC=$CLOUD_HOME/cloudsync/cloudsync/config/config.json +CLOUDSYNC_CONFIG_DST=$SETTING_CONF_FOLDER_PATH/CloudSync/config/config.json + +DEMO_MODE=0 +P_CANBUS=can0 +V_CANBUS=can1 +D_CANBUS=$P_CANBUS + +function checkDemoMode() { + if [ -d "$DEMO_HOME/$SRC_PATH_DRYDEMO" ]; then + DEMO_MODE=1 + fi +} + +# *** this function should be used without brackets in the if to be effective. +function isDemoMode() { + if [ $DEMO_MODE -eq 1 ]; then + echo $TRUE + else + echo $FALSE + fi +} + function user_input() { read -p "$1? $2" -n 1 -r if [ "$CONTINUE" == "y" ]; then echo "" return $TRUE else echo "" - return $FALSE + return $FALSE fi } @@ -241,7 +283,7 @@ function post_out () { echo "$1" >> $POSTOUT; } function post_out_dash () { echo "$COMMENT_DASH$1" >> $POSTOUT; } -function debug () { +function debug () { echo_dash_comment echo_dash_message "$1" echo_dash_comment @@ -274,35 +316,66 @@ killall $DENALI_BIN } +function queryOSVersion() { + #get the OS version ----------------------- OS Version + post_log_dash " OS Version " + post_log "$(cat /etc/os-release)" +} + function setupEthernet() { #setting up ethernet----------------------- Ethernet post_log_dash " Ethernet " ieth=eth0 udhcpc --timeout=5 --retries=2 -n -i $ieth - post_log "$(ip addr show $ieth)" # -details -statistics + post_log "$(ip addr show $ieth)" # -details -statistics } -function setupCANBus() { +function setupPCAN() { #setting up can interface ----------------- CANBus post_log_dash " CANBus " #current settings can be retrieved by the command below - #$ ip -details -statistics link show can0 - ip link set can0 up type can bitrate 250000 restart-ms 100 - ifconfig can0 txqueuelen 4000 - candump can0 -T1 # check if candump can successfully use the port. will terminate in 1ms + #$ ip -details -statistics link show $P_CANBUS + ip link set $P_CANBUS up type can bitrate 250000 restart-ms 100 + ifconfig $P_CANBUS txqueuelen 4000 +} + +function setupVCAN() { + modprobe vcan + ip link add dev $V_CANBUS type vcan + ip link set $V_CANBUS up +} + +function checkCANBus() { + candump $D_CANBUS -T1 # check if candump can successfully use the port. will terminate in 1ms if [ $? -eq 0 ]; then post_log_pass "$POSTMSG_CANBUS$POSTMSG_POSTFIX_PASSED" - post_log "$(ip link show can0)" # -details -statistics + post_log "$(ip link show $D_CANBUS)" # -details -statistics else post_log_fail "$POSTMSG_CANBUS$POSTMSG_POSTFIX_FAILED" fi } +function setupCANBus() { + if [ "$1" == "setup" ];then + D_CANBUS=$P_CANBUS # it is the default but kept to be consistent. + setupPCAN + else + if [ $(isDemoMode) -eq $TRUE ]; then + D_CANBUS=$V_CANBUS + setupVCAN + else + D_CANBUS=$P_CANBUS # it is the default but kept to be consistent. + setupPCAN + fi + fi + checkCANBus +} + function setupSDCard() { #mounting sdcard -------------------------- SD-CARD post_log_dash " SD-CARD " mkdir -p $SDCARD_MNT - mount $SDCARD_PRT $SDCARD_MNT + mount -o noexec,nodev,nosuid $SDCARD_PRT $SDCARD_MNT SDCTEST="$(mount | grep "$SDCARD_PRT on $SDCARD_MNT type $SDCARD_TYP_NAME (rw,")" if ! [ -z "$SDCTEST" ]; then SDINFO="$(df -h | grep -i $SDCARD_MNT)" @@ -408,7 +481,6 @@ fi } - function testApplicationShasum_setup() { # ----------------------------------------- Sha256Sum post_log_dash " Sha256Sum " @@ -422,7 +494,6 @@ fi } - function testApplicationShasum_local() { # ----------------------------------------- Sha256Sum post_log_dash " Sha256Sum " @@ -436,7 +507,6 @@ fi } - function testCloudSystem() { # ----------------------------------------- CloudSystem post_log_dash " CloudSystem " @@ -453,14 +523,20 @@ # removing the previous treatment logs so the new buff starts with fresh sequence echo "Removing CloudSync I/O buff" local CLOUDSYNC_LOGS="$SDCARD_MNT/$CLOUDSYNC_FOLDER/" + local CLOUDSYNC_CONF="$CLOUDSYNC_PATH/cloudsync/config/" + local CLOUDSYNC_MODE="" + if [[ "$APPLICATION_PARAMS" == *"-E"* ]]; then + CLOUDSYNC_MODE="upgrade" + else + CLOUDSYNC_MODE="update" + fi rm $(find $CLOUDSYNC_LOGS -name "*[_inp,_out].buf" ) 1>> $POSTOUT 2>> $POSTERR - + rm $(find $CLOUDSYNC_CONF -name "config_*.json" ) 1>> $POSTOUT 2>> $POSTERR echo "Executing the CloudSync" cd $CLOUDSYNC_PATH - ./cs.py start debug & - sleep 2 - CLOUDSYNC_STATUS="$(./cs.py status)" - if [ "$CLOUDSYNC_STATUS" == "$POSTMSG_CLOUDSYNC_RUNNING" ]; then + ./cs.py start debug $CLOUDSYNC_MODE & + CLOUDSYNC_STATUS="$(ps ax | grep -e cs.py -e cloud_sync.py | grep -v grep)" + if [ -n "$CLOUDSYNC_STATUS" ]; then post_log_pass "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED" else post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" @@ -497,10 +573,9 @@ echo "" } - -function startCloudSync_local() { - # ----------------------------------------- CloudSync - post_log_dash " CloudSync " +function cleanCloudSyncBufs() { + # ----------------------------------------- CloudSync buffs cleanup + post_log_dash " CloudSync buffs cleanup" local CLOUDSYNC_PATH=$CLOUD_HOME/$CLOUDSYNC_FOLDER local DATE_UTC=$(date -u +%Y_%m_%d) if [ -d $CLOUDSYNC_PATH ]; then @@ -514,12 +589,28 @@ sudo -u $CLOUD_USER touch "$CLOUDSYNC_LOGS/$DATE_UTC"_out.buf sudo -u $DENALI_USER touch "$CLOUDSYNC_LOGS/$DATE_UTC"_inp.buf + fi +} + +function startCloudSync_local() { + # ----------------------------------------- CloudSync + post_log_dash " CloudSync " + local CLOUDSYNC_PATH=$CLOUD_HOME/$CLOUDSYNC_FOLDER + local DATE_UTC=$(date -u +%Y_%m_%d) + if [ -d $CLOUDSYNC_PATH ]; then + post_log "Verify the CloudSync config" + if [ "$( diff $CLOUDSYNC_CONFIG_SRC $CLOUDSYNC_CONFIG_DST )" != "" ]; then + post_log "CloudSync configuration updated" + sudo -u $CLOUD_USER cp $CLOUDSYNC_CONFIG_SRC $CLOUDSYNC_CONFIG_DST 1>> $POSTOUT 2>> $POSTERR + else + post_log "CloudSync configuration verified" + fi + echo "Executing the CloudSync" cd $CLOUDSYNC_PATH sudo -u $CLOUD_USER ./cs.py start - sleep 2 - CLOUDSYNC_STATUS="$(sudo -u $CLOUD_USER ./cs.py status)" - if [ "$CLOUDSYNC_STATUS" == "$POSTMSG_CLOUDSYNC_RUNNING" ]; then + CLOUDSYNC_STATUS="$(ps ax | grep -e cs.py -e cloud_sync.py | grep -v grep)" + if [ -n "$CLOUDSYNC_STATUS" ]; then post_log_pass "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED" else post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" @@ -531,21 +622,72 @@ fi } - function startApplication_local() { # ----------------------------------------- Denali post_log_dash " Denali " #launching denali application DENALI_VERSION="$($DENALI_HOME/$DENALI_BIN -v)" if [ -n "$DENALI_VERSION" ]; then post_log_pass "$DENALI_VERSION" # log UI Software version - sudo -u $DENALI_USER $DENALI_HOME/$DENALI_BIN $APPLICATION_PARAMS 1>> /tmp/denali.out 2>> /tmp/denali.out & + if [ $(isDemoMode) -eq $TRUE ]; then + APPLICATION_PARAMS="$APPLICATION_PARAMS"" -q -D -A $D_CANBUS" + fi + sudo -u $DENALI_USER $DENALI_HOME/$DENALI_BIN $APPLICATION_PARAMS_DEFAULT $APPLICATION_PARAMS -C 1>> /tmp/denali.out 2>> /tmp/denali.out & else post_log_fail "Unknown Applicaion Version for $DENALI_HOME/$DENALI_BIN" fi } +function startDemoMode_local() { + # *** eliminated brackets are intentional. *** + if [ $(isDemoMode) -eq $TRUE ]; then + # ----------------------------------------- Demo Mode + post_log_dash " Demo Mode " + local DRYDEMO_PATH=$DEMO_HOME/$SRC_PATH_DRYDEMO + cd $DRYDEMO_PATH + ./run.py > $DRYDEMO_PATH.log & # create the log file at same level and name of the folder. + post_log "Dry-Demo Started" + fi +} +function log_backup() { + if [[ "$1" == "" ]]; then + post_log "Log Backup failed: Missing log location" + return $ERR_LOGBACKUP_PATH; + fi + local LOG_PATH="$LOG_BASE"/"$1" + cd "$LOG_PATH" + for logname in $(find -type f ! -name "*.$EXT_PEND.*"); do + name=$(basename $logname) + base="${name%%.*}" + ext="${name##*.}" + exts="${name#*.}" + #DEBUG echo name: $base + #DEBUG echo ext : $ext + #DEBUG echo exts: $exts + if [[ "$ext" == "$EXT_GZIP" ]]; then + mv "$name" "$base.u.$exts" + else + echo gzip "$name" + echo mv "$name.$EXT_GZIP" "$base.$EXT_PEND.$exts.$EXT_GZIP" + fi + echo + done +} + +function log_backup_logApp() { + log_backup $LOG_LOC_LOG +} + +function log_backup_logErr() { + log_backup $LOG_LOC_ERR +} + +function backupApplicationLogs() { + log_backup_logApp + log_backup_logErr +} + function timerStart() { time_start=$(date +%s) } @@ -562,8 +704,11 @@ function applicationPOST() { setupConsoleout disableRootSSH - cleanupPOSTLogs - setupCANBus + cleanupPOSTLogs + backupApplicationLogs + checkDemoMode + queryOSVersion + setupCANBus $1 setupResolved killApplication setupEthernet