Skip to content

Instantly share code, notes, and snippets.

@5p0ng3b0b
Last active March 5, 2025 01:57
Show Gist options
  • Save 5p0ng3b0b/5270af63dd7556e12cf4a91020f3cbd8 to your computer and use it in GitHub Desktop.
Save 5p0ng3b0b/5270af63dd7556e12cf4a91020f3cbd8 to your computer and use it in GitHub Desktop.
Script to generate a uci defaults file from an openwrt router. For use in custom firmwares using imagebuilder.
#!/bin/sh
# Create OpenWRT uci-defaults file for image builder
target=$(sed -n 1p /etc/opkg/distfeeds.conf | cut -d'/' -f8)
soc=$(sed -n 1p /etc/opkg/distfeeds.conf | cut -d'/' -f9)
arch=$(sed -n 2p /etc/opkg/distfeeds.conf | cut -d'/' -f8)
model=$(cat /tmp/sysinfo/model)
profile=$(cat /tmp/sysinfo/board_name | sed 's/,/_/')
script="/tmp/99-custom"
echo ----------------------------------------------------
echo Generating custom default file for $model
echo ----------------------------------------------------
echo "profile = $profile"
echo "target = $target"
echo "soc = $soc"
echo "arch = $arch"
echo "#!/bin/sh">"$script"
echo "#$model custom default settings">>"$script"
echo "uci -q batch << EOI" >> "$script"
for section in $(uci show 2>/dev/null | awk -F. '{print $1}' | sort -u); do
uci show "$section" | awk -F. '{print "set "$0}' >> "$script"
echo "commit $section" >> "$script"
done
echo "EOI" >> "$script"
chmod 755 "$script"
echo "Created $script".
echo Now transfer the file to the 'files/etc/uci-defaults/' folder in your image builder directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment