diff --git a/README.md b/README.md index db49c96..25b17ee 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,11 @@ The script will also ask you whether you want to keep the temporary files after In case you change your mind you can always delete the entire directory (by default `~/jetson_configure_tmp`). The size of this directory is about 75 GB. -After the script completes, you can continue configuration on the Jetson device by cloning this repository and running one of the `setup_utility.sh` scripts. +After the script completes, you can continue configuration on the Jetson device by cloning this repository and running the `setup_utility.sh` script. ## Configuration utility -- Run the script with "setup_utility.sh" in the root directory of the repository. -- The menu items will be automatically generated from the "subscripts" - folder -- Scripts and folders will appear in the menu as items or - folders. - - You can easily add new functionality by putting new scripts into the - subscripts folder. See examples of menus in the "examples_whiptail" - folder. +- Run the script with `setup_utility.sh` in the root directory of the repository. +- The menu items will be automatically generated from the "subscripts" folder +- Scripts and folders will appear in the menu as items or folders. +- You can easily add new functionality by putting new scripts into the subscripts folder. See examples of menus in the `examples_whiptail` folder. diff --git a/jetson_flash.sh b/jetson_flash.sh index 1b4a67c..488f7e1 100755 --- a/jetson_flash.sh +++ b/jetson_flash.sh @@ -8,7 +8,7 @@ # - prepare the filesystem with a headless user and autologin enabled # - flash the device with the prepared filesystem and binaries # -# After this script completes you can continue configuration on the device itself with the setup_utility_F4F.sh or setup_utility_MRS.sh scripts +# After this script completes you can continue configuration on the device itself with the setup_utility.sh script # set -euo pipefail diff --git a/setup_utility_MRS.sh b/setup_utility.sh similarity index 70% rename from setup_utility_MRS.sh rename to setup_utility.sh index 08cc7ba..1cbaf73 100755 --- a/setup_utility_MRS.sh +++ b/setup_utility.sh @@ -6,9 +6,8 @@ blink=$(tput blink) red='\033[0;31m' green='\033[0;32m' -light=$(echo $PROFILES | grep COLORSCHEME_LIGHT) -if [ -z "$light" ] -then +light=$(echo "$PROFILES" | grep COLORSCHEME_LIGHT) +if [ -z "$light" ]; then export NEWT_COLORS=' root=brightgreen,black border=brightgreen,black @@ -44,7 +43,6 @@ else ' fi - # export NEWT_COLORS=' # root=brightgreen,black # border=brightgreen,black @@ -86,13 +84,10 @@ fi # roottext=lightgrey,black # Specify the folder path where your files are located - - DIR="$(dirname "$(readlink -f "$0")")" folder_path="" first_run=true -if [ -z "$1" ] -then +if [ -z "$1" ]; then folder_path="$DIR/subscripts" sudo chmod -R +x "$DIR/subscripts" sudo chmod -R -x "$DIR/subscripts/5Udev_rules/DISREGARD_udev_rules" @@ -106,14 +101,25 @@ fi OPTIONS=() FULL_FILEPATHS=() -show_menu() { +show_main_menu() { whiptail --title "MRS UAV System Install Utility" --menu "Choose an option:" 0 0 0 "${OPTIONS[@]}" 3>&1 1>&2 2>&3 } +show_f4f_mrs_switch_menu() { + + F4F_MRS_SWITCH_OPTIONS=( + 1 "Use F4F defaults" + 2 "Use MRS defaults" + ) + + whiptail --title "MRS UAV System Install Utility" --menu "Do you want to use F4F or MRS defaults?" 0 0 0 "${F4F_MRS_SWITCH_OPTIONS[@]}" 3>&1 1>&2 2>&3 +} + main() { + while true; do clear - choice=$(show_menu) + choice=$(show_main_menu) if [ $? -eq 0 ]; then echo ${FULL_FILEPATHS[$((choice - 1))]} @@ -140,8 +146,7 @@ index="1" for file in "$folder_path"/*; do # Add each filename to the array disregard=$(echo $file | grep "DISREGARD") - if [ ! -z "$disregard" ] - then + if [ ! -z "$disregard" ]; then continue fi @@ -150,7 +155,7 @@ for file in "$folder_path"/*; do filename="${file##*"/"}" filename="${filename%.*}" filename="${filename//_/ }" - filename="${filename#[[:digit:]]}" #removes the first digit from script name + filename="${filename#[[:digit:]]}" # removes the first digit from script name if [[ -d ${file} ]]; then OPTIONS+=("$filename ...") @@ -161,17 +166,31 @@ for file in "$folder_path"/*; do FULL_FILEPATHS+=("$file") done -if [ "$first_run" = true ] ; then - #Check connection to the internet +if [ "$first_run" = true ]; then + # Check connection to the internet wget -q --spider http://google.com if [ $? -eq 0 ]; then echo -e "${green}Online${normal}" - sudo apt install git - sudo apt update + + # Check if apt update was already successfully ran in the last 60 minutes and if so, do not run it again + if [ -f /var/lib/apt/periodic/update-success-stamp ]; then + last_update=$(stat -c %Y /var/lib/apt/periodic/update-success-stamp) + now=$(date +%s) + if [ $((now - last_update)) -lt 3600 ]; then + echo "Apt update was already successfully ran in the last 60 minutes, not running it again" + else + sudo apt update + fi + fi + if ! command -v git &>/dev/null; then + echo "Git is not installed. Installing git..." + sudo apt install git + fi + if ! git diff --quiet || ! git diff --cached --quiet; then - echo "Error: Local changes detected. Commit or stash your changes before pulling." - exit 1 + echo "Error: Local changes detected. Commit or stash your changes before pulling." + exit 1 fi git pull else @@ -181,14 +200,29 @@ if [ "$first_run" = true ] ; then read -p "${blink}${bold}Hit enter to continue ...${normal}" fi - #Check for whiptail + # Check for whiptail whiptail_installed=$(apt-cache policy whiptail | grep Installed | grep none) - if [ ! -z "$whiptail_installed" ] - then + if [ ! -z "$whiptail_installed" ]; then echo "Whiptail NOT installed, will install now:" sudo apt install whiptail fi + # Ask whether the user wants to use F4F or MRS defaults + f4f_mrs_choice=$(show_f4f_mrs_switch_menu) + case $f4f_mrs_choice in + 1) + echo "Using F4F defaults" + export USE_DEFAULTS_FOR="F4F" + ;; + 2) + echo "Using MRS defaults" + export USE_DEFAULTS_FOR="MRS" + ;; + *) # the default case, also called when cancel is selected + exit 1 + ;; + esac fi + main diff --git a/setup_utility_F4F.sh b/setup_utility_F4F.sh deleted file mode 100755 index 45d7005..0000000 --- a/setup_utility_F4F.sh +++ /dev/null @@ -1,194 +0,0 @@ -#!/bin/bash - -bold=$(tput bold) -normal=$(tput sgr0) -blink=$(tput blink) -red='\033[0;31m' -green='\033[0;32m' - -light=$(echo $PROFILES | grep COLORSCHEME_LIGHT) -if [ -z "$light" ] -then - export NEWT_COLORS=' - root=brightgreen,black - border=brightgreen,black - title=brightgreen,black - roottext=white,black - window=brightgreen,black - textbox=white,black - button=black,brightgreen - compactbutton=white,black - listbox=white,black - actlistbox=black,white - actsellistbox=black,brightgreen - checkbox=brightgreen,black - actcheckbox=black,brightgreen - entry=black,brightgreen - ' -else - export NEWT_COLORS=' - root=green,white - border=green,white - title=green,white - roottext=black,white - window=green,white - textbox=black,white - button=white,green - compactbutton=black,white - listbox=black,white - actlistbox=black,white - actsellistbox=white,green - checkbox=green,white - actcheckbox=white,green - entry=white,green - ' -fi - - -# export NEWT_COLORS=' -# root=brightgreen,black -# border=brightgreen,black -# title=brightgreen,black -# roottext=white,black -# window=brightgreen,black -# textbox=white,black -# button=black,brightgreen -# compactbutton=white,black -# listbox=white,black -# actlistbox=black,white -# actsellistbox=black,brightgreen -# checkbox=brightgreen,black -# actcheckbox=black,brightgreen -# entry=black,brightgreen -# ' -# root=white,black -# border=black,lightgray -# window=lightgray,lightgray -# shadow=black,gray -# title=black,lightgray -# button=black,cyan -# actbutton=white,cyan -# compactbutton=black,lightgray -# checkbox=black,lightgray -# actcheckbox=lightgray,cyan -# entry=black,lightgray -# disentry=gray,lightgray -# label=black,lightgray -# listbox=black,lightgray -# actlistbox=black,cyan -# sellistbox=lightgray,black -# actsellistbox=lightgray,black -# textbox=black,lightgray -# acttextbox=black,cyan -# emptyscale=,gray -# fullscale=,cyan -# helpline=white,black -# roottext=lightgrey,black - -# Specify the folder path where your files are located - - -DIR="$(dirname "$(readlink -f "$0")")" -folder_path="" -first_run=true -if [ -z "$1" ] -then - folder_path="$DIR/subscripts" - sudo chmod -R +x "$DIR/subscripts" - sudo chmod -R -x "$DIR/subscripts/5Udev_rules/DISREGARD_udev_rules" - sudo chmod +x "$DIR/subscripts/5Udev_rules/DISREGARD_udev_rules" -else - folder_path="$1" - first_run=false -fi - -# Create an array to store filenames -OPTIONS=() -FULL_FILEPATHS=() - -show_menu() { - whiptail --title "MRS UAV System Install Utility" --menu "Choose an option:" 0 0 0 "${OPTIONS[@]}" 3>&1 1>&2 2>&3 -} - -main() { - while true; do - clear - choice=$(show_menu) - - if [ $? -eq 0 ]; then - echo ${FULL_FILEPATHS[$((choice - 1))]} - # ${FULL_FILEPATHS[$((choice - 1))]} - - if [[ -d ${FULL_FILEPATHS[$((choice - 1))]} ]]; then - echo "is a directory" - ./$0 ${FULL_FILEPATHS[$((choice - 1))]} f4f #Run this script again but in the selected folder, add the f4f parameter - else - ${FULL_FILEPATHS[$((choice - 1))]} f4f #add the f4f parameter - fi - if [ $? -eq 0 ]; then - read -p "${blink}${bold}Hit enter to continue ...${normal}" - fi - else - # echo "Menu canceled." - exit 1 - fi - done -} - -# Read filenames from the folder and populate the array -index="1" -for file in "$folder_path"/*; do - # Add each filename to the array - disregard=$(echo $file | grep "DISREGARD") - if [ ! -z "$disregard" ] - then - continue - fi - - OPTIONS+=("$index") - let "index++" - filename="${file##*"/"}" - filename="${filename%.*}" - filename="${filename//_/ }" - filename="${filename#[[:digit:]]}" #removes the first digit from script name - - if [[ -d ${file} ]]; then - OPTIONS+=("$filename ...") - else - OPTIONS+=("$filename") - fi - - FULL_FILEPATHS+=("$file") -done - -if [ "$first_run" = true ] ; then - #Check connection to the internet - wget -q --spider http://google.com - - if [ $? -eq 0 ]; then - echo -e "${green}Online${normal}" - sudo apt update - sudo apt install git - if ! git diff --quiet || ! git diff --cached --quiet; then - echo "Error: Local changes detected. Commit or stash your changes before pulling." - exit 1 - fi - git pull - else - echo -e "${red}${bold}You are not connected to the internet!${normal} (No response from google.com)" - echo -e "${red}${bold}You will not be to install/update any new software!${normal}" - echo -e "${red}${bold}You can however still use some of the configuration scripts${normal}" - read -p "${blink}${bold}Hit enter to continue ...${normal}" - fi - - #Check for whiptail - whiptail_installed=$(apt-cache policy whiptail | grep Installed | grep none) - - if [ ! -z "$whiptail_installed" ] - then - echo "Whiptail NOT installed, will install now:" - sudo apt install whiptail - fi - -fi -main diff --git a/subscripts/4Network/2Configure_networking.sh b/subscripts/4Network/2Configure_networking.sh index 2b20d4b..935f544 100755 --- a/subscripts/4Network/2Configure_networking.sh +++ b/subscripts/4Network/2Configure_networking.sh @@ -153,15 +153,15 @@ else echo " dhcp6: no" >>/tmp/01-netcfg.yaml address="" - if [[ "$1" == "f4f" ]]; then + if [[ $USE_DEFAULTS_FOR == "F4F" ]]; then address=$(input_box "Enter your static IP address for $int:" "192.168.12.101") - else + elif [[ $USE_DEFAULTS_FOR == "MRS" ]]; then address=$(input_box "Enter your static IP address for $int:" "192.168.69.101") fi echo " addresses: [$address/24]" >>/tmp/01-netcfg.yaml gateway="" - if [[ "$1" == "f4f" ]]; then + if [[ $USE_DEFAULTS_FOR == "F4F" ]]; then gateway=$(input_box "Enter your default gateway address:" "192.168.12.1") else gateway=$(input_box "Enter your default gateway address:" "192.168.69.1") @@ -173,7 +173,7 @@ else fi ap_name="" - if [[ "$1" == "f4f" ]]; then + if [[ $USE_DEFAULTS_FOR == "F4F" ]]; then ap_name=$(input_box "Enter your WiFi name (SSID):" "f4f_robot") else ap_name=$(input_box "Enter your WiFi name (SSID):" "mrs_ctu")