Changeset 14833


Ignorieren:
Zeitstempel:
22.08.2018 23:18:43 (vor 5 Wochen)
Autor:
er13
Nachricht:

rewrite "enforce urlader settings"-patch

Datei:
1 bearbeitet

Legende:

Unverändert
Hinzugefügt
Entfernt
  • trunk/patches/scripts/101-enforce_urlader-settings.sh

    r14830 r14833  
    1 if [ "$FREETZ_ENFORCE_URLADER_SETTINGS" = y ]; then 
    2     echo1 "enforce urlader settings" 
     1define_urlader_funcs() { 
     2cat <<- 'EOF' 
     3    # urlader functions 
     4    get_urlader_var() { 
     5      sed -n -e "s/^$1[ \t]\+\(.*\)\$/\1/p" /proc/sys/urlader/environment 
     6    } 
     7    set_urlader_var() { 
     8      [ "$(get_urlader_var $1)" != "$2" ] && echo "$1 $2" >/proc/sys/urlader/environment 
     9    } 
     10EOF 
     11} 
    312 
    4     mv "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S.orig" 
     13set_desired_urlader_vars() { 
     14local urlader_var freetz_config_var 
     15for urlader_var in firmware_version my_ipaddress ProductID; do 
     16    freetz_config_var="FREETZ_ENFORCE_URLADER_SETTING_${urlader_var^^}" 
     17    if [ -n "${!freetz_config_var}" ]; then 
     18        cat <<- EOF 
     19        set_urlader_var "${urlader_var}" "${!freetz_config_var}" 
     20        EOF 
     21    fi 
     22done 
     23} 
    524 
    6     cat > "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" << EOF 
    7 #!/bin/sh 
    8 mount -t proc proc /proc 
     25mount_proc() { 
     26cat <<- 'EOF' 
     27    mount -t proc proc /proc 
    928EOF 
     29} 
    1030 
    11     if [ -n "$FREETZ_ENFORCE_URLADER_SETTING_FIRMWARE_VERSION" ]; then 
    12         echo 'firmware_version="$(echo $(grep firmware_version /proc/sys/urlader/environment) | cut -d'"' '"' -f2)"' 
    13         echo 'if [ "$firmware_version" != "'$FREETZ_ENFORCE_URLADER_SETTING_FIRMWARE_VERSION'" ]; then' 
    14         echo 'echo firmware_version '$FREETZ_ENFORCE_URLADER_SETTING_FIRMWARE_VERSION' > /proc/sys/urlader/environment' 
    15 #       echo 'echo '$FREETZ_ENFORCE_URLADER_SETTING_FIRMWARE_VERSION' > /proc/sys/urlader/firmware_version' 
    16         echo 'fi' 
    17     fi >> "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" 
    18     if [ -n "$FREETZ_ENFORCE_URLADER_SETTING_MY_IPADDRESS" ]; then 
    19         echo 'my_ipaddress="$(echo $(grep my_ipaddress /proc/sys/urlader/environment) | cut -d'"' '"' -f2)"' 
    20         echo '[ "$my_ipaddress" = '$FREETZ_ENFORCE_URLADER_SETTING_MY_IPADDRESS' ] || echo my_ipaddress '$FREETZ_ENFORCE_URLADER_SETTING_MY_IPADDRESS' > /proc/sys/urlader/environment' 
    21     fi >> "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" 
    22     if [ -n "$FREETZ_ENFORCE_URLADER_SETTING_PRODUCTID" ]; then 
    23         echo 'ProductID="$(echo $(grep ProductID /proc/sys/urlader/environment) | cut -d'"' '"' -f2)"' 
    24         echo '[ "$ProductID" = '$FREETZ_ENFORCE_URLADER_SETTING_PRODUCTID' ] || echo ProductID '$FREETZ_ENFORCE_URLADER_SETTING_PRODUCTID' > /proc/sys/urlader/environment' 
    25     fi >> "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" 
     31umount_proc() { 
     32cat <<- 'EOF' 
     33    umount /proc 
     34EOF 
     35} 
    2636 
    27     cat >> "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" << EOF 
    28 umount /proc 
    29 EOF 
    30     cat "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S.orig" >> "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" 
    31     rm -f "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S.orig" 
    32     chmod 755 "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" 
    33 fi 
     37[ "$FREETZ_ENFORCE_URLADER_SETTINGS" = y -a -n "$(set_desired_urlader_vars)" ] || return 0 
     38 
     39echo1 "enforce urlader settings" 
     40 
     41{ 
     42    rc_S="${FILESYSTEM_MOD_DIR}/etc/init.d/rc.S" 
     43 
     44    { 
     45        echo 
     46        echo "# override urlader variables" 
     47        echo "$(set_desired_urlader_vars)" 
     48        echo 
     49    } > "${rc_S}.urlader_vars" 
     50 
     51    { 
     52        # copy the 1st line (according to the standard must be a shebang line) 
     53        sed -n -e '1p' "${rc_S}" 
     54 
     55        # add the definitions of the urlader getter/setter funcs 
     56        echo 
     57        echo "$(define_urlader_funcs)" 
     58        echo 
     59 
     60        # add mount/umount lines if rc.S doesn't contain 
     61        # the "mount -t proc ..." line yet 
     62        if ! grep -q "^$(mount_proc)$" "${rc_S}" >/dev/null 2>&1; then 
     63            echo "$(mount_proc)" 
     64            echo "$(umount_proc)" 
     65        fi 
     66 
     67        # copy all lines starting from the 2nd one, i.e. except for the 1st one 
     68        sed -e '1d' "${rc_S}" 
     69    } | { 
     70        # append "set_urlader_var"-calls after the "mount -t proc ..." line 
     71        sed -e '\#'^"$(mount_proc)"'$# r '"${rc_S}.urlader_vars" 
     72    } > "${rc_S}.modified" 
     73 
     74    rm -f "${rc_S}.urlader_vars" 
     75} 
     76 
     77chmod 755 "${rc_S}.modified" 
     78mv "${rc_S}.modified" "${rc_S}" 
Hinweis: Hilfe zur Verwendung der Changeset-Ansicht finden Sie unter TracChangeset.