#!/bin/ash clean_distfeeds() { # Define the list of items to comment out items_to_comment=$(cat <> "$TEMP_FILE" continue 2 fi done # Check if the line matches items to keep for item in $items_to_keep; do if [ "$line" = "$item" ] || [ "$line" = "# $item" ]; then echo "$item" >> "$TEMP_FILE" continue 2 fi done # Preserve all other lines echo "$line" >> "$TEMP_FILE" done < "$INPUT_FILE" # Ensure all items_to_keep are present for item in $items_to_keep; do if ! grep -qx "$item" "$TEMP_FILE"; then echo "$item" >> "$TEMP_FILE" fi done # Replace the original file with the modified one mv "$TEMP_FILE" "$INPUT_FILE" echo "Processed '$INPUT_FILE'. Backup saved as '${INPUT_FILE}.bak'." } repo_iamromulanSDXPINN_check() { # Define the repository and key details STABLE_REPO_LINE="src/gz iamromulan-SDXPINN-repo https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/SDXPINN/opkg-feed" DEV_REPO_LINE="src/gz iamromulan-SDXPINN-repo https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/development-SDXPINN/opkg-feed" FEEDS_FILE="/etc/opkg/customfeeds.conf" PUBLIC_KEY_URL="https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/SDXPINN/opkg-feed/iamromulan-SDXPINN-repo.key" TMP_KEY="/tmp/iamromulan-SDXPINN-repo.key" KEYS_DIR="/etc/opkg/keys" # Remove duplicate and development repo lines if grep -q "iamromulan-SDXPINN-repo" "$FEEDS_FILE"; then echo "Cleaning up duplicate or development repo entries in $FEEDS_FILE." sed -i "/iamromulan-SDXPINN-repo/d" "$FEEDS_FILE" fi # Add the stable repository to customfeeds.conf echo "Adding stable repository to $FEEDS_FILE." echo "$STABLE_REPO_LINE" >> "$FEEDS_FILE" || { echo "Error: Could not add repository to $FEEDS_FILE." return 1 } # Download the key temporarily for verification curl -fsSL "$PUBLIC_KEY_URL" -o "$TMP_KEY" || { echo "Error: Failed to download public key from $PUBLIC_KEY_URL." return 1 } # Check if the key already exists in /etc/opkg/keys/ local key_installed=0 for key in "$KEYS_DIR"/*; do if cmp -s "$TMP_KEY" "$key"; then echo "Public key already installed: $(basename "$key")." key_installed=1 break fi done # If the key is not installed, add it if [ "$key_installed" -eq 0 ]; then echo "Installing public key..." opkg-key add "$TMP_KEY" || { echo "Error: Failed to add public key." rm -f "$TMP_KEY" return 1 } echo "Public key installed successfully." fi # Clean up temporary key file rm -f "$TMP_KEY" return 0 } # Begin Patch Process echo -e "\e[92mBegining sdxpinn-patch process...\e[0m" echo -e "\e[92mEnsuring distfeeds is clean of any non-working sources and has stock OpenWRT ones...\e[0m" clean_distfeeds echo -e "\e[92mEnsuring iamromulan's SDXPINN repo is listed in customfeeds and public key is installed...\e[0m" repo_iamromulanSDXPINN_check echo -e "\e[92miamromulan's SDXPINN repo source and key is installed.\e[0m" echo -e "\e[92msdxpinn-patch process complete.\e[0m" exit 0