From 3c5688012f9ca29d2961103a56bfcfad607bd4c2 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 23 Feb 2024 19:20:39 +0100 Subject: [PATCH] refactor --- .../OPTIONS/app_net_ready/app_net_ready.sh | 6 ++-- RESOURCES/OPTIONS/banner/banner.sh | 19 ++-------- RESOURCES/OPTIONS/bluetooth/bluetooth.sh | 32 +++++------------ .../OPTIONS/boot_resource/boot_resource.sh | 11 ++---- RESOURCES/OPTIONS/camera/camera.sh | 36 +++---------------- .../OPTIONS/custom_update/custom_update.sh | 7 +--- RESOURCES/OPTIONS/fswebcam/fswebcam.sh | 20 ++--------- .../kobra_unleashed/kobra_unleashed.sh | 26 ++++++-------- RESOURCES/OPTIONS/opkg/opkg.sh | 25 ++++--------- RESOURCES/OPTIONS/python/python.sh | 21 +++-------- RESOURCES/OPTIONS/root_access/root_access.sh | 17 ++------- RESOURCES/OPTIONS/ssh/ssh.sh | 25 ++++--------- .../OPTIONS/startup_script/startup_script.sh | 29 +++++---------- RESOURCES/OPTIONS/uart/uart.sh | 19 ++-------- 14 files changed, 67 insertions(+), 226 deletions(-) diff --git a/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh b/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh index 572367c..42c9bed 100755 --- a/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh +++ b/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh @@ -22,14 +22,14 @@ if [ ! -d "$project_root" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 4 fi # try to find out the app version (like app_ver="309") -def_target="$project_root/unpacked/squashfs-root/app/app" +def_target="$ROOTFS_DIR/app/app" app_ver=$("$app_version_tool" "$def_target") if [ $? != 0 ]; then echo -e "${RED}ERROR: Cannot find the app version ${NC}" @@ -44,7 +44,7 @@ if [ $? != 0 ]; then fi # find if the selected setting file exists -settings_file="$project_root/RESOURCES/OPTIONS/app_net_ready/$settings/${app_ver}.${app_model}" +settings_file="$OPTIONS_DIR/app_net_ready/$settings/${app_ver}.${app_model}" if [ ! -f "$settings_file" ]; then echo -e "${RED}ERROR: Unsupported model and version! Cannot find the settings file '$settings_file' ${NC}" exit 7 diff --git a/RESOURCES/OPTIONS/banner/banner.sh b/RESOURCES/OPTIONS/banner/banner.sh index 26f0d21..9912893 100755 --- a/RESOURCES/OPTIONS/banner/banner.sh +++ b/RESOURCES/OPTIONS/banner/banner.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -17,15 +12,7 @@ banner_file="$2" # Echo the banner into $project_root/unpacked/etc/banner # Check the required tools -TOOL_LIST="cat" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "cat" # Check the project root folder if [ ! -d "$project_root" ]; then @@ -34,13 +21,13 @@ if [ ! -d "$project_root" ]; then fi # Check the banner exists -if [ ! -f "$project_root/RESOURCES/OPTIONS/$banner_file/$banner_file" ]; then +if [ ! -f "$OPTIONS_DIR/$banner_file/$banner_file" ]; then echo -e "${RED}ERROR: Cannot find the file '$banner_file' ${NC}" exit 3 fi # Overwrite the banner file with ./banner if error then exit -cat "$project_root/RESOURCES/OPTIONS/$banner_file/$banner_file" >"$project_root/unpacked/squashfs-root/etc/banner" +cat "$OPTIONS_DIR/$banner_file/$banner_file" >"$ROOTFS_DIR/etc/banner" if [ $? != 0 ]; then echo -e "${RED}ERROR: Cannot overwrite the banner file ${NC}" exit 4 diff --git a/RESOURCES/OPTIONS/bluetooth/bluetooth.sh b/RESOURCES/OPTIONS/bluetooth/bluetooth.sh index dacdae9..7cfed68 100755 --- a/RESOURCES/OPTIONS/bluetooth/bluetooth.sh +++ b/RESOURCES/OPTIONS/bluetooth/bluetooth.sh @@ -1,11 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,15 +9,7 @@ fi project_root="$1" # check the required tools -TOOL_LIST="rm" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "rm" # check the project root folder if [ ! -d "$project_root" ]; then @@ -52,18 +38,18 @@ folders=( # Remove the folders and files # Check if folder or file and remove it for folder in "${folders[@]}"; do - if [ -d "$project_root/unpacked/squashfs-root/$folder" ]; then - echo "Removing folder: $project_root/unpacked/squashfs-root/$folder" - rm -rf "$project_root/unpacked/squashfs-root/$folder" + if [ -d "$ROOTFS_DIR/$folder" ]; then + echo "Removing folder: $ROOTFS_DIR/$folder" + rm -rf "$ROOTFS_DIR/$folder" if [ $? -ne 0 ]; then - echo -e "${RED}ERROR: Failed to remove folder: $project_root/unpacked/squashfs-root/$folder ${NC}" + echo -e "${RED}ERROR: Failed to remove folder: $ROOTFS_DIR/$folder ${NC}" exit 3 fi - elif [ -f "$project_root/unpacked/squashfs-root/$folder" ]; then - echo "Removing file: $project_root/unpacked/squashfs-root/$folder" - rm -f "$project_root/unpacked/squashfs-root/$folder" + elif [ -f "$ROOTFS_DIR/$folder" ]; then + echo "Removing file: $ROOTFS_DIR/$folder" + rm -f "$ROOTFS_DIR/$folder" if [ $? -ne 0 ]; then - echo -e "${RED}ERROR: Failed to remove file: $project_root/unpacked/squashfs-root/$folder ${NC}" + echo -e "${RED}ERROR: Failed to remove file: $ROOTFS_DIR/$folder ${NC}" exit 3 fi fi diff --git a/RESOURCES/OPTIONS/boot_resource/boot_resource.sh b/RESOURCES/OPTIONS/boot_resource/boot_resource.sh index 4859210..e50796c 100755 --- a/RESOURCES/OPTIONS/boot_resource/boot_resource.sh +++ b/RESOURCES/OPTIONS/boot_resource/boot_resource.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -21,21 +16,21 @@ if [ ! -d "$project_root" ]; then fi # check the selected boot resource folder -boot_resource_folder="$project_root/RESOURCES/OPTIONS/boot_resource/$boot_resource" +boot_resource_folder="$OPTIONS_DIR/boot_resource/$boot_resource" if [ ! -d "$boot_resource_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$boot_resource_folder' ${NC}" exit 3 fi # check the selected boot resource file -boot_resource_file="$project_root/RESOURCES/OPTIONS/boot_resource/$boot_resource/boot-resource" +boot_resource_file="$boot_resource_folder/boot-resource" if [ ! -f "$boot_resource_file" ]; then echo -e "${RED}ERROR: Cannot find the folder '$boot_resource_file'\nPlease use 'sudo ./process.sh' to create the 'boot_resource' file from the source folder ${NC}" exit 3 fi # check the target folder -target_folder="$project_root/unpacked" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 4 diff --git a/RESOURCES/OPTIONS/camera/camera.sh b/RESOURCES/OPTIONS/camera/camera.sh index 2fa7596..87184ef 100755 --- a/RESOURCES/OPTIONS/camera/camera.sh +++ b/RESOURCES/OPTIONS/camera/camera.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -22,28 +17,7 @@ if [ "$package_action" == "run" ]; then auto_start="Y" fi -# check the required tools -app_version_tool=$(which app_version.sh) -app_model_tool=$(which app_model.sh) -TOOL_LIST="unzip app_version.sh app_model.sh dd printf" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - local_tool_path="$project_root/TOOLS/$tool_name" - if [ ! -f "$local_tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 2 - else - if [ "$tool_name" == "app_version.sh" ]; then - app_version_tool="$local_tool_path" - fi - if [ "$tool_name" == "app_model.sh" ]; then - app_model_tool="$local_tool_path" - fi - fi - fi -done +check_tools "unzip app_version.sh app_model.sh dd printf" # check the project root folder if [ ! -d "$project_root" ]; then @@ -52,7 +26,7 @@ if [ ! -d "$project_root" ]; then fi # check the webcam package folder -webcam_package_folder="${project_root}/RESOURCES/OPTIONS/camera/${package_name}" +webcam_package_folder="$OPTIONS_DIR/camera/$package_name" if [ ! -d "$webcam_package_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$webcam_package_folder' ${NC}" exit 4 @@ -66,7 +40,7 @@ if [ ! -f "$webcam_package_file" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 6 @@ -80,11 +54,11 @@ cd "$current_folder" || exit 8 if [ "$auto_start" == "N" ]; then # auto start not requested, remove the auto start - rm -f "$project_root/unpacked/squashfs-root/opt/etc/init.d/S55camera" + rm -f "$ROOTFS_DIR/opt/etc/init.d/S55camera" fi # try to find out the app version (like app_ver="309") -def_target="$project_root/unpacked/squashfs-root/app/app" +def_target="$ROOTFS_DIR/app/app" app_ver=$("$app_version_tool" "$def_target") if [ $? != 0 ]; then echo -e "${RED}ERROR: Cannot find the app version ${NC}" diff --git a/RESOURCES/OPTIONS/custom_update/custom_update.sh b/RESOURCES/OPTIONS/custom_update/custom_update.sh index 1a82afa..f653094 100755 --- a/RESOURCES/OPTIONS/custom_update/custom_update.sh +++ b/RESOURCES/OPTIONS/custom_update/custom_update.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -27,7 +22,7 @@ if [ ! -f "$public_key" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root/etc" +target_folder="$ROOTFS_DIR/etc" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the output folder '$target_folder' ${NC}" exit 4 diff --git a/RESOURCES/OPTIONS/fswebcam/fswebcam.sh b/RESOURCES/OPTIONS/fswebcam/fswebcam.sh index 37952c9..5586d11 100755 --- a/RESOURCES/OPTIONS/fswebcam/fswebcam.sh +++ b/RESOURCES/OPTIONS/fswebcam/fswebcam.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -14,16 +9,7 @@ fi project_root="$1" fswebcam_package="$2" -# check the required tools -TOOL_LIST="unzip sed" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "unzip sed" # check the project root folder if [ ! -d "$project_root" ]; then @@ -32,7 +18,7 @@ if [ ! -d "$project_root" ]; then fi # check the fswebcam package folder -fswebcam_package_folder="${project_root}/RESOURCES/OPTIONS/fswebcam/${fswebcam_package}" +fswebcam_package_folder="${OPTIONS_DIR}/fswebcam/${fswebcam_package}" if [ ! -d "$fswebcam_package_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$fswebcam_package_folder' ${NC}" exit 4 @@ -46,7 +32,7 @@ if [ ! -f "$fswebcam_package_file" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 6 diff --git a/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh b/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh index f966992..0384a3d 100755 --- a/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh +++ b/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh @@ -1,32 +1,28 @@ #!/bin/bash -RED='\033[0;31m' -YELLOW='\033[1;33m' -GREEN='\033[0;32m' -NC='\033[0m' - # default urls to be replaced mqtt_urls="mqtt-universe-test.anycubic.com mqtt-universe.anycubic.com mqtt-test.anycubic.com mqtt.anycubic.com" +project_root="$1" + # check the parameters if [ $# != 2 ]; then echo "usage : $0 " exit 1 fi -def_target="$1/unpacked/squashfs-root/app/app" +def_target="$ROOTFS_DIR/app/app" + def_url="$2" # check the required tools -TOOL_LIST="printf dd grep awk" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "printf dd grep awk" + +# check the project root folder +if [ ! -d "$project_root" ]; then + echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}" + exit 3 +fi # check the input file if [ ! -f "$def_target" ]; then diff --git a/RESOURCES/OPTIONS/opkg/opkg.sh b/RESOURCES/OPTIONS/opkg/opkg.sh index 50ad725..d17227e 100755 --- a/RESOURCES/OPTIONS/opkg/opkg.sh +++ b/RESOURCES/OPTIONS/opkg/opkg.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,15 +10,7 @@ project_root="$1" opkg_package="$2" # check the required tools -TOOL_LIST="unzip grep sed" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "unzip grep sed" # check the project root folder if [ ! -d "$project_root" ]; then @@ -32,7 +19,7 @@ if [ ! -d "$project_root" ]; then fi # check the opkg package folder -opkg_package_folder="${project_root}/RESOURCES/OPTIONS/opkg/${opkg_package}" +opkg_package_folder="${OPTIONS_DIR}/opkg/${opkg_package}" if [ ! -d "$opkg_package_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$opkg_package_folder' ${NC}" exit 4 @@ -46,7 +33,7 @@ if [ ! -f "$opkg_package_file" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 6 @@ -57,13 +44,13 @@ current_folder="$PWD" cd "$target_folder" || exit 7 unzip -o "$opkg_package_file" # add "/opt/etc/init.d/rc.unslung start" to $project_root/unpacked/squashfs-root/etc/rc.local before the exit 0 line -result=$(grep "/opt/etc/init.d/rc.unslung start" "$project_root/unpacked/squashfs-root/etc/rc.local") +result=$(grep "/opt/etc/init.d/rc.unslung start" "$ROOTFS_DIR/etc/rc.local") if [ -z "$result" ]; then # add it only if not already done - sed -i '/exit 0/i /opt/etc/init.d/rc.unslung start' "$project_root/unpacked/squashfs-root/etc/rc.local" + sed -i '/exit 0/i /opt/etc/init.d/rc.unslung start' "$ROOTFS_DIR/etc/rc.local" fi # extend the PATH to $project_root/unpacked/squashfs-root/etc/profile -sed -i 's#export PATH="/usr/sbin:/usr/bin:/sbin:/bin"#export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"#' "$project_root/unpacked/squashfs-root/etc/profile" +sed -i 's#export PATH="/usr/sbin:/usr/bin:/sbin:/bin"#export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"#' "$ROOTFS_DIR/etc/profile" cd "$current_folder" || exit 8 echo -e "${GREEN}SUCCESS: The '$opkg_package' opkg package has been installed ${NC}" diff --git a/RESOURCES/OPTIONS/python/python.sh b/RESOURCES/OPTIONS/python/python.sh index 88d1423..3bd3e4a 100755 --- a/RESOURCES/OPTIONS/python/python.sh +++ b/RESOURCES/OPTIONS/python/python.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,15 +10,7 @@ project_root="$1" python_package="$2" # check the required tools -TOOL_LIST="unzip sed" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "unzip sed" # check the project root folder if [ ! -d "$project_root" ]; then @@ -32,7 +19,7 @@ if [ ! -d "$project_root" ]; then fi # check the python package folder -python_package_folder="${project_root}/RESOURCES/OPTIONS/python/${python_package}" +python_package_folder="${OPTIONS_DIR}/python/${python_package}" if [ ! -d "$python_package_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$python_package_folder' ${NC}" exit 4 @@ -46,7 +33,7 @@ if [ ! -f "$python_package_file" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 6 @@ -57,7 +44,7 @@ current_folder="$PWD" cd "$target_folder" || exit 7 unzip -o "$python_package_file" # extend the PATH to $project_root/unpacked/squashfs-root/etc/profile -sed -i 's#export PATH="/usr/sbin:/usr/bin:/sbin:/bin"#export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"#' "$project_root/unpacked/squashfs-root/etc/profile" +sed -i 's#export PATH="/usr/sbin:/usr/bin:/sbin:/bin"#export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"#' "$ROOTFS_DIR/etc/profile" cd "$current_folder" || exit 8 echo -e "${GREEN}The python package has been successfully installed ${NC}" diff --git a/RESOURCES/OPTIONS/root_access/root_access.sh b/RESOURCES/OPTIONS/root_access/root_access.sh index e9adc07..b081202 100755 --- a/RESOURCES/OPTIONS/root_access/root_access.sh +++ b/RESOURCES/OPTIONS/root_access/root_access.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,15 +10,7 @@ project_root="$1" password_hash="$2" # check the required tools -TOOL_LIST="awk" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "awk" # check the project root folder if [ ! -d "$project_root" ]; then @@ -32,7 +19,7 @@ if [ ! -d "$project_root" ]; then fi # check the target file -target_file="$project_root/unpacked/squashfs-root/etc/shadow" +target_file="$ROOTFS_DIR/etc/shadow" if [ ! -f "$target_file" ]; then echo -e "${RED}ERROR: Cannot find the target file '$target_file' ${NC}" exit 3 diff --git a/RESOURCES/OPTIONS/ssh/ssh.sh b/RESOURCES/OPTIONS/ssh/ssh.sh index 248ad47..fe67781 100755 --- a/RESOURCES/OPTIONS/ssh/ssh.sh +++ b/RESOURCES/OPTIONS/ssh/ssh.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,15 +10,7 @@ project_root="$1" ssh_package="$2" # check the required tools -TOOL_LIST="unzip grep sed" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "unzip grep sed" # check the project root folder if [ ! -d "$project_root" ]; then @@ -32,7 +19,7 @@ if [ ! -d "$project_root" ]; then fi # check the ssh package folder -ssh_package_folder="${project_root}/RESOURCES/OPTIONS/ssh/${ssh_package}" +ssh_package_folder="$OPTIONS_DIR/ssh/${ssh_package}" if [ ! -d "$ssh_package_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$ssh_package_folder' ${NC}" exit 4 @@ -46,7 +33,7 @@ if [ ! -f "$ssh_package_file" ]; then fi # check the target folder -target_folder="$project_root/unpacked/squashfs-root" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 6 @@ -57,13 +44,13 @@ current_folder="$PWD" cd "$target_folder" || exit 7 unzip -o "$ssh_package_file" # add "/opt/etc/init.d/rc.unslung start" to $project_root/unpacked/squashfs-root/etc/rc.local before the exit 0 line -result=$(grep "/opt/etc/init.d/rc.unslung start" "$project_root/unpacked/squashfs-root/etc/rc.local") +result=$(grep "/opt/etc/init.d/rc.unslung start" "$ROOTFS_DIR/etc/rc.local") if [ -z "$result" ]; then # add it only if not already done - sed -i '/exit 0/i /opt/etc/init.d/rc.unslung start' "$project_root/unpacked/squashfs-root/etc/rc.local" + sed -i '/exit 0/i /opt/etc/init.d/rc.unslung start' "$ROOTFS_DIR/etc/rc.local" fi # extend the PATH to $project_root/unpacked/squashfs-root/etc/profile -sed -i 's#export PATH="/usr/sbin:/usr/bin:/sbin:/bin"#export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"#' "$project_root/unpacked/squashfs-root/etc/profile" +sed -i 's#export PATH="/usr/sbin:/usr/bin:/sbin:/bin"#export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"#' "$ROOTFS_DIR/etc/profile" cd "$current_folder" || exit 8 echo -e "${GREEN}The ssh package has been successfully installed ${NC}" diff --git a/RESOURCES/OPTIONS/startup_script/startup_script.sh b/RESOURCES/OPTIONS/startup_script/startup_script.sh index c1a860e..bfb3b4c 100755 --- a/RESOURCES/OPTIONS/startup_script/startup_script.sh +++ b/RESOURCES/OPTIONS/startup_script/startup_script.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,18 +10,10 @@ project_root="$1" startup_script="$2" # check the required tools -TOOL_LIST="sed" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "sed" # Check if $startup_script is available -if [ ! -f "$project_root/RESOURCES/OPTIONS/startup_script/$startup_script" ]; then +if [ ! -f "$OPTIONS_DIR/startup_script/$startup_script" ]; then echo -e "${RED}ERROR: Cannot find the file '$startup_script' ${NC}" exit 2 fi @@ -38,20 +25,20 @@ if [ ! -d "$project_root" ]; then fi # Check if $project_root/RESOURCES/KEYS/mosquitto exists -if [ ! -d "$project_root/RESOURCES/KEYS/mosquitto" ]; then - echo -e "${RED}ERROR: Cannot find the folder '$project_root/RESOURCES/KEYS/mosquitto' ${NC}" +if [ ! -d "$KEYS_DIR/mosquitto" ]; then + echo -e "${RED}ERROR: Cannot find the folder '$KEYS_DIR/mosquitto' ${NC}" exit 4 fi # Copy everything from $project_root/RESOURCES/KEYS/mosquitto to $project_root/unpacked/squashfs-root/etc/ssl/certs -mkdir -p "$project_root/unpacked/squashfs-root/etc/ssl/certs" -cp -rf "$project_root/RESOURCES/KEYS/mosquitto"/* "$project_root/unpacked/squashfs-root/etc/ssl/certs" +mkdir -p "$ROOTFS_DIR/etc/ssl/certs" +cp -rf "$KEYS_DIR/mosquitto"/* "$ROOTFS_DIR/etc/ssl/certs" # Move $startup_script to project root/unpacked/squashfs-root/etc -cp -rf "$project_root/RESOURCES/OPTIONS/startup_script/$startup_script" "$project_root/unpacked/squashfs-root/etc" +cp -rf "$OPTIONS_DIR/startup_script/$startup_script" "$ROOTFS_DIR/etc" # Add /etc/$startup_script to $project_root/unpacked/squashfs-root/etc/rc.local before the exit 0 line -sed -i "/exit 0/i /etc/$startup_script" "$project_root/unpacked/squashfs-root/etc/rc.local" +sed -i "/exit 0/i /etc/$startup_script" "$ROOTFS_DIR/etc/rc.local" echo -e "${GREEN}INFO: Startup script '$startup_script' has been installed ${NC}" diff --git a/RESOURCES/OPTIONS/uart/uart.sh b/RESOURCES/OPTIONS/uart/uart.sh index b264bd2..e734e4f 100755 --- a/RESOURCES/OPTIONS/uart/uart.sh +++ b/RESOURCES/OPTIONS/uart/uart.sh @@ -1,10 +1,5 @@ #!/bin/bash -# global definitions: -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - # check the parameters if [ $# != 2 ]; then echo "usage : $0 " @@ -15,15 +10,7 @@ project_root="$1" uart_package="$2" # check the required tools -TOOL_LIST="unzip" -for tool_name in $TOOL_LIST; do - echo "Checking tool: $tool_name" - tool_path=$(which "$tool_name") - if [ -z "$tool_path" ]; then - echo -e "${RED}ERROR: Missing tool '$tool_name' ${NC}" - exit 1 - fi -done +check_tools "unzip" # check the project root folder if [ ! -d "$project_root" ]; then @@ -32,7 +19,7 @@ if [ ! -d "$project_root" ]; then fi # check the uart package folder -uart_package_folder="${project_root}/RESOURCES/OPTIONS/uart/${uart_package}" +uart_package_folder="${OPTIONS_DIR}/uart/${uart_package}" if [ ! -d "$uart_package_folder" ]; then echo -e "${RED}ERROR: Cannot find the folder '$uart_package_folder' ${NC}" exit 4 @@ -46,7 +33,7 @@ if [ ! -f "$uart_package_file" ]; then fi # check the target folder -target_folder="$project_root/unpacked" +target_folder="$ROOTFS_DIR" if [ ! -d "$target_folder" ]; then echo -e "${RED}ERROR: Cannot find the target folder '$target_folder' ${NC}" exit 6