From 313c050ff81c21a6767f91722fbd723174f018ab Mon Sep 17 00:00:00 2001 From: AGG2017 Date: Sun, 18 Feb 2024 09:40:40 -0500 Subject: [PATCH] Proper tools checking --- RESOURCES/OPTIONS/app_dns/app_dns.sh | 11 +++++++++++ RESOURCES/OPTIONS/fswebcam/fswebcam.sh | 2 +- .../OPTIONS/kobra_unleashed/kobra_unleashed.sh | 11 +++++++++++ RESOURCES/OPTIONS/opkg/opkg.sh | 2 +- RESOURCES/OPTIONS/python/python.sh | 2 +- RESOURCES/OPTIONS/root_access/root_access.sh | 11 +++++++++++ RESOURCES/OPTIONS/ssh/ssh.sh | 2 +- .../OPTIONS/startup_script/startup_script.sh | 11 +++++++++++ RESOURCES/OPTIONS/webcam/webcam.sh | 2 +- pack.sh | 15 ++++++++++++--- patch.sh | 2 +- 11 files changed, 62 insertions(+), 9 deletions(-) diff --git a/RESOURCES/OPTIONS/app_dns/app_dns.sh b/RESOURCES/OPTIONS/app_dns/app_dns.sh index 54c873b..ac6f21d 100755 --- a/RESOURCES/OPTIONS/app_dns/app_dns.sh +++ b/RESOURCES/OPTIONS/app_dns/app_dns.sh @@ -13,6 +13,17 @@ fi project_root="$1" dns_replacement="$2" +# check the required tools +TOOL_LIST="printf dd grep cut xargs" +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 the project root folder if [ ! -d "$project_root" ]; then echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}" diff --git a/RESOURCES/OPTIONS/fswebcam/fswebcam.sh b/RESOURCES/OPTIONS/fswebcam/fswebcam.sh index 8956cdb..a9d2697 100755 --- a/RESOURCES/OPTIONS/fswebcam/fswebcam.sh +++ b/RESOURCES/OPTIONS/fswebcam/fswebcam.sh @@ -14,7 +14,7 @@ project_root="$1" fswebcam_package="$2" # check the required tools -TOOL_LIST="unzip" +TOOL_LIST="unzip sed" for tool_name in $TOOL_LIST; do echo "Checking tool: $tool_name" tool_path=$(which "$tool_name") diff --git a/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh b/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh index 36bcdcb..0e934b2 100755 --- a/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh +++ b/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh @@ -15,6 +15,17 @@ fi def_target="$1/unpacked/squashfs-root/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 the input file if [ ! -f "$def_target" ]; then echo -e "${RED}ERROR: Cannot find the app file ${NC}" diff --git a/RESOURCES/OPTIONS/opkg/opkg.sh b/RESOURCES/OPTIONS/opkg/opkg.sh index 4d0a26c..7a46d2e 100755 --- a/RESOURCES/OPTIONS/opkg/opkg.sh +++ b/RESOURCES/OPTIONS/opkg/opkg.sh @@ -14,7 +14,7 @@ project_root="$1" opkg_package="$2" # check the required tools -TOOL_LIST="unzip" +TOOL_LIST="unzip grep sed" for tool_name in $TOOL_LIST; do echo "Checking tool: $tool_name" tool_path=$(which "$tool_name") diff --git a/RESOURCES/OPTIONS/python/python.sh b/RESOURCES/OPTIONS/python/python.sh index bd8f204..44e7c55 100755 --- a/RESOURCES/OPTIONS/python/python.sh +++ b/RESOURCES/OPTIONS/python/python.sh @@ -14,7 +14,7 @@ project_root="$1" python_package="$2" # check the required tools -TOOL_LIST="unzip" +TOOL_LIST="unzip sed" for tool_name in $TOOL_LIST; do echo "Checking tool: $tool_name" tool_path=$(which "$tool_name") diff --git a/RESOURCES/OPTIONS/root_access/root_access.sh b/RESOURCES/OPTIONS/root_access/root_access.sh index ed1137f..7c03418 100755 --- a/RESOURCES/OPTIONS/root_access/root_access.sh +++ b/RESOURCES/OPTIONS/root_access/root_access.sh @@ -13,6 +13,17 @@ fi 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 the project root folder if [ ! -d "$project_root" ]; then echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}" diff --git a/RESOURCES/OPTIONS/ssh/ssh.sh b/RESOURCES/OPTIONS/ssh/ssh.sh index 6e70efd..d93e188 100755 --- a/RESOURCES/OPTIONS/ssh/ssh.sh +++ b/RESOURCES/OPTIONS/ssh/ssh.sh @@ -14,7 +14,7 @@ project_root="$1" ssh_package="$2" # check the required tools -TOOL_LIST="unzip" +TOOL_LIST="unzip grep sed" for tool_name in $TOOL_LIST; do echo "Checking tool: $tool_name" tool_path=$(which "$tool_name") diff --git a/RESOURCES/OPTIONS/startup_script/startup_script.sh b/RESOURCES/OPTIONS/startup_script/startup_script.sh index 3833836..1bff6c5 100755 --- a/RESOURCES/OPTIONS/startup_script/startup_script.sh +++ b/RESOURCES/OPTIONS/startup_script/startup_script.sh @@ -13,6 +13,17 @@ fi 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 if $startup_script is available if [ ! -f "$project_root/RESOURCES/OPTIONS/startup_script/$startup_script" ]; then echo -e "${RED}ERROR: Cannot find the file '$startup_script' ${NC}" diff --git a/RESOURCES/OPTIONS/webcam/webcam.sh b/RESOURCES/OPTIONS/webcam/webcam.sh index 2f03d95..a6991bc 100755 --- a/RESOURCES/OPTIONS/webcam/webcam.sh +++ b/RESOURCES/OPTIONS/webcam/webcam.sh @@ -16,7 +16,7 @@ webcam_package="$2" # 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" +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") diff --git a/pack.sh b/pack.sh index 5b64226..d96c9dd 100755 --- a/pack.sh +++ b/pack.sh @@ -12,7 +12,7 @@ installed_options="installed_options.log" FILES="sw-description sw-description.sig boot-resource uboot boot0 kernel rootfs dsp0 cpio_item_md5" # check the required tools -TOOL_LIST="grep md5sum openssl sha256sum mksquashfs python3 auto_install.py" +TOOL_LIST="grep md5sum openssl wc awk sha256sum mksquashfs python3 auto_install.py" for tool_name in $TOOL_LIST; do echo "Checking tool: $tool_name" tool_path=$(which "$tool_name") @@ -40,12 +40,20 @@ cd unpacked || exit 2 rm -rf rootfs mksquashfs squashfs-root rootfs -comp xz -all-root +# check if the updated rootfs can fit in the partitions rootfsA/B +file_size=$(wc -c rootfs | awk '{print $1}') +if [ "$file_size" -ge 134217729 ]; then + echo -e "${RED}ERROR: The size of the file 'unpacked/rootfs' is larger than the max 128MB allowed.\Please disable some of the less important options and try again! ${NC}" + cd .. + exit 3 +fi + # check the input files for i in $FILES; do if [ "$i" != "cpio_item_md5" ] && [ ! -f "$i" ]; then echo -e "${RED}ERROR: Cannot find the input file '$i' ${NC}" cd .. - exit 3 + exit 4 fi done @@ -59,7 +67,8 @@ for i in $FILES; do sed -i -e "s/$hash_old/$hash_new/g" sw-description else echo -e "${RED}ERROR: Cannot find the hash for: '$i' ${NC}" - exit 4 + cd .. + exit 5 fi fi done diff --git a/patch.sh b/patch.sh index df61a1d..4f97084 100755 --- a/patch.sh +++ b/patch.sh @@ -27,7 +27,7 @@ if [ ! -f "$optionsfile" ]; then fi # check the required tools -TOOL_LIST="awk" +TOOL_LIST="awk head sed" for tool_name in $TOOL_LIST; do echo "Checking tool: $tool_name" tool_path=$(which "$tool_name")