Index: scripts/autostart =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r025abd59dd1582ac0a7ad7af79358929042ea4bc --- scripts/autostart (.../autostart) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ scripts/autostart (.../autostart) (revision 025abd59dd1582ac0a7ad7af79358929042ea4bc) @@ -17,7 +17,9 @@ case "$1" in start) logger "Starting autostart scripts" - /home/root/run.sh + HOME="/home/root" + cd "$HOME" + ./run.sh "$HOME" logger $? exit 0 ;; Index: scripts/globals.sh =================================================================== diff -u --- scripts/globals.sh (revision 0) +++ scripts/globals.sh (revision 025abd59dd1582ac0a7ad7af79358929042ea4bc) @@ -0,0 +1,198 @@ +#!/bin/sh +########################################################################### +# +# Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. +# +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# +# @file globals.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 14-Dec-2022 +# @author (original) Behrouz NematiPour +# @date (original) 14-Dec-2022 +############################################################################ + +# @details +# This script includes the global variables and functions to be used in the setup and start scripts. + +TRUE=1 +FALSE=0 + +COMMENT_STAR="********************************************************************************" +COMMENT_DASH="--------------------------------------------------------------------------------" + +DATETIME="$1 $2" + +#DO NOT MODIFY VARIABLES, unless the denali applicaiton is updated as well to match. +SDCARD_DEV=/dev/mmcblk1 +SDCARD_PRT=/dev/mmcblk1p1 +SDCARD_MNT=/media/sd-card +SDCARD_TYP_NAME=ext4 +SDCARD_TYP_NUMB=83 + +USB_DEV=/dev/sda1 +USB_MNT=/media/usb + +CLOUDSYNC_FOLDER=cloudsync # both for log and application + +LOG_LOCATION=$HOME/Desktop +LOG_OUT_FILE="" +LOG_ERR_FILE="" + +ERR_MISSING_FOLDER=101 +ERR_MISSING_FILE=102 +ERR_CONNECTION=103 +ERR_DENALI_BIN=104 +ERR_FONTS_EMTY=105 +ERR_FONTS_PATH=106 +ERR_KILLPROMPT=107 +ERR_MISSING_KEY=109 +ERR_SCP_FAIL=110 +ERR_INVALID_IP=111 +ERR_SD_CARD=112 + +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_FONTS="fonts" + +DST_IP="" +DST_USER=root +DST_PATH_CONFIG="/home/$DST_USER/.config" +DST_PATH_HOME="/home/$DST_USER" +DST_PATH_SCRIPTS="/home/$DST_USER/scripts" +DST_PATH_CLOUDSYNC="/home/$DST_USER/cloudsync" +DST_PATH_FONTS="/usr/share/fonts/truetype" + +POSTLOG=$HOME/post.log +POSTERR=$HOME/post.err +POSTOUT=$HOME/post.out +POSTMSG_POSTFIX_PASSED=" passed" +POSTMSG_POSTFIX_FAILED=" failed" +POSTMSG_CANBUS="CANBus" +POSTMSG_SDCARD="SD-CARD" +POSTMSG_TOUCH="Touch" +POSTMSG_RTC="RTC" +POSTMSG_WIFI="WiFi" +POSTMSG_BLUETOOTH="Bluetooth" +POSTMSG_SHASUM="App shasum" +POSTMSG_CLOUDSYNC="CloudSync" +POSTMSG_CLOUDSYNC_RUNNING="CloudSync app IS running" + +TDCTL_NTP_USED=$FALSE +TDCTL_RTC_LOCL=$TRUE +TDCTL_TIMEZONE=America/Los_Angeles + +IP_SEG_MAX_LEN=3 +IP_EMT="192.168.10." +SSH_PARAM="-oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -oLogLevel=ERROR -oConnectTimeout=2" + +CMD_RTC_EPOCH="cat /sys/class/rtc/rtc0/since_epoch" +CMD_SDCARD_DEV="ls $SDCARD_DEV" +CMD_SDCARD_PRT="ls $SDCARD_PRT" +CMD_LINUX_TYPE="sfdisk --part-type $SDCARD_DEV 1" + +INITD_LOCATION=/etc/init.d/ +INITD_AUTOSTART=autostart +DENALI_BIN=denali +LAUNCH_SCR=run.sh + +function confirm() { + read -p "$1? [y,n]" -n 1 -r CONTINUE + if [ "$CONTINUE" == "y" ]; then + echo "" + return $TRUE + else + echo "" + return $FALSE + fi +} + +string_trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + printf '%s' "$var" +} + +function echo_star_comment() { + echo "$COMMENT_STAR"" $1 " +} + +function echo_star_message() { + echo " * $1" +} + +function echo_dash_comment() { + echo "$COMMENT_DASH"" $1 " +} + +function echo_dash_message() { + echo " $1" +} + +function timestamp() { + echo $(date +"%Y%m%d-%H%M%S") +} + +function validIP() +{ + local ip=$1 + if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + OIFS=$IFS + IFS='.' + ip=($ip) + IFS=$OIFS + if [[ ${ip[0]} -gt 255 && \ + ${ip[1]} -gt 255 && \ + ${ip[2]} -gt 255 && \ + ${ip[3]} -gt 255 ]]; then + return $ERR_INVALID_IP + fi + else + return $ERR_INVALID_IP + fi + return 0 +} + +function existsFolder() { + if [ ! -d "$1" ]; then + return "$ERR_MISSING_FOLDER" + fi +} + +function existsFile() { + if [ ! -f "$1" ]; then + return "$ERR_MISSING_FILE" + fi +} + +COUT="/dev/null" + +function post_log_clear () { echo "" > $POSTLOG; } +function post_err_clear () { echo "" > $POSTERR; } +function post_out_clear () { echo "" > $POSTOUT; } + +function post_log_pass () { echo "$1" >> $POSTLOG; echo "[ OK ] $1" > "$COUT"; } +function post_log_fail () { echo "$1" >> $POSTLOG; echo "[FAILED] $1" > "$COUT"; } +function post_log_dash () { echo "$COMMENT_DASH$1" >> $POSTLOG; echo "$COMMENT_DASH$1" > "$COUT"; } +function post_log_star () { echo "$COMMENT_DASH$1" >> $POSTLOG; echo "$COMMENT_STAR$1" > "$COUT"; } +function post_log () { echo "$1" >> $POSTLOG; echo " $1" > "$COUT"; } + +function post_err () { echo "$1" >> $POSTERR; } +function post_err_dash () { echo "$COMMENT_DASH$1" >> $POSTERR; } + +function post_out () { echo "$1" >> $POSTOUT; } +function post_out_dash () { echo "$COMMENT_DASH$1" >> $POSTOUT; } + +function debug () { + echo_dash_comment + echo_dash_message "$1" + echo_dash_comment +} Index: scripts/run.sh =================================================================== diff -u -r265ce7409a0ea99a4ae059f5ce7978c9cdb10631 -r025abd59dd1582ac0a7ad7af79358929042ea4bc --- scripts/run.sh (.../run.sh) (revision 265ce7409a0ea99a4ae059f5ce7978c9cdb10631) +++ scripts/run.sh (.../run.sh) (revision 025abd59dd1582ac0a7ad7af79358929042ea4bc) @@ -12,210 +12,185 @@ # @date (last) 28-Sep-2022 # @author (original) Behrouz NematiPour # @date (original) 28-Oct-2019 -# +# @date 09-Dec-2022 ############################################################################ -function currDate() -{ - echo $(date +"%d%m%Y%H%M%S") -} +echo "HOME : $HOME " > /home/root/post.debug +HOME="$1" +source ./globals.sh +COUT="/dev/$(echo $(dmesg | grep "printk: console") | sed 's/.*printk: console.*\(tty.*\)].*/\1/')" +echo "COMMENT_DASH: $COMMENT_DASH " >> /home/root/post.debug +echo "HOME : $HOME " >> /home/root/post.debug +echo "COUT : $COUT " >> /home/root/post.debug +echo "POSTLOG : $POSTLOG " >> /home/root/post.debug - -#DO NOT MODIFY VARIABLES -#unless the denali applicaiton is updated as well to match. -HOME=/home/root - -SDCARD_DEV=/dev/mmcblk1p1 -SDCARD_MNT=/media/sd-card -SDCARD_TYP=ext4 -USB_DEV=/dev/sda1 -USB_MNT=/media/usb -CLOUDSYNC_FOLDER=cloudsync # both for log and application - -POSTLOG=$HOME/post.log -POSTERR=$HOME/post.err -POSTOUT=$HOME/post.out -POSTMSG_POSTFIX_PASSED=" passed" -POSTMSG_POSTFIX_FAILED=" failed" -POSTMSG_CANBUS="CANBus" -POSTMSG_SDCARD="SD-CARD" -POSTMSG_TOUCH="Touch" -POSTMSG_RTC="RTC" -POSTMSG_WIFI="WiFi" -POSTMSG_BLUETOOTH="Bluetooth" -POSTMSG_SHASUM="App shasum" -POSTMSG_CLOUDSYNC="CloudSync" -POSTMSG_CLOUDSYNC_RUNNING="CloudSync app IS running" - # cleanup the POST log file -echo "Start: $(currDate)" > $POSTLOG -echo "" > $POSTERR -echo "" > $POSTOUT +post_log_clear +post_err_clear +post_out_clear +post_log_star " ***** " +post_log "Start: $(timestamp)" # log the current date, time #create folders for sd-card and usb if not exist mkdir -p $SDCARD_MNT mkdir -p $USB_MNT # ---------------------------------------- STOP denali in case running (sys not rebooted) -killall denali +killall $DENALI_BIN -# ---------------------------------------- UPDATE -#mounting usb -mount $USB_DEV $USB_MNT -USBTEST="$(mount | grep "$USB_MNT")" -if ! [ -z "$USBTEST" ]; then - echo ":: USB drive found and mounted on $USB_MNT" - #A simple none secure update - if [ -e $USB_MNT/denali ]; then - mv $HOME/denali $HOME/denali.$(currDate) - cp $USB_MNT/denali $HOME/denali - # check if update where successful - if [ $? -eq 0 ]; then - sync;sync;sync; - echo ":: Denali application has been updated with the one on the USB drive" - mv $USB_MNT/denali $USB_MNT/denali.updated - sync;sync;sync; - fi - fi -fi - -# ---------------------------------------- SETUP & POST -#Here only passed is logged and if nothing added to the post.log means it failed. - - #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 if [ $? -eq 0 ]; then - echo $POSTMSG_CANBUS$POSTMSG_POSTFIX_PASSED >> $POSTLOG + post_log_pass "$POSTMSG_CANBUS$POSTMSG_POSTFIX_PASSED" + post_log "$(ip link show can0)" # -details -statistics else - echo $POSTMSG_CANBUS$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_CANBUS$POSTMSG_POSTFIX_FAILED" fi #mounting sdcard -------------------------- SD-CARD -mount $SDCARD_DEV $SDCARD_MNT -SDCTEST="$(mount | grep "$SDCARD_DEV on $SDCARD_MNT type $SDCARD_TYP (rw,")" +post_log_dash " SD-CARD " +mount $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)" - echo $POSTMSG_SDCARD$POSTMSG_POSTFIX_PASSED >> $POSTLOG - echo $SDCTEST >> $POSTLOG - echo $SDINFO >> $POSTLOG + post_log_pass "$POSTMSG_SDCARD$POSTMSG_POSTFIX_PASSED" + post_log "$SDCTEST" + post_log "$SDINFO" else - echo $POSTMSG_SDCARD$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_SDCARD$POSTMSG_POSTFIX_FAILED" fi #test the touch screen -------------------- Touch -#if loaded successful it has a long description with "Touch" keyword, 'T' capital. -#if fails has a one line error with "touch" keyword, 't' non-capital. -#if there is other issues can even be empty. -TSTEST="$(dmesg | grep Touch)" -if [ $? -eq 0 ]; then - echo $POSTMSG_TOUCH$POSTMSG_POSTFIX_PASSED >> $POSTLOG +post_log_dash " Touch " +# when successfully connected and can be loaded +# Sitronix touch driver 2.10.2 Release date: 20180809 +# atmel_mxt_ts 3-004a: Direct firmware load for maxtouch.cfg failed with error -2 +# atmel_mxt_ts 3-004a: Touchscreen size X1279Y799 +# input: Atmel maXTouch Touchscreen as /devices/platform/soc@0/soc@0:bus@30800000/30a50000.i2c/i2c-3/3-004a/input/input2 +# When NOT connected +# Sitronix touch driver 2.10.2 Release date: 20180809 +TSTEST="$(dmesg | grep "input: Atmel maXTouch Touchscreen as ")" +if [ "$?" -eq 0 ]; then + post_log_pass "$POSTMSG_TOUCH$POSTMSG_POSTFIX_PASSED" + post_log "$TSTEST" else - echo $POSTMSG_TOUCH$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_TOUCH$POSTMSG_POSTFIX_FAILED" fi #test the RTC ----------------------------- RTC +post_log_dash " RTC" #may not be an accurate test but sufficient for now #and could not find a way to get the rtc clock with the higher resolusion #it should not be confused with date command which is system date/time and not hwclock hwclock -r # if there is any issue with rtc hwclock will show errors if [ $? -eq 0 ]; then - RTC1=$(cat /sys/class/rtc/rtc0/since_epoch) + RTC1=$($CMD_RTC_EPOCH) sleep 1 - RTC2=$(cat /sys/class/rtc/rtc0/since_epoch) + RTC2=$($CMD_RTC_EPOCH) if [ $(($RTC2 - $RTC1)) -eq 1 ]; then - echo $POSTMSG_RTC$POSTMSG_POSTFIX_PASSED >> $POSTLOG + post_log_pass "$POSTMSG_RTC$POSTMSG_POSTFIX_PASSED" else - echo $POSTMSG_RTC$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_RTC$POSTMSG_POSTFIX_FAILED" fi fi -# ---------------------------------------- Connections -# stop the connection manager daemon -killall connmand - - -# ---------------------------------------- Bluetooth +# ----------------------------------------- Bluetooth +post_log_dash " Bluetooth " /usr/share/silex-uart/silex-uart.sh start 1>> $POSTOUT 2>> $POSTERR sleep 5 hciconfig hci0 up if [ $? -eq 0 ]; then - echo $POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_PASSED >> $POSTLOG + post_log_pass "$POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_PASSED" + post_log "$(hciconfig hci0)" else - echo $POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_FAILED" fi -# ---------------------------------------- WiFi +# ----------------------------------------- WiFi +post_log_dash " WiFi " killall wpa_supplicant 1>> $POSTOUT 2>> $POSTERR if [[ ! -z $(dmesg | grep "wlan: driver loaded") ]]; then - echo $POSTMSG_WIFI$POSTMSG_POSTFIX_PASSED >> $POSTLOG + post_log_pass "$POSTMSG_WIFI$POSTMSG_POSTFIX_PASSED" + post_log "$(dmesg | grep -i wlan:)" + post_log "$(ip link show wlan0)" # -details -statistics else - echo $POSTMSG_WIFI$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_WIFI$POSTMSG_POSTFIX_FAILED" fi -# ---------------------------------------- Sha256Sum +# ----------------------------------------- Sha256Sum +post_log_dash " Sha256Sum " #check the denali applicatoin checksum -SHA_ACT=$(tail -c 83 $HOME/denali | cut -c19-82) -SHA_EXP=$(head -c -83 $HOME/denali | sha256sum -b --tag | cut -c14-77) +SHA_ACT=$(tail -c 83 $HOME/$DENALI_BIN | cut -c19-82) +SHA_EXP=$(head -c -83 $HOME/$DENALI_BIN | sha256sum -b --tag | cut -c14-77) if [ "$SHA_ACT" == "$SHA_EXP" ]; then - echo $POSTMSG_SHASUM$POSTMSG_POSTFIX_PASSED >> $POSTLOG + post_log_pass "$POSTMSG_SHASUM$POSTMSG_POSTFIX_PASSED" else - echo $POSTMSG_SHASUM$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_SHASUM$POSTMSG_POSTFIX_FAILED" fi -# ---------------------------------------- CloudSync -if [ -d $CLOUDSYNC_FOLDER ]; then +# ----------------------------------------- CloudSync +post_log_dash " CloudSync " +if [ -d $HOME/$CLOUDSYNC_FOLDER ]; then # moving/ backing up the previous treatment logs so the new buff starts with fresh sequence echo "Backing up CloudSync I/O buff" CLOUDSYNC_PATH="$SDCARD_MNT"/"$CLOUDSYNC_FOLDER" - CLOUDSYNC_BACKUP="$CLOUDSYNC_PATH"_backup/$(currDate)/ + CLOUDSYNC_BACKUP="$CLOUDSYNC_PATH"_backup/$(timestamp)/ mkdir -p $CLOUDSYNC_BACKUP - mv $CLOUDSYNC_PATH/* $CLOUDSYNC_BACKUP - rm $HOME/$CLOUDSYNC_FOLDER/data/* - echo "Starting CloudSync" >> $POSTLOG + mv $CLOUDSYNC_PATH/* $CLOUDSYNC_BACKUP 1>> $POSTOUT 2>> $POSTERR + rm $HOME/$CLOUDSYNC_FOLDER/data/* 1>> $POSTOUT 2>> $POSTERR cd $HOME/$CLOUDSYNC_FOLDER/ python3 ./cs.py start & sleep 2 CLOUDSYNC_STATUS="$(python3 ./cs.py status)" - if $CLOUDSYNC_STATUS == $POSTMSG_CLOUDSYNC_RUNNING; then - echo $POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED >> $POSTLOG + if [ "$CLOUDSYNC_STATUS" == "$POSTMSG_CLOUDSYNC_RUNNING" ]; then + post_log_pass "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED" else - echo $POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" fi + post_log "$CLOUDSYNC_STATUS" cd else - echo $POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED >> $POSTLOG + post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" fi -# ---------------------------------------- Denali +# ----------------------------------------- Denali +post_log_dash " Denali " #launching denali application -$HOME/denali -u -C & # -C to disable cloudsync for now sync it blocks the system and no cloudsync has been installed. +DENALI_VERSION="$($HOME/$DENALI_BIN -v)" +if [ -n "$DENALI_VERSION" ]; then + post_log_pass "$($HOME/$DENALI_BIN -v)" # log UI Software version + $HOME/$DENALI_BIN -u -C & # -C to disable cloudsync for now sync it blocks the system and no cloudsync has been installed. +else + post_log_fail "Unknown Applicaion Version" +fi -# ---------------------------------------- END +# ----------------------------------------- END # tag the end time in the POST log file -echo "End: $(date +"%d%m%Y%H%M%S")" >> $POSTLOG +post_log "End: $(timestamp)" +post_log_star " ***** " - -# ---------------------------------------- Ethernet +# ----------------------------------------- Ethernet # setup ethernet # note: At this time the application is running and also the ehternet connection is not necessary # so the sleep here is not hurtung any part of the applicaion progress. sleep 10 udhcpc eth0 & +exit 0 Index: scripts/setup.sh =================================================================== diff -u -r54c4136d95375116e6daf23b7d4179159cf13d0c -r025abd59dd1582ac0a7ad7af79358929042ea4bc --- scripts/setup.sh (.../setup.sh) (revision 54c4136d95375116e6daf23b7d4179159cf13d0c) +++ scripts/setup.sh (.../setup.sh) (revision 025abd59dd1582ac0a7ad7af79358929042ea4bc) @@ -1,5 +1,5 @@ #!/bin/sh -########################################################################### +############################################################################ # # Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. # @@ -12,45 +12,135 @@ # @date (last) 01-Jul-2022 # @author (original) Behrouz NematiPour # @date (original) 13-Mar-2020 -# +# @date 09-Dec-2022 ############################################################################ # @details # This script is part of setting up the newly flashed SoM which will run on the device # after the start.sh script is done copying files on the device. -echo "setup the time/date controller" -# to use the system time/date and not use the network time protocol -timedatectl set-ntp 0 +source ./globals.sh "$1" "$2" -echo "Setup the timezone (PDT Pacific)" -timedatectl set-timezone America/Los_Angeles -timedatectl set-local-rtc 1 +function check_sdcard() { + if [ ! "$($CMD_SDCARD_DEV)" == "$SDCARD_DEV" ];then # if no SD-Card found ask operator to install on and retry after power-cycle. + echo_dash_comment + echo_dash_message "No SD-Card detected" + echo_dash_message "UI Software logging will not work without a SD-Card" + echo_dash_message " - Power off the device" + echo_dash_message " - Install the SD-Card" + echo_dash_message " - Power on the device" + echo_dash_message " - run the $0" + echo_dash_comment + exit $ERR_SD_CARD + fi -echo "Setup the time/date" -while true; do - read -p "please enter the date (yyyy-MM-dd HH:mm): " -r DATE - timedatectl set-time "$DATE" - if [ $? -eq 0 ]; then - break + if [ ! "$($CMD_SDCARD_PRT)" == "$SDCARD_PRT" ]; then return $FALSE; fi # if partition 1 doesn't exist , do the format + if [ ! "$($CMD_LINUX_TYPE)" == "$SDCARD_TYP_NUMB" ]; then return $FALSE; fi # if partition 1 type is not Linux(83) , do the format + return $TRUE # otherwise , do not format +} + +function format_sdcard() { + check_sdcard + if [ $? -eq $TRUE ]; then # if sd-card is OK + echo "Found the SD-Card $SDCARD_DEV" + confirm "Do you want to format the SD-Card" + if [ $? -eq $FALSE ]; then # give user an option to skip the format + return $? + fi fi -done + + echo "Unmount the SD-Card if is in use" + umount "$SDCARD_PRT" + echo "Removing current partitions" + sfdisk --delete $SDCARD_DEV 1>/dev/null 2>/dev/null + echo "Create new partition" + echo "label:MBR" | sfdisk $SDCARD_DEV 1>/dev/null 2>/dev/null + echo "type=83" | sfdisk $SDCARD_DEV 1>/dev/null 2>/dev/null + echo "Create a ext4 file system" + mkfs.ext4 $SDCARD_PRT -L "Denali_Log" -F # 1>/dev/null 2>/dev/null -echo "Disabling Qt demo" -systemctl disable qtlauncher -systemctl disable ebikedata + check_sdcard + if [ $? -eq $TRUE ]; then + echo "SD-Card format PASSED" + else + echo "SD-Card format FAILED !!!" + fi +} -echo "Setting denali as default auto start application" -mkdir /etc/init.d/ -mv autostart /etc/init.d/ -update-rc.d autostart defaults +function set_timezone() { + echo "setup the time/date controller" + # to use the system time/date and not use the network time protocol + timedatectl set-ntp $TDCTL_NTP_USED + + echo "Setup the timezone (PDT Pacific)" + timedatectl set-timezone $TDCTL_TIMEZONE + timedatectl set-local-rtc $TDCTL_RTC_LOCL +} -chmod a+x $HOME/denali +function set_datetime() { + echo "Setup the time/date" + while true; do + timedatectl set-time "$DATETIME" 1>/dev/null 2>/dev/null + if [ $? -eq 0 ]; then + break + else + read -p "please enter the date (yyyy-MM-dd HH:mm): " -e -i "$DATETIME" -r DATETIME + fi + done +} -echo "Syncing file system updates" -sync +function diable_b2qt_services() { + echo "Disabling boot2Qt setvices" + systemctl disable b2qt + systemctl disable connman + systemctl disable qtlauncher + systemctl disable ebikedata +} -read -p "ready to reboot? [y,n]" -n 1 -r CONFIRM -if [ "$CONFIRM" == "y" ]; then - reboot -fi +function setup_denali() { + echo "Setting denali as default auto start application" + + chmod a+x $HOME/$INITD_AUTOSTART + chmod a+x $HOME/$LAUNCH_SCR + chmod a+x $HOME/$DENALI_BIN + + rm -f "$POSTLOG" "$POSTERR" "$POSTOUT" + + echo "Syncing file system updates" + sync;sync;sync +} + +function disable_autostart() { + # in case the device is alread setup, disable the autostart of the application until the setup script enables it. + rm -f $INITD_LOCATION$INITD_AUTOSTART +} + +function enable_autostart() { + mkdir -p $INITD_LOCATION + mv $INITD_AUTOSTART $INITD_LOCATION + update-rc.d $INITD_AUTOSTART defaults +} + +function confirm_reboot() { + read -p "ready to reboot? [y,n]" -n 1 -r CONFIRM + if [ "$CONFIRM" == "y" ]; then + rm $0 + reboot + fi + echo "" +} + +function main() { + disable_autostart + format_sdcard + set_timezone + set_datetime "$1" "$2" + diable_b2qt_services + setup_denali + enable_autostart +} + +main "$1" "$2" +confirm_reboot + +exit 0 Index: scripts/start.sh =================================================================== diff -u -r54c4136d95375116e6daf23b7d4179159cf13d0c -r025abd59dd1582ac0a7ad7af79358929042ea4bc --- scripts/start.sh (.../start.sh) (revision 54c4136d95375116e6daf23b7d4179159cf13d0c) +++ scripts/start.sh (.../start.sh) (revision 025abd59dd1582ac0a7ad7af79358929042ea4bc) @@ -18,234 +18,233 @@ # @details # This file is used to setup newly flashed SoM to copy everythin on the device. -FLG_QUIET=0 -SSH_QUIET="" -EMT_IP="192.168." +source ./globals.sh -ERR_CONNECTION=1 -ERR_DENALI_BIN=2 -ERR_FONTS_EMTY=3 -ERR_FONTS_PATH=4 -ERR_KILLPROMPT=5 - -SRC_PATH_SCRIPTS="scripts" -SRC_PATH_CONFIG="settings" -SRC_PATH_FONTS="fonts" - -DST_IP=$EMT_IP -DST_USER=root -DST_PATH_CONFIG="/home/$DST_USER/.config" -DST_PATH_HOME="/home/$DST_USER" -DST_PATH_SCRIPTS="/home/$DST_USER/scripts" -DST_PATH_FONTS="/usr/share/fonts/truetype" - -SRC_PATH_DENALI="." -DENALI_BIN=denali - - -if [ "$1" = "-h" -o "$1" = "--help" ]; then - echo -e "-h \t This help" - echo -e "-q \t Quiet mode" - echo "usage start.sh [] [-q]" - exit 0 -fi - -if [ "$1" = "-q" -o "$2" = "-q" ]; then - FLG_QUIET=1 - SSH_QUIET="-oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -oLogLevel=ERROR -oConnectTimeout=5 -oHostKeyAlgorithms=+ssh-rsa" - echo -e "Running in quiet mode." -fi - -if [ -n "$1" -a "$1" != "-q" ]; then - DST_IP="$1" -fi - -function runssh() { - ssh $SSH_QUIET $DST_USER@$DST_IP "$1" +function displayHelp() { + if [ "$1" = "-h" -o "$1" = "--help" ]; then + echo -e "-h \t This help" + echo "usage start.sh [ [xxx] or [xxx.xxx.xxx.xxx] or [] ]" + exit 0 + fi } -function folderExists() { - if [ ! -d "$1" ]; then - echo 1 - return +function exitConfirm() { + read -p "Continue? [y,n]" -n 1 -r CONTINUE + if [ "$CONTINUE" != "y" ]; then + echo "" + exit "$1" + else + echo "" fi - echo 0 } -function fileExists() { - if [ ! -f "$1" ]; then - echo 1 - return +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 - echo 0 } -function copyFolderTo() { - echo $1 - scp -r $SSH_QUIET $1/. $DST_USER@$DST_IP:$2 +function setupLogs() { + local log_location=$LOG_LOCATION/$DST_IP + mkdir -p $log_location + LOG_OUT_FILE="$log_location/update-$(timestamp).log" + LOG_ERR_FILE="$log_location/update-$(timestamp).err" + touch $LOG_OUT_FILE + touch $LOG_ERR_FILE +} - if [ ! $? -eq 0 ];then - echo "copy of folder $1 unsuccessful" - return 1 - fi - return 0 +function sshKeyExists() { + existsFile $SRC_FILE_SSHKEY_PUB + return $? } -function copyFileTo() { - if [ $(fileExists "$1") -eq 0 ]; then - scp $SSH_QUIET $1 $DST_USER@$DST_IP:$2 - if [ ! $? -eq 0 ];then - echo "copy of file $1 unsuccessful" - return 1 - fi +function sshKeyGen() { + sshKeyExists + if [ ! $? -eq 0 ]; then + echo "No ssh key found,Generating ssh key" + ssh-keygen -N "" -f $SRC_FILE_SSHKEY 1>>$LOG_OUT_FILE 2>>$LOG_ERR_FILE + return $? else - echo " ~~~ File $1 doesn't exist" + echo "Found ssh key " $SRC_FILE_SSHKEY_PUB fi return 0 } -function exitconfirm() { - read -p "Continue? [y,n]" -n 1 -r CONTINUE - if [ "$CONTINUE" != "y" ]; then - echo "" - exit "$1" - else - echo "" +function sshKeyCopy() { + echo "Registering the ssh key on the device $DST_IP" + echo "Please wait ..." + 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 + exitConfirm $? + return $? fi } -function killPrompt() { - if [ ! $FLG_QUIET -eq 1 ]; then - echo "All the settings, configurations and binaries will be overwritten" - exitconfirm $ERR_KILLPROMPT - fi +function sshRun() { + ssh $SSH_PARAM $DST_USER@$DST_IP $1 + return $? } -function removeIPFromHost() { - ssh-keygen -f "/home/denali/.ssh/known_hosts" -R "$DST_IP" - sleep 5 -} - -# getting the ip address of the device -function getIpAddress() { - while true; do - if [ "$DST_IP" = "$EMT_IP" ]; then - read -p "Please enter the device Ip address: " -e -i "$DST_IP" -r DST_IP - else - if [ ! $FLG_QUIET -eq 1 ]; then - read -p "Please enter the device Ip address: " -e -i "$DST_IP" -r DST_IP +function copyFolderTo() { + existsFolder "$1" + if [ $? -eq 0 ]; then + echo -n "Copy folder" >> $LOG_OUT_FILE + scp -r $SSH_PARAM $1/* $DST_USER@$DST_IP:$2 + if [ $? -eq 0 ]; then + echo " Successfull - $1" >> $LOG_OUT_FILE + else + echo " Failed" >> $LOG_OUT_FILE + exitConfirm $? + return $? fi + else + echo "File '$1' doesn't exist" | tee -a $LOG_OUT_FILE + exitConfirm $? fi - if [ ! -z "$DST_IP" ]; then - echo "removing device Ip Address from known hosts" - removeIPFromHost - echo "Testing connection on IP $DST_IP" + return 0 +} - runssh "exit 0" +function copyFileTo() { + existsFile "$1" + if [ $? -eq 0 ]; then + echo -n "Copy file" >> $LOG_OUT_FILE + scp $SSH_PARAM $1 $DST_USER@$DST_IP:$2 if [ $? -eq 0 ]; then - break + echo " Successfull - $1" >> $LOG_OUT_FILE else - echo " ~~~ Cannot connect to the device." - echo " ~~~ Either device not connected or the IP address is not correct." - exitconfirm $ERR_CONNECTION + echo " Failed" >> $LOG_OUT_FILE + exitConfirm $? + return $? fi + else + echo "File '$1' doesn't exist" | tee -a $LOG_OUT_FILE + exitConfirm $? fi - done - echo "Connection successful on device with IP $DST_IP" - echo "" + return 0 } -# getting the denali application path -function getDenaliPath() { - while true; do - if [ ! $FLG_QUIET -eq 1 ]; then - read -p "Please enter the Denali application path: " -e -i $SRC_PATH_DENALI -r SRC_PATH_DENALI - fi - echo "Testing the Denali application path" - if [ $(fileExists "$SRC_PATH_DENALI/$DENALI_BIN") -eq 0 ]; then - break - else - echo " ~~~ Cannot find the Denali application." - echo " ~~~ Either the path is not correct or the Denali application doesn't exist." - exitconfirm $ERR_DENALI_BIN - fi - done - echo "The Denali application found successfully in path '$SRC_PATH_DENALI'" - echo "" +function killPrompt() { + echo_star_comment + echo_star_message "Current running UI Software on the device will be stopped." + echo_star_message "All the settings, configurations and binaries will be overwritten" + echo_star_comment + exitConfirm $ERR_KILLPROMPT } -# getting the fonts path -function getFontsPath() { +function getDeviceIP() { while true; do - if [ ! $FLG_QUIET -eq 1 ]; then - read -p "Please enter the fonts path: " -e -i $SRC_PATH_FONTS -r SRC_PATH_FONTS - fi - echo "Testing fonts path" - if [ "$(folderExists "$SRC_PATH_FONTS")" -eq 0 ]; then - if [ "$(ls)" != "" ]; then + validIP "$DST_IP" + if [ $? -eq 0 ]; then + break + else + read -p "Please enter the device Ip address: " -e -i "$IP_EMT" -r DST_IP + validIP "$DST_IP" + if [ $? -eq 0 ]; then break else - echo " ~~~ The folder $SRC_PATH_FONTS is empty" - exitconfirm $ERR_FONTS_EMTY + echo "The entered IP address is not valid [$DST_IP]" + exitConfirm $? fi - else - echo " ~~~ Cannot find Fonts path." - exitconfirm $ERR_FONTS_PATH fi done - echo "Fonts found successfully in path '$SRC_PATH_FONTS'" - echo "" } -# SSH Connection -function connect() { - echo "******************************************************" - echo "please ssh into device $DST_IP and run ./setup.sh" - echo "******************************************************" - read -p "Hit enter to continue" - runssh # the setup.sh has to run on the device while user has logged into the device. +function setupBootupScripts() { + echo_dash_comment + echo_dash_message "Installing bootup scripts" | tee -a $LOG_OUT_FILE + echo_dash_comment + copyFileTo "globals.sh" $DST_PATH_HOME + copyFileTo "autostart" $DST_PATH_HOME + copyFileTo "run.sh" $DST_PATH_HOME + copyFileTo "setup.sh" $DST_PATH_HOME } -# copy the settings scripts function setupSettingsScripts() { - runssh "mkdir -p $DST_PATH_SCRIPTS ;" - runssh "rm -frd $DST_PATH_SCRIPTS/*;" + echo_dash_comment + echo_dash_message "Installing settings scripts" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "rm -frd $DST_PATH_SCRIPTS;" + sshRun "mkdir -p $DST_PATH_SCRIPTS;" copyFolderTo $SRC_PATH_SCRIPTS $DST_PATH_SCRIPTS - runssh "cd $1; chmod a+x *.sh;" + sshRun "cd $1; chmod a+x *.sh;" } -# copy the instructions -function setupInstructions() { - runssh "mkdir -p $DST_PATH_CONFIG ;" - runssh "rm -frd $DST_PATH_CONFIG/*;" +function setupConfigurations() { + echo_dash_comment + echo_dash_message "Installing configurations" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "rm -frd $DST_PATH_CONFIG;" + sshRun "mkdir -p $DST_PATH_CONFIG;" copyFolderTo $SRC_PATH_CONFIG $DST_PATH_CONFIG } -# copy the fonts +function setupCloudSync() { + echo_dash_comment + echo_dash_message "Installing CloudSync" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "killall python3" + sshRun "rm -frd $DST_PATH_CLOUDSYNC;" + sshRun "mkdir -p $DST_PATH_CLOUDSYNC;" + copyFolderTo $SRC_PATH_CLOUDSYNC $DST_PATH_CLOUDSYNC +} + function setupFonts() { - getFontsPath + echo_dash_comment + echo_dash_message "Installing fonts" | tee -a $LOG_OUT_FILE + echo_dash_comment copyFolderTo $SRC_PATH_FONTS $DST_PATH_FONTS } -function main() { - getIpAddress +function setupApplication() { + echo_dash_comment + echo_dash_message "Installing UI Software" | tee -a $LOG_OUT_FILE + echo_dash_comment + sshRun "killall $DENALI_BIN" + copyFileTo $DENALI_BIN $DST_PATH_HOME +} - killPrompt +function connect() { + echo_dash_comment + echo_dash_message "please ssh into device $DST_IP and run ./setup.sh " + echo_dash_comment + read -p "Hit enter to continue" + sshRun # the setup.sh has to run on the device while user has logged into the device. +} - copyFileTo "autostart" $DST_PATH_HOME - copyFileTo "run.sh" $DST_PATH_HOME - copyFileTo "setup.sh" $DST_PATH_HOME +function wipe_device() { + sshRun "rm -frd *" + sshRun "rm -frd .*" +} +function main() { + displayHelp "$1" + + defaultIP "$1" + getDeviceIP + setupLogs + + sshKeyGen + sshKeyCopy + + killPrompt + wipe_device + + setupBootupScripts setupSettingsScripts - setupInstructions + setupConfigurations + setupCloudSync setupFonts - getDenaliPath - runssh "killall $DENALI_BIN" - copyFileTo "$SRC_PATH_DENALI/$DENALI_BIN" $DST_PATH_HOME + setupApplication } # running the main function -main +main "$1" connect +exit 0