-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsackman.sh
executable file
·67 lines (48 loc) · 1.63 KB
/
sackman.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
export SACKMAN_PREFIX="$( dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" )"
source $SACKMAN_PREFIX/lib/sackman/util.sh
usage() {
cat <<EOF >/dev/stderr
usage: $(basename "$0") run [flags] IMAGE [COMMAND [ARG...]]"
NOTE: For options that appear prior to the image name:
Do not put a space in front of option-values.
Use --option-name=VALUE or -oVALUE instead.
Otherwise sackman may not identify the image name correctly.
EOF
exit 1
}
[[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]] && usage
SACKMAN_MOUNT=$SACKMAN_PREFIX/lib/sackman/fuse-overlayfs.sh
SACKMAN_RSYNC=$SACKMAN_PREFIX/lib/sackman/rsync.sh
if [[ -n "$FILE_LOG" ]]
then
export SACKMAN_OUTFILE="$(realpath "$FILE_LOG")"
else
export SACKMAN_OUTFILE="/tmp/sackman.$USER.$$"
fi
for arg in "$@"
do
[[ "$arg" =~ ^- ]] || {
if [[ -z "$cmd" ]]
then
cmd="$arg"
else
SRC_IMAGE="$arg"
break
fi
}
done
[[ "$cmd" == "run" ]] || error "Invalid command \"$cmd\"."
[[ -n "$SRC_IMAGE" ]] || error "Could not find image name in command."
call podman \
--storage-driver overlay \
--storage-opt "overlay.mount_program=$SACKMAN_MOUNT" \
"$@"
[[ -z "$DST_IMAGE" ]] && read -p "Enter the new image name: " DST_IMAGE
export SRC_CONT=$(call buildah from "$SRC_IMAGE") || exit
export DST_CONT=$(call buildah from scratch) || exit
call buildah unshare $SACKMAN_RSYNC || exit
call buildah rm $SRC_CONT || exit
call buildah commit --squash $DST_CONT "$DST_IMAGE" || exit
call buildah rm $DST_CONT
[[ -z "$FILE_LOG" ]] && call rm $SACKMAN_OUTFILE || exit