ret=0
unit=$1
journalctl -qn2 -f -u $unit &
- systemctl start $unit
sleep 2
- kill $jr_pid &>/dev/null ||:
- unset jr_pid
- fg &>/dev/null ||:
+ systemctl start $unit
}
sm() { # switch mail host
mns-setup $ns
pid=$(servicepid $unit)
- # i can't remember the exact reason i started exporting, but it does keep the
- # environment vars perfectly accurate, whereas sudo -E does not quite. Although,
- # we could just set those explicity, PATH is the main one. It also
- # seems less secure since another process could modify the temp file.
- tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
- export -p >$tmpf
- printf "%s " "${@@Q}" >>$tmpf
- echo >>$tmpf
- echo "rm -f $tmpf" >>$tmpf
+ env-tmpf "$@"
m sudo nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $USER -i bash -c ". $tmpf"
}
unit=$1
shift
pid=$(servicepid $unit)
- tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
- export -p >$tmpf
- printf "%s " "${@@Q}" >>$tmpf
- echo >>$tmpf
- echo "rm -f $tmpf" >>$tmpf
+ env-tmpf "$@"
m sudo nsenter -t $pid -n -m sudo -u $USER -i bash -c ". $tmpf"
}
m sudo nsenter -t $pid -n -m "$@"
}
+## create tempfile script which runs command under same env then deletes itself.
+# background: i can't remember the exact reason i started exporting, but it does keep the
+# environment vars perfectly accurate, whereas sudo -E does not quite. Although,
+# we could just set those explicity, PATH is the main one. It also
+# seems less secure since another process could modify the temp file.
+env-tmpf() {
+ tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
+ {
+ export -p
+ printf "%s " "${@@Q}"
+ echo
+ echo "rm -f $tmpf"
+ } >$tmpf
+}
# systemd network namespace (not mount) cmd
# usage: UNIT CMD...
unit=$1
shift
pid=$(servicepid $unit)
- tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX)
- export -p >$tmpf
- printf "%s " "${@@Q}" >>$tmpf
- echo >>$tmpf
- echo "rm -f $tmpf" >>$tmpf
+ env-tmpf "$@"
m sudo nsenter -t $pid -n sudo -u $USER -i bash -c ". $tmpf"
}
}
spdfx() {
- local spd_file
spdx -f ~/.spd/spd/spd_data_financial.gpg "$@"
}
printf "%s\n" "$*"
fi
}
+append-status-file() {
+ if $verbose; then
+ tee -a $status_file
+ else
+ >>$status_file
+ fi
+}
p() { printf "%s\n" "$*"; }
# log-once COUNT NAME [MESSAGE]
lo() {
p "$snapshotmsg" | loday -1 old-snapshot
fi
# not bothering to get info on all volumes if we find an old one.
- else
- echo | loday -1 old-snapshot
+ else
+ echo | loday -1 old-snapshot
fi
fi
fi
if [[ ${chars[*]} ]]; then
- echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file
+ echo "ps_char=\"${chars[*]} \$ps_char\"" | append-status-file
fi
fi
write-status
if [[ $1 ]]; then
- cat $status_file
exit 0
fi