OpenWRTでuciコマンドを使用してすべての設定オプションを取得する方法

OpenWRTでuciコマンドを使用してすべての設定オプションを取得する方法

uciOpenWRTを実行するルーターを構成していますが、コマンド(統合構成インターフェース)を使用して既存の構成ファイルを確認する方法を理解するのに問題があります。シェルスクリプトでこの設定を自動化したいと思います。

ファイアウォール構成を例にとると、/etc/config/firewall長さは195なのでcat

いくつかのルールがあります。最初のルールを使用してください。

root@OpenWrt:/etc/config# grep -B1 -A6 'Allow-DHCP-Renew' /etc/config/firewall
config rule
    option name     Allow-DHCP-Renew
    option src      wan
    option proto        udp
    option dest_port    68
    option target       ACCEPT
    option family       ipv4

root@OpenWrt:/etc/config# 

@rule[0]次のように、最初のルール()の個々のフィールドを確認できますname

root@OpenWrt:/etc/config# uci get firewall.@rule[0].name
Allow-DHCP-Renew
root@OpenWrt:/etc/config# 

しかし、ルール全体を出力として見ることはできません。試してみましたが、uci get firewall.@rule[0].*正しい構文ではありません。

uci( )に関するマニュアルがないので、man uciこのコマンドをどのように使用するかについての情報がどこにあるのかわかりません。

このような「集団買収」は可能ですか?

ベストアンサー1

デバイスのすべての現在の設定を使用してOpenWRTを設定するスクリプトを生成したい場合。

#!/bin/sh
# Create OpenWRT setup script
script="/tmp/uci_setup_script.sh"
echo "#!/bin/sh" > "$script"
echo "uci -q batch << EOI" >> "$script"
for section in $(uci show | 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"

カスタムファームウェアにImage Builderを使用している場合は、files/etc/uci-defaultsImage Builderディレクトリにフォルダのファイルを作成します。

#!/bin/sh
# Create OpenWRT uci-defaults file for image builder
# copy generated file to 'files/etc/uci-defaults/' folder in your image builder directory
script="/tmp/99-custom"
echo "#!/bin/sh" > "$script"
echo "uci -q batch << EOI" >> "$script"
for section in $(uci show | awk -F. '{print $1}' | sort -u); do
uci show "$section" | awk -F. '{print "set "$0}' >> "$script"
echo "commit $section" >> "$script"
echo "EOI" >> "$script"
chmod 755 "$script"
done

おすすめ記事