diff --git a/RESOURCES/OpenCentauri/boot-resource b/RESOURCES/OpenCentauri/boot-resource new file mode 100644 index 0000000..c4ce91b Binary files /dev/null and b/RESOURCES/OpenCentauri/boot-resource differ diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..c4f1f41 --- /dev/null +++ b/configure.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +CONFIG_FILE="patch_config" +HELP_FILE="./key_info.sh" +TEMP_INPUT=$(mktemp) +TEMP_CONFIG=$(mktemp) + +# Load help descriptions +if ! source "$HELP_FILE"; then + echo "Error: Could not load help text from $HELP_FILE" + exit 1 +fi + +# Read config into associative array +declare -A config +while IFS='=' read -r raw_key raw_value; do + [[ -z "$raw_key" || "$raw_key" =~ ^# ]] && continue + key=$(echo "$raw_key" | xargs) + value=$(echo "$raw_value" | xargs) + config["$key"]="$value" +done < "$CONFIG_FILE" + +# Edit function +edit_key() { + local key="$1" + local current="${config[$key]}" + local desc="${help_short[$key]:-No description available}" + local help="${help_long[$key]:-No additional help available.}" + + local prompt="$desc\n\n$help\n\nCurrent value: $current\n\nPress Enter to confirm." + + dialog --clear \ + --inputbox "$prompt" 18 70 "$current" 2> "$TEMP_INPUT" + + [[ $? -ne 0 ]] && return + + local input + input=$(<"$TEMP_INPUT") + config["$key"]="$input" +} + +# Main loop +while true; do + menu_items=() + key_list=() + index=1 + + for key in "${!config[@]}"; do + desc="${help_short[$key]:-No description available}" + val="${config[$key]}" + menu_items+=("$index" "$desc (Current: $val)") + key_list[$index]="$key" + ((index++)) + done + + dialog --clear \ + --title "Patch Config Editor" \ + --menu "Select a setting to edit:" \ + 20 75 12 \ + "${menu_items[@]}" 2> "$TEMP_INPUT" + + [[ $? -ne 0 ]] && break + + selection=$(<"$TEMP_INPUT") + selected_key="${key_list[$selection]}" + edit_key "$selected_key" +done + +# Save config +declare -A updated_keys +> "$TEMP_CONFIG" + +while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" =~ ^[[:space:]]*# ]] || [[ -z "$line" ]]; then + echo "$line" >> "$TEMP_CONFIG" + continue + fi + + if [[ "$line" =~ ^[[:space:]]*([^=[:space:]]+)[[:space:]]*=[[:space:]]*(.*)$ ]]; then + key="${BASH_REMATCH[1]}" + if [[ -n "${config[$key]+_}" ]]; then + if [[ -z "${updated_keys[$key]+_}" ]]; then + echo "$key=${config[$key]}" >> "$TEMP_CONFIG" + updated_keys[$key]=1 + else + continue + fi + else + echo "$line" >> "$TEMP_CONFIG" + fi + else + echo "$line" >> "$TEMP_CONFIG" + fi +done < "$CONFIG_FILE" + +# Append any new keys +for key in "${!config[@]}"; do + if [[ -z "${updated_keys[$key]+_}" ]]; then + echo "$key=${config[$key]}" >> "$TEMP_CONFIG" + fi +done + +mv "$TEMP_CONFIG" "$CONFIG_FILE" +rm -f "$TEMP_INPUT" + +dialog --msgbox "Configuration saved to '$CONFIG_FILE'." 6 50 +clear diff --git a/key_info.sh b/key_info.sh new file mode 100755 index 0000000..785cbcc --- /dev/null +++ b/key_info.sh @@ -0,0 +1,9 @@ +# Short descriptions for config keys +declare -A help_short=( + [OC_APP_BOOT_DELAY]="Core app boot delay (in seconds)" +) + +# Long descriptions for config keys +declare -A help_long=( + [OC_APP_BOOT_DELAY]="How long to wait until starting /app/app on boot. If non-zero, you can SSH in after boot and run 'noapp' to prevent start" +) diff --git a/patch.sh b/patch.sh index 0573b16..087fe9d 100755 --- a/patch.sh +++ b/patch.sh @@ -2,6 +2,7 @@ # # Script to apply the standard patchset for OpenCentauri Firmware Build # +DEBUG_PATCH=0 if [ $UID -ne 0 ]; then echo "Error: Please run as root." @@ -22,49 +23,51 @@ check_tools "grep md5sum openssl wc awk sha256sum mksquashfs git git-lfs" # Source the ./patch_config config settings! . $(dirname $0)/patch_config -echo Go into the squashfs-root dir for the rest of the steps! +echo "Go into the squashfs-root dir for the rest of the steps!" cd ./unpacked/squashfs-root +if [ $DEBUG_PATCH = 1 ]; then set -x +fi -echo Check MD5sum on OpenCentauri bootstrap +echo "Check MD5sum on OpenCentauri bootstrap" if [[ ! $(md5sum "$OC_BOOTSTRAP" | awk '{print $1}') = "$OC_BOOTSTRAP_MD5" ]]; then printf "MD5 hash of %s does not match expected %s, aborting...\n" "$OC_BOOTSTRAP" "$OC_BOOTSTRAP_MD5" exit 1 fi -echo Copy over the OpenCentauri bootstrap tarball to /app +echo "Copy over the OpenCentauri bootstrap tarball to /app" cp ../../RESOURCES/OpenCentauri/OpenCentauri-bootstrap.tar.gz ./app chmod 644 ./app/OpenCentauri-bootstrap.tar.gz -echo Install OpenCentauri firmware public key +echo "Install OpenCentauri firmware public key" cat ../../RESOURCES/KEYS/swupdate_public.pem > ./etc/swupdate_public.pem -echo Install OpenCentauri banner file +echo "Install OpenCentauri banner file" cat ../../RESOURCES/OpenCentauri/banner > ./etc/banner -echo Configure bind-shell for recovery purposes on 4567/tcp +echo "Configure bind-shell for recovery purposes on 4567/tcp" cat ../../RESOURCES/OpenCentauri/bind-shell > ./app/bind-shell chmod 755 ./app/bind-shell cat ../../RESOURCES/OpenCentauri/12-shell > ./etc/hotplug.d/block/12-shell chmod 644 ./etc/hotplug.d/block/12-shell -echo Block Elegoo automated FW updates from Chitui via hosts file entry +echo "Block Elegoo automated FW updates from Chitui via hosts file entry" sed -re '1a # Block automatic software updates from Elegoo\n127.0.0.1 mms.chituiot.com' -i ./etc/hosts -echo Set root password to 'OpenCentauri' +echo "Set root password to 'OpenCentauri'" sed -re 's|^root:[^:]+:(.*)$|root:$1$rjtTIZX8$BmFRX/0pY6iP8VemQeOhN/:\1|' -i ./etc/shadow -echo Add mlocate group +echo "Add mlocate group" sed -re 's|^(network.+)$|\1\nmlocate:x:102:|' -i ./etc/group -echo Fix fgrep error on login in /etc/profile +echo "Fix fgrep error on login in /etc/profile" sed -re 's|fgrep|grep -F|' -i ./etc/profile -echo Create sshd privilege separation user +echo "Create sshd privilege separation user" echo 'sshd:x:22:65534:OpenSSH Server:/opt/var/empty:/dev/null' >> ./etc/passwd -echo Set hostname to OpenCentauri +echo "Set hostname to OpenCentauri" sed -re 's|TinaLinux|OpenCentauri|' -i ./etc/config/system echo 'Update web interface JavaScript and overlay image(s)' @@ -72,14 +75,14 @@ cat ../../RESOURCES/OpenCentauri/opencentauri-logo-small.png > ./app/www/assets/ # Need to re-size logo width from 160px to 300px so it's not to small, since wider! sed -re 's|(logo-img\[.+\])\{width:160px\}|\1{width:300px}|' -i ./app/www/*.js -echo Add OpenCentauri initialization to /etc/rc.local +echo "Add OpenCentauri initialization to /etc/rc.local" # Just copy in the modified /etc/rc.local, need to make this better... cat ../../RESOURCES/OpenCentauri/rc.local > ./etc/rc.local # Do edits to this file from ./patch_config sed -re "s|%OC_APP_BOOT_DELAY%|$OC_APP_BOOT_DELAY|g" -i ./etc/rc.local sed -re "s|%OC_APP_GADGET%|$OC_APP_GADGET|g" -i ./etc/rc.local -echo Installing automatic wifi scripts/automation to run on boot +echo "Installing automatic wifi scripts/automation to run on boot" # Install oc-startwifi.sh script to /app: cat ../../RESOURCES/OpenCentauri/oc-startwifi.sh > ./app/oc-startwifi.sh chmod 755 ./app/oc-startwifi.sh @@ -97,6 +100,11 @@ chmod 755 ./usr/sbin/mount_usb cat ../../RESOURCES/OpenCentauri/mount_usb_daemon > ./usr/sbin/mount_usb_daemon chmod 755 ./usr/sbin/mount_usb_daemon +if [ $INCLUDE_CUSTOM_SPLASH = 1 ]; then +cp ../../RESOURCES/OpenCentauri/boot-resource ../boot-resource +echo "Custom Boot-resource copied in!" +fi + # TODO: Fix swupdate_cmd.sh -i /mnt/exUDISK/update/update.swu -e stable,now_A_next_B -k /etc/swupdate_public.pem # Write log to /mnt/exUDISK/ instead of /mnt/UDISK diff --git a/patch_config b/patch_config index fd0aef0..ad5d9cb 100644 --- a/patch_config +++ b/patch_config @@ -14,3 +14,6 @@ OC_APP_BOOT_DELAY=10 # If this file exists, then auto noapp on boot # Designed to allow for a Raspberry Pi in gadget mode to plug in! OC_APP_GADGET=/dev/ttyACM0 + +# Flash with the OpenCentauri custom splash screen +INCLUDE_CUSTOM_SPLASH=1