Skip to content

Instantly share code, notes, and snippets.

@notyal
Created May 7, 2020 02:47
Show Gist options
  • Save notyal/77cca232b501cdc449b924cc93b37ac5 to your computer and use it in GitHub Desktop.
Save notyal/77cca232b501cdc449b924cc93b37ac5 to your computer and use it in GitHub Desktop.
add additional packages from a list to openwrt .config
#!/bin/bash
# add additional packages from a list to openwrt .config
# its a good idea to run `make defconfig` afterwards
file="$1"
config="$2"
_testexist(){
# _testexist [file path] [type of file]
path="$1"
filetype="$2"
if [[ ! -f "$path" ]]; then
echo "ERROR: Cannot access $filetype \`$path'"
echo
echo "USAGE: $0 [packages] [config]"
exit 1
fi
}
_testexist "$file" "packages"
_testexist "$config" "config"
cp -v "$config" "${config}.bak"
while IFS= read line; do
package="CONFIG_PACKAGE_$line"
notSet="# $package is not set"
setYes="${package}=y"
if [[ ! -z $(grep "$notSet" "$config") ]]; then
echo -e "[+] Setting =y for :\t$package"
sed -i -e "s/$notSet/$setYes/g" "$config"
elif [[ ! -z $(grep "$setYes" "$config") ]]; then
echo -e "[=] Already set for:\t$package"
else
echo -e "[!] Did not find :\t$package"
fi
done <"$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment