blob: 82e79d8824a3400591352a9b2aa44e5aeea2595c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/bin/sh
. samizdat-paths.sh
error()
{
printf 'Error: %s\n' "${*:-command failed}" >&2
exit 1
}
warning()
{
printf 'Warning: %s\n' "${*:-something went wrong}" >&2
}
store_tmpfs()
{
local dir="$1"
mountpoint -q "$dir" || return 0
[ ! -d "$dir".backup ] || error "existing child backup found: '$dir.backup'. Refusing to continue."
cp -a "$dir" "$dir".backup || error "failed to make copy of child."
umount "$dir" || error "failed to unmount child tmpfs"
rmdir "$dir" || mv -Tb "$dir" "$dir".unlikely
mv -T "$dir".backup "$dir" || error "failed to move copied child dir into place. Child will not function!"
}
assert_root()
{
[ "$(id -u)" = 0 ] || error "you are not root"
}
main()
{
assert_root
child=$1
[ "$child" ] || usage
if [ -d "$samizdat_child_dir"/child."$child" ]; then
store_tmpfs "$samizdat_child_dir"/child."$child"
else
error "not a directory: $samizdat_child_dir/child.$child"
fi
}
case $# in
0) read child < reused-child && main "$child" ;;
*) main "$@" ;;
esac
|