#!/bin/sh ########################################################################### # # Copyright (c) 2020-2023 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 setup.sh # # @author (last) Behrouz NematiPour # @date (last) 16-Dec-2022 # @author (original) Behrouz NematiPour # @date (original) 13-Mar-2020 # ############################################################################ # @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. source ./globals.sh "$1" "$2" function check_sdcard() { while true; do 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 "Insert a SD-Card and continue when ready" echo_dash_comment confirm "Continue" if [ $? -eq $FALSE ]; then exit $ERR_SD_CARD fi else break fi done 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 while true; do echo "Unmount the SD-Card if is in use" umount "$SDCARD_PRT" if [ ! "$( mount | grep $SDCARD_PRT)" == "" ]; then # is still mounted if [ $? -eq $FALSE ]; then # if SD-Card cannot the unmounted then stop the format. echo "The SD-Card $SDCARD_DEV cannot be unmounted, therefore cannot be formatted" confirm "Do you want to retry?" if [ $? -eq $FALSE ]; then return $FALSE # do not continue with format fi else break fi else break fi done 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 check_sdcard if [ $? -eq $TRUE ]; then echo "SD-Card format PASSED" else echo "SD-Card format FAILED !!!" fi } 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 } 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 } function disable_service() { echo "Disabling '$1' service" systemctl stop "$1" systemctl disable "$1" if [ -z $(systemctl status | cat | grep "$1" | grep -v grep) ]; then echo "'$1' service disabled" else echo "'$1' service not disabled!" fi } function disable_unwanted_services() { disable_service b2qt.service disable_service connman.service disable_service qtlauncher.service disable_service ebikedata.service disable_service rpcbind.service disable_service rpcbind.socket disable_service rpcbind.target } 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 enableDRT() { # trying to temporarily add the DRT server input open for the device registration iptables -A INPUT -p tcp -s $CloudSync_DRT_SERVER_IP --dport $CloudSync_DRT_SERVER_PORT -j ACCEPT # enables the ping from the DRT server to the device [ useful for testing ] iptables -A INPUT -p icmp --icmp-type echo-request -s $CloudSync_DRT_SERVER_IP -j ACCEPT } function executionMode() { if [ "$(grep $SETUP_ENABLE_MANUFACTURING_MODE $SETUP_CONF_FILE)" = "" ]; then # -U for Updating mode # -a for disabling the non-minimizable Alarms APPLICATION_PARAMS="-U -a" else # -E for Maunufacturing mode # -a for disabling the non-minimizable Alarms APPLICATION_PARAMS="-E -a" fi enableDRT applicationPOST "setup" testApplicationShasum_setup startCloudSync_setup startApplication_setup } function main() { disable_autostart format_sdcard set_timezone # set_datetime "$1" "$2" disable_unwanted_services setup_denali enable_autostart executionMode } main "$1" "$2" exit 0