-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.expand.exec
120 lines (100 loc) · 3.46 KB
/
image.expand.exec
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
#
# See the COPYRIGHT.md file at the top-level directory of this distribution and at
# https://github.com/singularityware/singularity/blob/master/COPYRIGHT.md.
#
# This file is part of the Singularity Linux container project. It is subject to the license
# terms in the LICENSE.md file found in the top-level directory of this distribution and
# at https://github.com/singularityware/singularity/blob/master/LICENSE.md. No part
# of Singularity, including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE.md file.
#
# This file also contains content that is covered under the LBNL/DOE/UC modified
# 3-clause BSD license and is subject to the license terms in the LICENSE-LBNL.md
# file found in the top-level directory of this distribution and at
# https://github.com/singularityware/singularity/blob/master/LICENSE-LBNL.md.
## Basic sanity
if [ -z "$SINGULARITY_libexecdir" ]; then
echo "Could not identify the Singularity libexecdir."
exit 1
fi
## Load functions
if [ -f "$SINGULARITY_libexecdir/singularity/functions" ]; then
. "$SINGULARITY_libexecdir/singularity/functions"
else
echo "Error loading functions: $SINGULARITY_libexecdir/singularity/functions"
exit 1
fi
PATH=/sbin:/usr/sbin:${PATH:-}
IMAGE_SIZE="512"
while true; do
case ${1:-} in
-h|--help|help)
exec "$SINGULARITY_libexecdir/singularity/cli/help.exec" "$SINGULARITY_COMMAND"
;;
-s|--size)
shift
SINGULARITY_IMAGESIZE="${1:-}"
export SINGULARITY_IMAGESIZE
shift
;;
-*)
message ERROR "Unknown option: ${1:-}\n"
exit 1
;;
*)
break
;;
esac
done
if [ -f "$SINGULARITY_libexecdir/singularity/cli/$SINGULARITY_COMMAND.info" ]; then
. "$SINGULARITY_libexecdir/singularity/cli/$SINGULARITY_COMMAND.info"
else
message ERROR "Could not find the info file for: $SINGULARITY_COMMAND\n"
ABORT 255
fi
if [ -z "${1:-}" ]; then
if [ -n "${USAGE:-}" ]; then
echo "USAGE: $USAGE"
else
echo "To see usage summary type: singularity help $SINGULARITY_COMMAND"
fi
exit 0
fi
SINGULARITY_IMAGE="${1:-}"
SINGULARITY_WRITABLE=1
export SINGULARITY_IMAGE SINGULARITY_WRITABLE
if [ -z "$SINGULARITY_IMAGE" ]; then
message ERROR "You must supply a path to an image to expand\n"
exit 1
fi
if [ ! -f "$SINGULARITY_IMAGE" ]; then
message ERROR "Singularity image file not found: $SINGULARITY_IMAGE\n"
exit 1
fi
IMAGE_TYPE=`eval "$SINGULARITY_libexecdir/singularity/bin/image-type" "${SINGULARITY_IMAGE}" 2>/dev/null`
if [ "$IMAGE_TYPE" != "EXT3" ]; then
message ERROR "This is not a writable Singularity image format\n"
ABORT 255
fi
if ! touch "$SINGULARITY_IMAGE" >/dev/null 2>&1; then
message ERROR "Inappropriate permission to modify: $SINGULARITY_IMAGE\n"
ABORT 255
fi
message 1 "Expanding image by ${SINGULARITY_IMAGESIZE:-768}MB\n"
if ! dd if=/dev/zero bs=1M count=${SINGULARITY_IMAGESIZE:-768} status=none >> "$SINGULARITY_IMAGE"; then
message ERROR "Failed expanding image!\n"
exit 1
fi
message 1 "Checking image's file system\n"
if ! /sbin/e2fsck -fy "$SINGULARITY_IMAGE"; then
exit 1
fi
message 1 "Resizing image's file system\n"
if ! /sbin/resize2fs "$SINGULARITY_IMAGE"; then
exit 1
fi
message 1 "Image is done: $SINGULARITY_IMAGE\n"
exit 0