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