代码之家  ›  专栏  ›  技术社区  ›  tgogos

uci-如何恢复所有未老化的更改

  •  3
  • tgogos  · 技术社区  · 7 年前

    uci

    uci set ", " uci add uci rename “和” uci delete “命令暂存到临时位置,并立即写入flash” uci commit ".

    如果我答对了,您首先运行一些与上述命令类似的命令,并将更改写入您运行的配置文件 uci提交 例如,假设我做了以下更改。。。

    root@OpenWrt:~# uci changes
    network.vlan15.ifname='eth1.15'
    network.vlan15.type='bridge'
    network.vlan15.proto='static'
    network.vlan15.netmask='255.255.255.0'
    network.vlan15.ipaddr='192.168.10.0'
    

    5 回复  |  直到 7 年前
        1
  •  4
  •   Mischa Diehm    5 年前

    root@firlefanz:~# rm -rf /tmp/.uci/
    
        2
  •  3
  •   Clèm    3 年前

    revert  <config>[.<section>[.<option>]]     Revert the given option, section or configuration file.
    

    所以,在你的情况下,它应该是

    uci revert network.vlan15
    

    看见 https://openwrt.org/docs/guide-user/base-system/uci

        3
  •  2
  •   ogelpre    3 年前

    uci changes | sed -rn 's%^[+-]?([^=+-]*)([+-]?=.*|)$%\1%' | xargs -n 1 uci revert
    

    tl;dr sed命令从阶段性更改中提取选项名称。xargs命令对每个提取的选项执行revert命令。

    现在,让我们深入了解每件事:

    uci changes 打印准备好的更改,然后通过管道传输到sed命令。

    sed opton -r -n 抑制图案匹配的自动打印。

    s 用于执行搜索和替换,以及 % 用作搜索和替换项的分隔字符。

    uci变更行有不同的格式。

    - . 添加的配置选项前缀为 +

    匹配前缀 [+-]? 已使用。问号表示方括号中的一个字符可以进行可选匹配。

    选项名称将与图案匹配 [^=+-]* 。只要该字符不是以下字符之一,则该正则表达式具有任意数量字符的含义: =+- .

    第二部分是简单的一部分,意味着没有字符。删除uci选项时会发生这种情况。 = 可以用可选的前缀 + - .之后 可以是由表示的一个或多个字符 .* =<value> 指示该值从列表中删除或添加到列表中(如果选项是列表)。

    \1 换句话说:只打印选项名称。

    -n 1 xargs execuse uci revert <option_name> 对于每个 option_name 通过sed发送。

    以下是不同格式的 uci变更 输出:

    -a
    +b='create new option with this value'
    c='change an existing option to this value'
    d+='appended to list'
    e-='removed from list'
    

    a
    b
    c
    d
    e
    

    xargs -n 1 然后将执行以下命令:

    uci revert a
    uci revert b
    uci revert c
    uci revert d
    uci revert e
    

    这就是“一行”的全部魅力所在。

        4
  •  1
  •   igal    7 年前

    uci uci changes 命令与一些shell脚本一起使用,以实现所需的结果。下面是一个示例脚本:

    #!/bin/ash
    
    # uci-revert-all.sh
    # Revert all uncommitted uci changes
    
    # Iterate over changed settings
    # Each line has the form of an equation, e.g. parameter=value
    for setting in $(uci changes); do
    
        # Extract parameter from equation
        parameter=$(echo ${setting} | grep -o '^\(\w\|[._-]\)\+')
    
        # Display a status message
        echo "Reverting: ${parameter}"
    
        # Revert the setting for the given parameter
        uci revert "${parameter}"
    done
    

    一个更简单的选择可能是使用 uci revert <config>

    #!/bin/ash
    
    # uci-revert-all.sh
    # Revert all uncommitted uci changes
    
    for config in /etc/config/*; do
        uci revert $(basename ${config})
    done
    

        5
  •  0
  •   jaimet    2 年前

    这是另一个简短的一行回复

    for i in /etc/config/* ; do uci revert ${i##*/} ; done
    

    (仅供参考,本使用 posix parameter expansion 的“删除最大前缀模式”。)