|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 |
|
| 4 | + |
| 5 | +echo "determining container command." |
4 | 6 | if [ -z "${CONTAINER_CMD}" ]; then
|
5 |
| - CONTAINER_CMD=$(command -v docker || echo "") |
| 7 | + CONTAINER_CMD=$(command -v docker || echo ) |
6 | 8 | fi
|
7 | 9 | if [ -z "${CONTAINER_CMD}" ]; then
|
8 |
| - CONTAINER_CMD=$(command -v podman || echo "") |
| 10 | + CONTAINER_CMD=$(command -v podman || echo ) |
9 | 11 | fi
|
10 |
| - |
| 12 | +if [ -z "${CONTAINER_CMD}" ]; then |
| 13 | +echo "Error determining container command." |
| 14 | +exit 1 |
| 15 | +fi |
| 16 | +echo "container command: '${CONTAINER_CMD}'." |
| 17 | +echo "creating temporary directory." |
11 | 18 | TMPDIR="$(mktemp -d)"
|
12 | 19 | rc=$?
|
13 | 20 |
|
14 | 21 | if [ $rc -ne 0 ]; then
|
15 |
| - echo "Error creating temporary directory" |
16 |
| -else |
17 |
| - CONTAINER_ID="$(${CONTAINER_CMD} run --network=none --name samba \ |
18 |
| - --volume="${TMPDIR}":/share:Z --rm -d "${LOCAL_TAG}")" |
| 22 | + echo "Error creating temporary directory." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | +echo "temporary directory: '${TMPDIR}'" |
| 26 | +echo "starting Samba container." |
| 27 | +CONTAINER_ID="$(${CONTAINER_CMD} run --network=none --name samba \ |
| 28 | + --volume="${TMPDIR}":/share:Z --rm -d "${LOCAL_TAG}")" |
| 29 | +rc=$? |
| 30 | + |
| 31 | +if [ $rc -ne 0 ]; then |
| 32 | + echo "Error running samba container" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | +echo "Container started, ID: '${CONTAINER_ID}'" |
| 36 | + |
| 37 | +# give samba a second to come up |
| 38 | +sleep 1 |
| 39 | + |
| 40 | +echo "Listing samba shares" |
| 41 | + ${CONTAINER_CMD} exec "${CONTAINER_ID}" smbclient -U% -L 127.0.0.1 |
19 | 42 | rc=$?
|
20 | 43 |
|
21 |
| - if [ $rc -ne 0 ]; then |
22 |
| - echo "Error running samba container" |
23 |
| - else |
24 |
| - echo "Container started, ID: '${CONTAINER_ID}'" |
| 44 | +if [ ${rc} -ne 0 ]; then |
| 45 | + echo "Error listing samba shares" |
| 46 | + exit 1 |
| 47 | +fi |
25 | 48 |
|
26 |
| - # give samba a second to come up |
27 |
| - sleep 1 |
28 | 49 |
|
29 |
| - ${CONTAINER_CMD} exec "${CONTAINER_ID}" smbclient -U% -L 127.0.0.1 |
30 |
| - rc=$? |
| 50 | +echo "stopping samba container." |
31 | 51 |
|
32 |
| - if [ $rc -ne 0 ]; then |
33 |
| - echo "Error listing samba shares" |
34 |
| - fi |
35 |
| - fi |
| 52 | +${CONTAINER_CMD} kill "${CONTAINER_ID}" |
| 53 | +rc=$? |
36 | 54 |
|
37 |
| - ${CONTAINER_CMD} kill "${CONTAINER_ID}" |
| 55 | +if [ $rc -ne 0 ]; then |
| 56 | + echo "Error stopping samba container" |
| 57 | + exit 1 |
38 | 58 | fi
|
39 | 59 |
|
| 60 | +echo "samba container stopped." |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +echo "removing temporary directory." |
40 | 66 | rm -rf "${TMPDIR}"
|
| 67 | +rc=$? |
| 68 | + |
41 | 69 |
|
42 | 70 | if [ $rc -eq 0 ]; then
|
43 | 71 | echo "Success"
|
|
0 commit comments