#!/bin/bash ########################################################################### # # Copyright (c) 2019-2020 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 copy.sh # # @author (last) Behrouz NematiPour # @date (last) 13-Mar-2020 # @author (original) Behrouz NematiPour # @date (original) 13-Mar-2020 # ############################################################################ # device default Ip Address and denali application path if [ "$1" == "" ]; then IPADDR="192.168.10.135" else IPADDR="$1" fi SSHUSER=root HOMEPATH="/home/$SSHUSER/" FONTPATH="/usr/share/fonts/truetype/" FONTSPATH="/home/denali/Project/application/resources/fonts/" DENALIPATH="/home/denali/Project/tmp/build/denali-Qt_5_12_5_iMX8-Release/" DENALINAME=denali function folderExists() { if [ ! -d "$1" ]; then echo 1 return fi echo 0 } function fileExists() { if [ ! -f "$1" ]; then echo 1 return fi echo 0 } function copyFolderTo() { echo $1 scp $1/* $SSHUSER@$IPADDR:$2 if [ ! $? -eq 0 ];then echo "copy of file $1 unsuccessful" return 1 fi return 0 } function copyFileTo() { if [ $(fileExists "$1") -eq 0 ]; then scp $1 $SSHUSER@$IPADDR:$2 if [ ! $? -eq 0 ];then echo "copy of file $1 unsuccessful" return 1 fi else echo "File $1 doesn't exist" fi return 0 } function exitconfirm() { read -p "Continue? [y,n]" -n 1 -r CONTINUE if [ "$CONTINUE" != "y" ]; then echo "" exit "$1" else echo "" fi } function removeIPFromHost() { ssh-keygen -f "/home/denali/.ssh/known_hosts" -R "$IPADDR" sleep 5 } # getting the ip address of the device function getIpAddress() { while true; do read -p "Please enter the device Ip address: " -e -i $IPADDR -r IPADDR echo "removing device Ip Address from known hosts" removeIPFromHost echo "Testing connection on IP $IPADDR" if [ ! -z $IPADDR ]; then ping $IPADDR -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 fi done echo "Connection successful on device with IP $IPADDR" echo "" } # getting the denali application path function getDenaliPath() { while true; do read -p "Please enter the Denali application path: " -e -i $DENALIPATH -r DENALIPATH echo "Testing Denali application path" if [ $(fileExists "$DENALIPATH/$DENALINAME") -eq 0 ]; then break else echo "Cannot find Denali application." echo "Either the path is not correct or the Denali application doesn't exist." exitconfirm 2 fi done echo "Denali application found successfully in path '$DENALIPATH'" echo "" } # getting the fonts path function getFontsPath() { while true; do read -p "Please enter the Fonts path: " -e -i $FONTSPATH -r FONTSPATH echo "Testing Fonts path" if [ "$(folderExists "$FONTSPATH")" -eq 0 ]; then if [ "$(ls)" != "" ]; then break else echo "The folder $FONTSPATH is empty" exitconfirm 3 fi else echo "Cannot find Fonts path." exitconfirm 4 fi done echo "Fonts found successfully in path '$FONTSPATH'" echo "" } # SSH Connection function connect() { echo "please ssh into device $IPADDR 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 $SSHUSER@$IPADDR else echo "" fi } function main() { getIpAddress copyFileTo "autostart" $HOMEPATH copyFileTo "run.sh" $HOMEPATH copyFileTo "setup.sh" $HOMEPATH getDenaliPath copyFileTo $DENALIPATH/$DENALINAME $HOMEPATH getFontsPath copyFolderTo $FONTSPATH $FONTPATH } # running the main function main connect