From a43cdacb7e3fdb9f1f0ae0e9d1c2f6417f2d4ca5 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 23 Feb 2024 15:30:30 +0100 Subject: [PATCH] add more options --- RESOURCES/OPTIONS/app_dns/app_dns.sh | 7 +- RESOURCES/OPTIONS/app_images/app_images.sh | 3 + .../OPTIONS/app_net_ready/app_net_ready.sh | 3 + RESOURCES/OPTIONS/banner/banner | 8 +++ RESOURCES/OPTIONS/banner/banner.sh | 51 +++++++++++++ RESOURCES/OPTIONS/bluetooth/bluetooth.sh | 72 +++++++++++++++++++ .../OPTIONS/boot_resource/boot_resource.sh | 3 + RESOURCES/OPTIONS/camera/camera.sh | 4 ++ .../OPTIONS/custom_update/custom_update.sh | 3 + RESOURCES/OPTIONS/fswebcam/fswebcam.sh | 3 + .../kobra_unleashed/kobra_unleashed.sh | 7 +- RESOURCES/OPTIONS/opkg/opkg.sh | 3 + RESOURCES/OPTIONS/python/python.sh | 3 + RESOURCES/OPTIONS/root_access/root_access.sh | 3 + RESOURCES/OPTIONS/ssh/ssh.sh | 3 + .../OPTIONS/startup_script/startup_script.sh | 3 + RESOURCES/OPTIONS/uart/uart.sh | 3 + options.cfg | 7 ++ patch.sh | 3 +- 19 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 RESOURCES/OPTIONS/banner/banner create mode 100755 RESOURCES/OPTIONS/banner/banner.sh create mode 100755 RESOURCES/OPTIONS/bluetooth/bluetooth.sh diff --git a/RESOURCES/OPTIONS/app_dns/app_dns.sh b/RESOURCES/OPTIONS/app_dns/app_dns.sh index ac6f21d..7065897 100755 --- a/RESOURCES/OPTIONS/app_dns/app_dns.sh +++ b/RESOURCES/OPTIONS/app_dns/app_dns.sh @@ -2,6 +2,8 @@ # global definitions: RED='\033[0;31m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -49,7 +51,8 @@ dns_url="udp://$old_dns:53" results=$(grep --binary-files=text -b -o "$dns_url" "$def_target" | xargs echo -n) if [ -z "$results" ]; then echo -e "${RED}ERROR: The 'app' might be already patched. Cannot find the expected DNS '$dns_url' ${NC}" - exit 5 + echo -e "${YELLOW}INFO: Will not patch the 'app' file...${NC}" + exit 0 fi # replace all found old DNS with the new one for result in $results; do @@ -57,4 +60,6 @@ for result in $results; do printf "udp://%s:53\x00" "$new_dns" | dd of="$def_target" bs=1 seek="$offset" conv=notrunc &>>/dev/null done +echo -e "${GREEN}SUCCESS: The 'app' has been patched with the new DNS '$new_dns' ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/app_images/app_images.sh b/RESOURCES/OPTIONS/app_images/app_images.sh index 55ce5ec..f579576 100755 --- a/RESOURCES/OPTIONS/app_images/app_images.sh +++ b/RESOURCES/OPTIONS/app_images/app_images.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -36,4 +37,6 @@ fi # copy the selected image set to the target /bin/cp -rf "$image_set_folder" "$target_folder" +echo -e "${GREEN}SUCCESS: The '$image_set' image set has been copied to the target folder ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh b/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh index dd1b9ef..303ba2d 100755 --- a/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh +++ b/RESOURCES/OPTIONS/app_net_ready/app_net_ready.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -78,4 +79,6 @@ while read -r line; do printf "$settings_data" | dd of="$def_target" bs=1 seek="$settings_addr" conv=notrunc done <"$settings_file" +echo -e "${GREEN}SUCCESS: The 'app_net_ready' settings have been applied ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/banner/banner b/RESOURCES/OPTIONS/banner/banner new file mode 100644 index 0000000..5c2d673 --- /dev/null +++ b/RESOURCES/OPTIONS/banner/banner @@ -0,0 +1,8 @@ + ████████╗██╗███╗ ██╗ █████╗ ███╗ ███╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██╗ + ╚══██╔══╝██║████╗ ██║██╔══██╗ ████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗██║ + ██║ ██║██╔██╗ ██║███████║ ██╔████╔██║██║ ██║██║ ██║██║ ██║█████╗ ██║ ██║██║ + ██║ ██║██║╚██╗██║██╔══██║ ██║╚██╔╝██║██║ ██║██║ ██║██║ ██║██╔══╝ ██║ ██║╚═╝ + ██║ ██║██║ ╚████║██║ ██║ ██║ ╚═╝ ██║╚██████╔╝██████╔╝██████╔╝███████╗██████╔╝██╗ + ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═╝ + + Based on OpenWrt! | Tina Linux (Neptune, 619) \ No newline at end of file diff --git a/RESOURCES/OPTIONS/banner/banner.sh b/RESOURCES/OPTIONS/banner/banner.sh new file mode 100755 index 0000000..26f0d21 --- /dev/null +++ b/RESOURCES/OPTIONS/banner/banner.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# global definitions: +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' + +# check the parameters +if [ $# != 2 ]; then + echo "usage : $0 " + exit 1 +fi + +project_root="$1" +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 the project root folder +if [ ! -d "$project_root" ]; then + echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}" + exit 2 +fi + +# Check the banner exists +if [ ! -f "$project_root/RESOURCES/OPTIONS/$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" +if [ $? != 0 ]; then + echo -e "${RED}ERROR: Cannot overwrite the banner file ${NC}" + exit 4 +fi + +echo -e "${GREEN}SUCCESS: The 'banner' file has been overwritten ${NC}" + +exit 0 diff --git a/RESOURCES/OPTIONS/bluetooth/bluetooth.sh b/RESOURCES/OPTIONS/bluetooth/bluetooth.sh new file mode 100755 index 0000000..dacdae9 --- /dev/null +++ b/RESOURCES/OPTIONS/bluetooth/bluetooth.sh @@ -0,0 +1,72 @@ +#!/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 " + exit 1 +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 the project root folder +if [ ! -d "$project_root" ]; then + echo -e "${RED}ERROR: Cannot find the folder '$project_root' ${NC}" + exit 2 +fi + +# Check the bluetooth folder and if exist then remove it + +# A list of folders to remove +# Create an array of folders to remove +folders=( + "etc/bluetooth" + "etc/dbus-1/system.d/bluetooth*.conf" + "lib/bluetooth" + "lib/upgrade/keep.d/bluez-daemon" + "usr/bin/bccmd" + "usr/bin/bdaddr" + "usr/bin/blue*" + "usr/bin/bt*" + "usr/lib/alsa-lib" + "usr/lib/libbluetooth*" + "usr/share/alsa/alsa.conf.d/20-bluealsa.conf" +) + +# 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 [ $? -ne 0 ]; then + echo -e "${RED}ERROR: Failed to remove folder: $project_root/unpacked/squashfs-root/$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" + if [ $? -ne 0 ]; then + echo -e "${RED}ERROR: Failed to remove file: $project_root/unpacked/squashfs-root/$folder ${NC}" + exit 3 + fi + fi +done + +echo -e "${GREEN}SUCCESS: The 'bluetooth' has been removed ${NC}" diff --git a/RESOURCES/OPTIONS/boot_resource/boot_resource.sh b/RESOURCES/OPTIONS/boot_resource/boot_resource.sh index 0887727..4859210 100755 --- a/RESOURCES/OPTIONS/boot_resource/boot_resource.sh +++ b/RESOURCES/OPTIONS/boot_resource/boot_resource.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -43,4 +44,6 @@ fi # copy the selected boot resource to the target /bin/cp -f "$boot_resource_file" "$target_folder" +echo -e "${GREEN}SUCCESS: The '$boot_resource' boot resource has been copied to the target folder ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/camera/camera.sh b/RESOURCES/OPTIONS/camera/camera.sh index aeb7be2..2fa7596 100755 --- a/RESOURCES/OPTIONS/camera/camera.sh +++ b/RESOURCES/OPTIONS/camera/camera.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -106,16 +107,19 @@ if [ "$app_ver" == "3.0.9" ]; then if [ "$app_model" == "K2Pro" ]; then # stop the app to log the message 'cannot open video' printf "\x00\xf0\x20\xe3" | dd of="$def_target" bs=1 seek=2339112 conv=notrunc + echo -e "${GREEN}SUCCESS: The 'app' has been patched to support the webcam package (K2Pro) ${NC}" exit 0 fi if [ "$app_model" == "K2Plus" ]; then # stop the app to log the message 'cannot open video' printf "\x00\xf0\x20\xe3" | dd of="$def_target" bs=1 seek=2339152 conv=notrunc + echo -e "${GREEN}SUCCESS: The 'app' has been patched to support the webcam package (K2Plus) ${NC}" exit 0 fi if [ "$app_model" == "K2Max" ]; then # stop the app to log the message 'cannot open video' printf "\x00\xf0\x20\xe3" | dd of="$def_target" bs=1 seek=2339152 conv=notrunc + echo -e "${GREEN}SUCCESS: The 'app' has been patched to support the webcam package (K2Max) ${NC}" exit 0 fi fi diff --git a/RESOURCES/OPTIONS/custom_update/custom_update.sh b/RESOURCES/OPTIONS/custom_update/custom_update.sh index 14a75d1..1a82afa 100755 --- a/RESOURCES/OPTIONS/custom_update/custom_update.sh +++ b/RESOURCES/OPTIONS/custom_update/custom_update.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -35,4 +36,6 @@ fi # enable custom updates by providing a custom public key cp "$public_key" "$target_folder" +echo -e "${GREEN}SUCCESS: The custom public key has been copied to the target folder ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/fswebcam/fswebcam.sh b/RESOURCES/OPTIONS/fswebcam/fswebcam.sh index a9d2697..37952c9 100755 --- a/RESOURCES/OPTIONS/fswebcam/fswebcam.sh +++ b/RESOURCES/OPTIONS/fswebcam/fswebcam.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -59,4 +60,6 @@ unzip -o "$fswebcam_package_file" 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" cd "$current_folder" || exit 8 +echo -e "${GREEN}SUCCESS: The '$fswebcam_package' fswebcam package has been enabled ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh b/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh index 0e934b2..f966992 100755 --- a/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh +++ b/RESOURCES/OPTIONS/kobra_unleashed/kobra_unleashed.sh @@ -1,6 +1,8 @@ #!/bin/bash RED='\033[0;31m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' NC='\033[0m' # default urls to be replaced @@ -38,7 +40,8 @@ for url in $mqtt_urls; do grep "$mqtt_url" "$def_target" &>>/dev/null if [ $? -ne 0 ]; then echo -e "${RED}ERROR: The 'app' might be already patched. Cannot find the expected URL '$mqtt_url' ${NC}" - exit 3 + echo -e "${YELLOW}INFO: Will not patch the 'app' file...${NC}" + exit 0 fi done @@ -53,4 +56,6 @@ for url in $mqtt_urls; do printf "mqtts://%s:8883\x00" "$def_url" | dd of="$def_target" bs=1 seek="$offset" conv=notrunc &>>/dev/null done +echo -e "${GREEN}INFO: The 'app' file has been successfully patched with the custom MQTT URL ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/opkg/opkg.sh b/RESOURCES/OPTIONS/opkg/opkg.sh index 7a46d2e..50ad725 100755 --- a/RESOURCES/OPTIONS/opkg/opkg.sh +++ b/RESOURCES/OPTIONS/opkg/opkg.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -65,4 +66,6 @@ fi 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" cd "$current_folder" || exit 8 +echo -e "${GREEN}SUCCESS: The '$opkg_package' opkg package has been installed ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/python/python.sh b/RESOURCES/OPTIONS/python/python.sh index 44e7c55..88d1423 100755 --- a/RESOURCES/OPTIONS/python/python.sh +++ b/RESOURCES/OPTIONS/python/python.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -59,4 +60,6 @@ unzip -o "$python_package_file" 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" cd "$current_folder" || exit 8 +echo -e "${GREEN}The python package has been successfully installed ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/root_access/root_access.sh b/RESOURCES/OPTIONS/root_access/root_access.sh index 7c03418..e9adc07 100755 --- a/RESOURCES/OPTIONS/root_access/root_access.sh +++ b/RESOURCES/OPTIONS/root_access/root_access.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -41,4 +42,6 @@ fi shadow_temp="${target_file}_temp" awk "BEGIN{FS=\":\"; OFS=FS} \$1==\"root\"{\$2=\"$password_hash\"} {print}" "$target_file" >"$shadow_temp" && mv "$shadow_temp" "$target_file" +echo -e "${GREEN}Root access enabled${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/ssh/ssh.sh b/RESOURCES/OPTIONS/ssh/ssh.sh index d93e188..248ad47 100755 --- a/RESOURCES/OPTIONS/ssh/ssh.sh +++ b/RESOURCES/OPTIONS/ssh/ssh.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -65,4 +66,6 @@ fi 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" cd "$current_folder" || exit 8 +echo -e "${GREEN}The ssh package has been successfully installed ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/startup_script/startup_script.sh b/RESOURCES/OPTIONS/startup_script/startup_script.sh index 1bff6c5..c1a860e 100755 --- a/RESOURCES/OPTIONS/startup_script/startup_script.sh +++ b/RESOURCES/OPTIONS/startup_script/startup_script.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -52,4 +53,6 @@ cp -rf "$project_root/RESOURCES/OPTIONS/startup_script/$startup_script" "$projec # 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" +echo -e "${GREEN}INFO: Startup script '$startup_script' has been installed ${NC}" + exit 0 diff --git a/RESOURCES/OPTIONS/uart/uart.sh b/RESOURCES/OPTIONS/uart/uart.sh index a49de95..b264bd2 100755 --- a/RESOURCES/OPTIONS/uart/uart.sh +++ b/RESOURCES/OPTIONS/uart/uart.sh @@ -2,6 +2,7 @@ # global definitions: RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # check the parameters @@ -57,4 +58,6 @@ cd "$target_folder" || exit 7 unzip -o "$uart_package_file" cd "$current_folder" || exit 8 +echo -e "${GREEN}INFO: The UART package has been installed. Version: $uart_package ${NC}" + exit 0 diff --git a/options.cfg b/options.cfg index 8b1cac7..251ed16 100644 --- a/options.cfg +++ b/options.cfg @@ -64,6 +64,9 @@ python="3.11" # It requires the options: [python], [fswebcam] and [ssh] #camera="3d-visualizer.run" [python] [fswebcam] [ssh] +# Change the banner to a custom one. (Recommended when custom firmware) +banner="banner" + # Enable the web interface Kobra Unleashed # More information: https://github.com/anjomro/kobra-unleashed # Replace the URL below with the URL of your MQTT server @@ -72,6 +75,10 @@ python="3.11" # Always keep a copy of the original keys in case you want to go back to AC cloud kobra_unleashed="localhost.mr-a.de" +# Delete the Bluetooth support because it's not used by Kobra Unleashed +# and can't be used since we replace mqtt anyways. +bluetooth="default" + # Patch the app to check the captive portal URLs less often (originally every 2s) # It is used to detect if the internet connection is established and alive # This patch will produce less unwanted web traffic if enabled diff --git a/patch.sh b/patch.sh index 1198204..6aeb9f3 100755 --- a/patch.sh +++ b/patch.sh @@ -9,6 +9,7 @@ installed_options="installed_options.log" # global definitions: RED='\033[0;31m' GREEN='\033[0;32m' +PURPLE='\033[0;35m' NC='\033[0m' project_root="$PWD" @@ -45,7 +46,7 @@ options=$(awk -F '=' '{if (! ($0 ~ /^;/) && ! ($0 ~ /^#/) && ! ($0 ~ /^$/) && ! # for each enabled option for option in $options; do - echo "Processing option '$option' ..." + echo -e "${PURPLE}Processing option '$option' ...${NC}" # parse the parameters (only from the first found option) # duplicated options are not supported, if needed use list of parameters for the same option: # startup_script="script1.sh" "script2.sh" "script3.sh"