|
36 | 36 | set -o errexit |
37 | 37 | set -o nounset |
38 | 38 |
|
39 | | -USAGE="USAGE: docker2singularity [-m \"/mount_point1 /mount_point2\"] [options] docker_image_name" |
| 39 | +usage="USAGE: docker2singularity [-m \"/mount_point1 /mount_point2\"] [options] docker_image_name" |
40 | 40 |
|
41 | 41 | # --- Option processing -------------------------------------------- |
42 | 42 | if [ $# == 0 ] ; then |
43 | | - echo $USAGE |
| 43 | + echo "${usage}" |
44 | 44 | echo "OPTIONS: |
45 | 45 |
|
46 | 46 | Image Format |
47 | 47 | -f: build development sandbox (folder) |
48 | 48 | -w: non-production writable image (ext3) |
49 | | -
|
50 | | - Default is squashfs (recommended) |
| 49 | + Default is squashfs (recommended) |
| 50 | + -n: provide basename for the container (default based on URI) |
51 | 51 | " |
52 | 52 |
|
53 | 53 | exit 1; |
54 | 54 | fi |
55 | 55 |
|
56 | 56 | mount_points="/oasis /projects /scratch /local-scratch /work /home1 /corral-repl /corral-tacc /beegfs /share/PI /extra /data /oak" |
57 | 57 | image_format="squashfs" |
58 | | -while getopts ':hm:wf' option; do |
59 | | - case "$option" in |
60 | | - h) echo "$USAGE" |
61 | | - exit 0 |
62 | | - ;; |
63 | | - m) mount_points=$OPTARG |
64 | | - ;; |
65 | | - f) image_format="sandbox" |
66 | | - ;; |
67 | | - w) image_format="writable" |
68 | | - ;; |
69 | | - :) printf "missing argument for -%s\n" "$OPTARG" >&2 |
70 | | - echo "$usage" >&2 |
71 | | - exit 1 |
72 | | - ;; |
73 | | - \?) printf "illegal option: -%s\n" "$OPTARG" >&2 |
74 | | - echo "$usage" >&2 |
75 | | - exit 1 |
76 | | - ;; |
77 | | - esac |
| 58 | +new_container_name="" |
| 59 | + |
| 60 | +while true; do |
| 61 | + case ${1:-} in |
| 62 | + -h|--help|help) |
| 63 | + echo "${usage}" |
| 64 | + exit 0 |
| 65 | + ;; |
| 66 | + -n|--name) |
| 67 | + shift |
| 68 | + new_container_name="${1:-}" |
| 69 | + shift |
| 70 | + ;; |
| 71 | + -m|--mount) |
| 72 | + shift |
| 73 | + mount_points="${1:-}" |
| 74 | + shift |
| 75 | + ;; |
| 76 | + -f|--folder) |
| 77 | + shift |
| 78 | + image_format="sandbox" |
| 79 | + shift |
| 80 | + ;; |
| 81 | + -s|--sandbox) |
| 82 | + shift |
| 83 | + image_format="writable" |
| 84 | + shift |
| 85 | + ;; |
| 86 | + :) printf "missing argument for -%s\n" "$option" >&2 |
| 87 | + echo "$usage" >&2 |
| 88 | + exit 1 |
| 89 | + ;; |
| 90 | + \?) printf "illegal option: -%s\n" "$option" >&2 |
| 91 | + echo "$usage" >&2 |
| 92 | + exit 1 |
| 93 | + ;; |
| 94 | + -*) |
| 95 | + printf "illegal option: -%s\n" "$option" >&2 |
| 96 | + echo "$usage" >&2 |
| 97 | + exit 1 |
| 98 | + ;; |
| 99 | + *) |
| 100 | + break; |
| 101 | + ;; |
| 102 | + esac |
78 | 103 | done |
79 | | -shift $((OPTIND - 1)) |
80 | 104 |
|
81 | 105 | image=$1 |
82 | 106 |
|
83 | 107 | echo "" |
84 | 108 | echo "Image Format: ${image_format}" |
| 109 | +echo "Docker Image: ${image}" |
| 110 | + |
| 111 | +if [ "${new_container_name}" != "" ]; then |
| 112 | + echo "Container Name: ${new_container_name}" |
| 113 | +fi |
| 114 | + |
| 115 | +echo "" |
85 | 116 |
|
86 | 117 | ################################################################################ |
87 | 118 | ### CONTAINER RUNNING ID ####################################################### |
@@ -132,8 +163,21 @@ TMPDIR=$(mktemp -u -d) |
132 | 163 | mkdir -p $TMPDIR |
133 | 164 |
|
134 | 165 | creation_date=`echo ${creation_date} | cut -c1-10` |
135 | | -new_container_name=/tmp/$image_name-$creation_date-$container_id |
| 166 | + |
| 167 | +# The user has not provided a custom name |
| 168 | +if [ "${new_container_name}" == "" ]; then |
| 169 | + new_container_name=/tmp/$image_name-$creation_date-$container_id |
| 170 | + |
| 171 | +# The user has provided a custom name |
| 172 | +else |
| 173 | + new_container_name=/tmp/$(basename $new_container_name) |
| 174 | + new_container_name="${new_container_name%.*}" |
| 175 | +fi |
| 176 | + |
| 177 | + |
136 | 178 | build_sandbox="${new_container_name}.build" |
| 179 | + |
| 180 | + |
137 | 181 | echo "(1/10) Creating a build sandbox..." |
138 | 182 | mkdir -p ${build_sandbox} |
139 | 183 | echo "(2/10) Exporting filesystem..." |
|
0 commit comments