Index: scripts/create_update_folder.sh =================================================================== diff -u -r3e49c0cb545fafdaaff760dd51dce8bc3263ab46 -r16805304205c7f4de46cc7fbbba68d3b7a32b3a9 --- scripts/create_update_folder.sh (.../create_update_folder.sh) (revision 3e49c0cb545fafdaaff760dd51dce8bc3263ab46) +++ scripts/create_update_folder.sh (.../create_update_folder.sh) (revision 16805304205c7f4de46cc7fbbba68d3b7a32b3a9) @@ -20,7 +20,6 @@ # Run example # └$ /home/denali/Projects/application/scripts/create_update_usb.sh Projects/application/ /media/denali/usb-disk1/ - FOLDER_BIN=/home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Release FOLDER_SRC=/home/denali/Projects/application FOLDER_DST=/home/denali/Desktop/update-folder Index: scripts/start.sh =================================================================== diff -u -r3e49c0cb545fafdaaff760dd51dce8bc3263ab46 -r16805304205c7f4de46cc7fbbba68d3b7a32b3a9 --- scripts/start.sh (.../start.sh) (revision 3e49c0cb545fafdaaff760dd51dce8bc3263ab46) +++ scripts/start.sh (.../start.sh) (revision 16805304205c7f4de46cc7fbbba68d3b7a32b3a9) @@ -18,12 +18,21 @@ # @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." +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="192.168.10.135" +DST_IP=$EMT_IP DST_USER=root DST_PATH_CONFIG="/home/$DST_USER/.config" DST_PATH_HOME="/home/$DST_USER" @@ -33,11 +42,28 @@ SRC_PATH_DENALI="." DENALI_BIN=denali -# device default Ip Address and denali application path -if [ -n "$1" ]; then -DST_IP="$1" + +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="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR" + 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 folderExists() { if [ ! -d "$1" ]; then echo 1 @@ -56,7 +82,8 @@ function copyFolderTo() { echo $1 - scp -r $1/* $DST_USER@$DST_IP:$2 + scp -r $SSH_QUIET $1/* $DST_USER@$DST_IP:$2 + if [ ! $? -eq 0 ];then echo "copy of folder $1 unsuccessful" return 1 @@ -66,7 +93,7 @@ function copyFileTo() { if [ $(fileExists "$1") -eq 0 ]; then - scp $1 $DST_USER@$DST_IP:$2 + scp $SSH_QUIET $1 $DST_USER@$DST_IP:$2 if [ ! $? -eq 0 ];then echo "copy of file $1 unsuccessful" return 1 @@ -87,6 +114,13 @@ fi } +function killPrompt() { + if [ ! $FLG_QUIET -eq 1 ]; then + echo "All the settings, configurations and binaries will be overwritten" + exitconfirm $ERR_KILLPROMPT + fi +} + function removeIPFromHost() { ssh-keygen -f "/home/denali/.ssh/known_hosts" -R "$DST_IP" sleep 5 @@ -95,20 +129,27 @@ # getting the ip address of the device function getIpAddress() { while true; do - read -p "Please enter the device Ip address: " -e -i $DST_IP -r DST_IP + 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 + fi + fi + if [ ! -z "$DST_IP" ]; then echo "removing device Ip Address from known hosts" removeIPFromHost echo "Testing connection on IP $DST_IP" - if [ ! -z "$DST_IP" ]; then - ping "$DST_IP" -c1 -W1 - if [ $? -eq 0 ]; then - break - else - echo " ~~~ Cannot connect to the device." - echo " ~~~ Either device not connected or the IP address is not correct." - exitconfirm 1 - fi + + ping "$DST_IP" -c1 -W1 + if [ $? -eq 0 ]; then + break + else + echo " ~~~ Cannot connect to the device." + echo " ~~~ Either device not connected or the IP address is not correct." + exitconfirm $ERR_CONNECTION fi + fi done echo "Connection successful on device with IP $DST_IP" echo "" @@ -117,14 +158,16 @@ # getting the denali application path function getDenaliPath() { while true; do - read -p "Please enter the Denali application path: " -e -i $SRC_PATH_DENALI -r SRC_PATH_DENALI + 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 2 + exitconfirm $ERR_DENALI_BIN fi done echo "The Denali application found successfully in path '$SRC_PATH_DENALI'" @@ -134,18 +177,20 @@ # getting the fonts path function getFontsPath() { while true; do - read -p "Please enter the fonts path: " -e -i $SRC_PATH_FONTS -r SRC_PATH_FONTS + 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 break else echo " ~~~ The folder $SRC_PATH_FONTS is empty" - exitconfirm 3 + exitconfirm $ERR_FONTS_EMTY fi else echo " ~~~ Cannot find Fonts path." - exitconfirm 4 + exitconfirm $ERR_FONTS_PATH fi done echo "Fonts found successfully in path '$SRC_PATH_FONTS'" @@ -154,27 +199,24 @@ # SSH Connection function connect() { + echo "******************************************************" echo "please ssh into device $DST_IP and run ./setup.sh" - read -p "Do you want to ssh into device? [y,n]" -n 1 -r CONFIRM - if [ "$CONFIRM" == "y" ]; then - echo "" - ssh $DST_USER@$DST_IP - else - echo "" - fi + echo "******************************************************" + read -p "Hit enter to continue" + runssh # the setup.sh has to run on the device while user has logged into the device. } # copy the settings scripts function setupSettingsScripts() { - ssh $DST_USER@$DST_IP "mkdir -p $DST_PATH_SCRIPTS;" + runssh "mkdir -p $DST_PATH_SCRIPTS;" copyFolderTo $SRC_PATH_SCRIPTS $DST_PATH_SCRIPTS - ssh $DST_USER@$DST_IP "cd $1; chmod a+x *.sh;" + runssh "cd $1; chmod a+x *.sh;" } # copy the instructions function setupInstructions() { - ssh $DST_USER@$DST_IP "mkdir -p $DST_PATH_CONFIG;" - ssh $DST_USER@$DST_IP "rm -frd $DST_PATH_CONFIG/*;" + runssh "mkdir -p $DST_PATH_CONFIG;" + runssh "rm -frd $DST_PATH_CONFIG/*;" copyFolderTo $SRC_PATH_CONFIG $DST_PATH_CONFIG } @@ -187,6 +229,8 @@ function main() { getIpAddress + killPrompt + copyFileTo "autostart" $DST_PATH_HOME copyFileTo "run.sh" $DST_PATH_HOME copyFileTo "setup.sh" $DST_PATH_HOME @@ -196,8 +240,8 @@ setupFonts getDenaliPath + runssh "killall $DENALI_BIN" copyFileTo "$SRC_PATH_DENALI/$DENALI_BIN" $DST_PATH_HOME - } # running the main function