File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/ucf_helper_functions.zip
Back
PK ��Z�� tests/test_14nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR mv $PKGF $PKGRF echo "this is a locally changed file" > $LOCF take_ref echo "rename_ucf_file" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files" handle_all_ucf_files $PKGDIR $LOCDIR is_local $LOCRF && check_ucfq_number 1 return $? PK ��Z��Z! tests/test_15nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR mv $PKGF $PKGRF rm -f $LOCF take_ref echo "rename_ucf_file" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files" handle_all_ucf_files $PKGDIR $LOCDIR is_deleted $LOCF && is_deleted $LOCRF && check_ucfq_number 1 return $? PK ��Z{5�_� � tests/test_06nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGF echo "this is a locally changed file" > $LOCF take_ref export UCF_FORCE_CONFFNEW=1 handle_all_ucf_files $PKGDIR $LOCDIR is_package $LOCF && check_ucfq_number 1 return $? PK ��ZC��� � tests/test_17nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGRF rm -f $PKGF echo "this is a locally changed file" > $LOCF take_ref echo "rename_ucf_file $LOCF $LOCRF" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files $PKGDIR $LOCDIR" export UCF_FORCE_CONFFOLD=1 handle_all_ucf_files $PKGDIR $LOCDIR echo "final check" is_local $LOCRF && check_ucfq_number 1 return $? PK ��Zac� � tests/test_02nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR echo "this is a locally changed file" > $LOCF take_ref handle_all_ucf_files $PKGDIR $LOCDIR is_local $LOCF && check_ucfq_number 1 return $? PK ��Z�m�� � tests/test_08nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGF rm -f $LOCF take_ref export UCF_FORCE_CONFFNEW=1 handle_all_ucf_files $PKGDIR $LOCDIR is_package $LOCF && check_ucfq_number 1 return $? PK ��Z/zx�P P tests/test_12nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR rm -f $PKGF rm -f $LOCF take_ref # the current code causes the deleted/deleted case to emit a ucf prompt # we can live with that since both choices yield the same result export UCF_FORCE_CONFFOLD=1 handle_all_ucf_files $PKGDIR $LOCDIR is_deleted $LOCF && check_ucfq_number 0 return $? PK ��Z��C� � tests/test_10nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR rm -f $PKGF echo "this is a locally changed file" > $LOCF take_ref export UCF_FORCE_CONFFOLD=1 handle_all_ucf_files $PKGDIR $LOCDIR is_local $LOCF && check_ucfq_number 0 return $? PK ��ZJ�'ɟ � tests/test_09nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR rm -f $PKGF take_ref handle_all_ucf_files $PKGDIR $LOCDIR is_deleted $LOCF && check_ucfq_number 0 return $? PK ��Z��p� � tests/test_04nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGF take_ref handle_all_ucf_files $PKGDIR $LOCDIR is_package $LOCF && check_ucfq_number 1 return $? PK ��Zy��z� � tests/test_05nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGF echo "this is a locally changed file" > $LOCF take_ref export UCF_FORCE_CONFFOLD=1 handle_all_ucf_files $PKGDIR $LOCDIR is_local $LOCF && check_ucfq_number 1 return $? PK ��Z�F �� � tests/test_07nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGF rm -f $LOCF take_ref export UCF_FORCE_CONFFOLD=1 handle_all_ucf_files $PKGDIR $LOCDIR is_deleted $LOCF && check_ucfq_number 1 return $? PK ��Z�;p�� � tests/test_03nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR rm -f $LOCF take_ref handle_all_ucf_files $PKGDIR $LOCDIR is_deleted $LOCF && check_ucfq_number 1 return $? PK ��Z�݀� � tests/test_13nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR mv $PKGF $PKGRF take_ref rename_ucf_file $LOCF $LOCRF handle_all_ucf_files $PKGDIR $LOCDIR is_local $LOCRF && check_ucfq_number 1 return $? PK ��Za�� � tests/test_18nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGRF rm -f $PKGF echo "this is a locally changed file" > $LOCF take_ref echo "rename_ucf_file $LOCF $LOCRF" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files $PKGDIR $LOCDIR" export UCF_FORCE_CONFFNEW=1 handle_all_ucf_files $PKGDIR $LOCDIR echo "final check" is_package $LOCRF $PKGRREF && check_ucfq_number 1 return $? PK ��ZVր�� � tests/test_11nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR rm -f $PKGF echo "this is a locally changed file" > $LOCF take_ref export UCF_FORCE_CONFFNEW=1 handle_all_ucf_files $PKGDIR $LOCDIR is_deleted $LOCF && check_ucfq_number 0 return $? PK ��Z�K�+ + tests/package-orignu �[��� this is the original file from the package PK ��Z�� B B tests/test_16nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGRF rm -f $PKGF take_ref echo "rename_ucf_file $LOCF $LOCRF" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files $PKGDIR $LOCDIR" handle_all_ucf_files $PKGDIR $LOCDIR echo "final check" is_package $LOCRF $PKGRREF && check_ucfq_number 1 return $? PK ��ZT���* * tests/package-changednu �[��� this is the changed file from the package PK ��Z~��� � tests/test_01nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR take_ref handle_all_ucf_files $PKGDIR $LOCDIR is_local $LOCF && check_ucfq_number 1 return $? PK ��Z�Y�Du u tests/test_19nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGRF rm -f $PKGF rm -f $LOCF take_ref echo "rename_ucf_file $LOCF $LOCRF" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files $PKGDIR $LOCDIR" export UCF_FORCE_CONFFOLD=1 handle_all_ucf_files $PKGDIR $LOCDIR echo "final check" is_deleted $LOCRF && is_deleted $LOCF && check_ucfq_number 1 return $? PK ��Z�blWj j tests/test_20nu ȯ�� #!/bin/bash handle_all_ucf_files $PKGDIR $LOCDIR cp package-changed $PKGRF rm -f $PKGF rm -f $LOCF take_ref echo "rename_ucf_file $LOCF $LOCRF" rename_ucf_file $LOCF $LOCRF echo "handle_all_ucf_files $PKGDIR $LOCDIR" export UCF_FORCE_CONFFNEW=1 handle_all_ucf_files $PKGDIR $LOCDIR echo "final check" is_package $LOCRF $PKGRREF && check_ucfq_number 1 return $? PK ��Z\�� � 00READMEnu �[��� ucf_helper_functions ==================== This directory contains a suggestion for code to help using ucf covering most of the real-life use cases. This code is in use since many months in the aide package and seems to work "well enough". See aide-common's maintainer scripts for usage examples. The package ships the current version of all config files in /usr/share/aide-common/config, and handles all of them in a single call of handle_all_ucf_files /usr/share/aide-common/config /etc. The code expects that the first parameter of handle_all_ucf_files is a pointer to the directory structure, and handle_all_ucf_files rebuilds that structure in the target directory. See the aide-common package for reference. This directory also contains a test suite so that the correct behavior of the function can be verified. Call ./testsuite as root. Sorry, the test suite needs root privileges and uses the ucf database of the host system. The test cases are kind of documented in the test-list file. PK ��Z�=PG� � test-listnu �[��� number op packagefile localfile ucfr UCF_FORCE_ expected result 1 update unchanged unchanged 1 local 2 update unchanged changed 1 local 3 update unchanged deleted 1 deleted 4 update changed unchanged 1 package 5 update changed changed 1 CONFFOLD local 6 update changed changed 1 CONFFNEW package 7 update changed deleted 1 CONFFOLD deleted 8 update changed deleted 1 CONFFNEW package 9 update deleted unchanged 0 deleted 10 update deleted changed 0 CONFFOLD local 11 update deleted changed 0 CONFFNEW deleted 12 update deleted deleted 0 (*) deleted 13 rename unchanged unchanged 1 newname 14 rename unchanged changed 1 changed newname 15 rename unchanged deleted 1 oldname and newname deleted 16 rename changed unchanged 1 package newname 17 rename changed changed 1 CONFFOLD local 18 rename changed changed 1 CONFFNEW package 19 rename changed deleted 1 local 20 rename changed deleted 1 package the column ucfr says how many files should be registered (check_ucfq_number) after the second ucf run. Tests do also check this. (*) the second ucf call causes a question to be asked while that it not strictly necessary. Since both options yield the same result, and this is an exotic corner case, we can live with that. PK ��Z�2 testsuitenu ȯ�� #!/bin/bash if [ "$(id -u)" -ne 0 ]; then echo >&2 "ERR: root needed" exit 1 fi set -u set -e DIR="$(pwd)/workdir" PKGDIR="$DIR/pkg" LOCDIR="$DIR/loc" PKGNAME="pkgname" PKGF="$PKGDIR/conffile" LOCF="$LOCDIR/conffile" PKGRF="$PKGDIR/renamedconffile" LOCRF="$LOCDIR/renamedconffile" REFDIR="reference" PKGREF="$REFDIR/pkg" LOCREF="$REFDIR/loc" PKGRREF="$REFDIR/renamedpkg" LOCRREF="$REFDIR/renamedloc" LOCNEWF="$DIR/localnewfile" TESTEE="ucf-helper-functions.sh" if [ -x "./$TESTEE" ]; then . ./$TESTEE fi cd tests cleanup() { for fn in $LOCF $LOCNEWF $LOCRF; do ucf --purge $fn ucfr --purge $PKGNAME $fn done rm -rf $DIR $PKGDIR $LOCDIR $REFDIR rm -f result } prepare() { cleanup mkdir $DIR $PKGDIR $LOCDIR $REFDIR cp package-orig $PKGF } take_ref() { if [ -e "$PKGF" ]; then cp $PKGF $PKGREF else touch $PKGREF-deleted fi if [ -e "$LOCF" ]; then cp $LOCF $LOCREF else touch $LOCREF-deleted fi if [ -e "$PKGRF" ]; then cp $PKGRF $PKGRREF else touch $PKGRREF-deleted fi if [ -e "$LOCRF" ]; then cp $LOCRF $LOCRREF else touch $LOCRREF-deleted fi } check_ucfq_number() { EXPECTED="$1" if [ $(ucfq --with-colons $PKGNAME | wc -l) != "$EXPECTED" ]; then echo >&2 "number of files registered to $PKGNAME not equal $EXPECTED, test failed" ucfq --with-colons $PKGNAME | wc -l ucfq $PKGNAME return 1 else echo >&2 "$EXPECTED file(s) registered to $PKGNAME, test passed" return 0 fi } is_package() { local LOCF local REFF LOCF=$1 REFF=${2:-$PKGREF} if ! cmp $LOCF $REFF; then echo >&2 "$LOCF not equal $REFF, test failed" return 1 else echo >&2 "$LOCF equals $REFF, test passed" return 0 fi } is_local() { local LOCF local REFF LOCF=$1 REFF="${2:-$LOCREF}" if ! cmp $LOCF $REFF; then echo >&2 "$LOCF not equal $REFF, test failed" return 1 else echo >&2 "$LOCF equals $REFF, test passed" return 0 fi } is_deleted() { RET=0 FN="$1" if [ -e "$FN" ]; then echo >&2 "$FN does still exist, test failed" RET=1 else echo >&2 "$FN is deleted, test passed" fi return $RET } print_state() { printf -- "------- %s\n" "${1:-}" echo "ls -alR $DIR" ls -alR $DIR head -n-0 /dev/null $DIR/*/* printf "ucfq $PKGNAME knows about %d files\n" "$(ucfq --with-colons "$PKGNAME" | wc -l)" ucfq --with-colons "$PKGNAME" } DEBIAN_FRONTEND=readline GLOB="${1:-*}" for test in ./test_$GLOB; do prepare RET=0 unset UCF_FORCE_CONFFOLD export -n UCF_FORCE_CONFFOLOLD unset UCF_FORCE_CONFFNEW export -n UCF_FORCE_CONFFNEW . $test || RET=$? if [ "$RET" -ne 0 ]; then echo "$test failed" print_state "$test failed" cleanup exit 1 else echo "$test passed" fi cleanup done # vim:sw=4:sts=4:et: PK ��Z_f�6K K TODOnu �[��� - make testsuite run without root - do not use ucf database of host system PK ��Z�� tests/test_14nu ȯ�� PK ��Z��Z! ] tests/test_15nu ȯ�� PK ��Z{5�_� � � tests/test_06nu ȯ�� PK ��ZC��� � � tests/test_17nu ȯ�� PK ��Zac� � � tests/test_02nu ȯ�� PK ��Z�m�� � � tests/test_08nu ȯ�� PK ��Z/zx�P P � tests/test_12nu ȯ�� PK ��Z��C� � 9 tests/test_10nu ȯ�� PK ��ZJ�'ɟ � ] tests/test_09nu ȯ�� PK ��Z��p� � 9 tests/test_04nu ȯ�� PK ��Zy��z� � " tests/test_05nu ȯ�� PK ��Z�F �� � S tests/test_07nu ȯ�� PK ��Z�;p�� � d tests/test_03nu ȯ�� PK ��Z�݀� � @ tests/test_13nu ȯ�� PK ��Za�� � < tests/test_18nu ȯ�� PK ��ZVր�� � tests/test_11nu ȯ�� PK ��Z�K�+ + + tests/package-orignu �[��� PK ��Z�� B B � tests/test_16nu ȯ�� PK ��ZT���* * tests/package-changednu �[��� PK ��Z~��� � � tests/test_01nu ȯ�� PK ��Z�Y�Du u T tests/test_19nu ȯ�� PK ��Z�blWj j tests/test_20nu ȯ�� PK ��Z\�� � � 00READMEnu �[��� PK ��Z�=PG� � � test-listnu �[��� PK ��Z�2 �"