Skip to content

Commit 3718c09

Browse files
committed
add -b and -c options
1 parent 36df84b commit 3718c09

2 files changed

Lines changed: 84 additions & 10 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ To use a local copy of the mfsbsd image instead of having the script download it
4747
./build.sh -r 14.3 -f downloads/mfsbsd-14.3-RELEASE-p3-amd64.img
4848
```
4949

50+
If no mfsBSD image is available for download, the script can try to automatically build it for the specified FreeBSD release:
51+
52+
```
53+
./build.sh -r 14.3 -b
54+
```
55+
56+
Please note that building mfsBSD requires more diskspace and will automatically install all required dependencies. Refer to [mfsBSD build instructions](https://github.com/mmatuska/mfsbsd/blob/master/BUILD.md) for further information.
57+
58+
Cleanup build/tmp directories:
59+
60+
```
61+
./build.sh -c
62+
```
63+
5064
## Acknowledgement
5165

5266
Thanks to Martin Matuška for creating [mfsBSD](https://mfsbsd.vx.sk/) and his talk on [Deploying FreeBSD systems with Foreman](https://blog.vx.sk/archives/60).

build.sh

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ IMAGE_MD_NO=99
66
IMAGE_MOUNT_DIR='/mnt/loop'
77
ROOT_MD_NO=100
88
ROOT_MOUNT_DIR='/mnt/mfsroot'
9+
CLEANUP=0
10+
MFSBSD_BUILD=0
11+
MFSBSD_DIST_DIR="${TMP_DIR}/dist"
912
MFSBSD_FILENAME=''
13+
MFSBSD_REPO='https://github.com/mmatuska/mfsbsd.git'
14+
MFSBSD_CLONE_DIR="${TMP_DIR}/mfsbsd"
15+
FREEBSD_MIRROR='https://download.freebsd.org/ftp/releases/amd64'
1016

1117
cleanup() {
1218
cd $TMP_DIR
13-
rm -R ${TMP_DIR}/rw $IMAGE_MOUNT_DIR $ROOT_MOUNT_DIR
19+
rm -R ${TMP_DIR}/rw $MFSBSD_DIST_DIR $MFSBSD_CLONE_DIR $IMAGE_MOUNT_DIR $ROOT_MOUNT_DIR 2>/dev/null
1420
}
1521

1622
if [ $(id -u) != "0" ]; then
@@ -21,6 +27,14 @@ fi
2127
# handle arguments
2228
while [ ${#} -gt 0 ]; do
2329
case "${1}" in
30+
-b)
31+
MFSBSD_BUILD=1
32+
shift
33+
;;
34+
-c)
35+
CLEANUP=1
36+
shift
37+
;;
2438
-f)
2539
if ! test -e ${2}; then
2640
echo "Specified mfsBSD file not found: ${2}"
@@ -44,6 +58,16 @@ while [ ${#} -gt 0 ]; do
4458
shift 1
4559
done
4660

61+
mkdir -p $TMP_DIR $MFSBSD_DIST_DIR
62+
cd $TMP_DIR
63+
64+
if [ "${CLEANUP}" == 1 ]; then
65+
echo "Cleaning up..."
66+
cleanup
67+
echo "Exiting."
68+
exit 0
69+
fi
70+
4771
if [ ! -e "${ORIG_DIR}/rc.local" ]; then
4872
echo "Custom rc.local not found."
4973
exit 1
@@ -70,18 +94,54 @@ else
7094
MFSBSD_PART_NUM="p2"
7195
fi
7296

73-
mkdir -p $TMP_DIR
74-
cd $TMP_DIR
75-
7697
# download mfsbsd image
77-
if [ -z "${MFSBSD_FILENAME}" ]; then
78-
if ! fetch https://mfsbsd.vx.sk/files/images/${REL_MAJOR}/amd64/${MFSBSD_IMAGE}; then
79-
echo "Failed to download mfsbsd image"
80-
exit 1
98+
if [ "${MFSBSD_BUILD}" == '0' ]; then
99+
if [ -z "${MFSBSD_FILENAME}" ]; then
100+
echo "Downloading mfsBSD image... (please wait)"
101+
if ! fetch https://mfsbsd.vx.sk/files/images/${REL_MAJOR}/amd64/${MFSBSD_IMAGE}; then
102+
echo "Failed to download mfsbsd image"
103+
exit 1
104+
fi
105+
else
106+
# use specified file instead
107+
MFSBSD_IMAGE=$MFSBSD_FILENAME
81108
fi
82109
else
83-
# use specified file instead
84-
MFSBSD_IMAGE=$MFSBSD_FILENAME
110+
echo "Building mfsBSD image... (please wait)"
111+
112+
# get distribution files
113+
for dist in base kernel; do
114+
if ! fetch -o ${MFSBSD_DIST_DIR}/${dist}.txz ${FREEBSD_MIRROR}/${REL_MAJOR}.${REL_MINOR}-RELEASE/${dist}.txz; then
115+
echo "Failed to download distribution files"
116+
exit 1
117+
fi
118+
done
119+
120+
# prepare mfsbsd build
121+
if [ ! -d "${MFSBSD_CLONE_DIR}" ]; then
122+
if ! git clone $MFSBSD_REPO $MFSBSD_CLONE_DIR; then
123+
echo "Failed to clone mfsbsd git repo"
124+
exit 1
125+
fi
126+
fi
127+
cd $MFSBSD_CLONE_DIR
128+
for file in conf/*.sample; do
129+
if ! mv "$file" "${file%.sample}"; then
130+
echo "Failed to prepare mfsbsd conf files"
131+
exit 1
132+
fi
133+
done
134+
135+
# build
136+
make BASE=$MFSBSD_DIST_DIR
137+
138+
# output file
139+
for image in ${MFSBSD_CLONE_DIR}/mfsbsd-${REL_MAJOR}.${REL_MINOR}-*.img; do
140+
echo "Successfully built mfsbsd image: ${image}"
141+
MFSBSD_IMAGE=$image
142+
break
143+
done
144+
cd $TMP_DIR
85145
fi
86146

87147
# mount mfsbsd disk image

0 commit comments

Comments
 (0)