3 ## Mock builtin utilities
4 # These should preempt builtin programs.
5 # They should print expected output on STDOUT, and write given arguments to
6 # mock_<name>_flags. Be sure to overwrite this file, not append! If they need
7 # to act differently depending on a condition, use temp files in $MOCKDIR, and
8 # delete when you're done. (Solaris shell does not re-export environment
9 # variables correctly).
11 MOCKDIR=$TMPDIR/mocks; export MOCKDIR
12 [ -d $MOCKDIR ] || mkdir $MOCKDIR
13 PATH=${MOCKDIR}:$PATH; export PATH
17 if [ ! "$IAmRoot" ]; then
18 # The repetitive stuff
19 cat << EOF > "$MOCKDIR/$1"
22 /bin/chmod u+x $MOCKDIR/$1
26 # Dynamic var names are ugly in shell, but useful.
27 eval mock_$1_flags=\$MOCKDIR/mock_\$1_flags
28 eval export mock_$1_flags
29 # Append to the list of flag files
30 mock_flag_files="$mock_flag_files mock_$1_flags"
36 cat << EOF >> "${MOCKDIR}/ps"
37 echo "ps args: \${@}" > $mock_ps_flags
38 if [ -f "${MOCKDIR}/running" ]; then
39 ps_list="inetd xinetd launchd"
44 echo "faux process list: \$ps_list"
50 cat << EOF >> "${MOCKDIR}/chown"
51 echo "chown args: \${@}" > $mock_chown_flags
57 cat << EOF >> "${MOCKDIR}/chmod"
58 echo "chmod args: \${@}" > $mock_chmod_flags
64 # Set defaults for deb_uid and amanda_group, if running outside test_sh_libs
65 deb_uid=${deb_uid:=12345}
66 amanda_group=${amanda_group:=disk}
69 cat << EOF >> "${MOCKDIR}/id"
70 echo "id args: \${1}" > $mock_id_flags
71 [ -n "\${1}" ] || { echo "Missing a username to id!"; exit 1; }
73 # We have to return the most basic form of id to be portable
74 # group file is used for supplemental groups.
75 if [ -f "${MOCKDIR}/is_member" ]; then
76 echo "uid=${deb_uid}(\${1}) gid=6(${amanda_group})"
78 echo "uid=123(\${1}) gid=123(foobar)"
85 cat << EOF >> "${MOCKDIR}/svcs"
86 echo "svcs args: \${@}" > $mock_svcs_flags
87 if [ -f "${MOCKDIR}/prexisting_service" ]; then
88 echo "online Sep_09 svc:/network/amanda/tcp:default"
90 echo "Pattern '\${3}' doesn't match any instances"
96 # xinetd init script replacement
98 cat << EOF >> "${MOCKDIR}/xinetd"
99 echo "xinetd args: \${1}" > $mock_xinetd_flags
100 [ -f ${MOCKDIR}/success ] && exit 0
101 echo "xinetd did not \${1}"
106 # inetd init script replacement
108 cat << EOF >> "${MOCKDIR}/inetd"
109 echo "inetd args: \${1}" > $mock_inetd_flags
110 [ -f ${MOCKDIR}/success ] && exit 0
111 echo "inetd did not \${1}"
116 # install replacement
118 cat << EOF >> "${MOCKDIR}/install"
119 echo "install args: \$@" > $mock_install_flags
120 [ -f ${MOCKDIR}/success ] && exit 0
121 echo "Some funky install error, yo!"
125 # TODO: inetconv inetadm, svcadm
127 # Touch all the flag files
128 for file in $mock_flag_files; do