forked from billm/pfsense-tools-centipede-slbd
/
modify_m0n0wall_image.sh
executable file
·58 lines (43 loc) · 1.29 KB
/
modify_m0n0wall_image.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
#/bin/sh
# Instructions (as root)-- make a directory and put this script inside it.
# chmod +x workon.sh
# Download or copy an image file into the directory
# ./workon.sh wrap-1.11.img
# This will start your SHELL inside the mounted image.
# When you are done, type exit. This exits your SHELL and lets
# this script proceed (umount, gzip, etc).
# The image file now contains your changes (and is no longer signed).
# Set your shell -- /bin/csh will always work
SHELL=/usr/local/bin/bash
[ ! -x $SHELL ] && echo "${SHELL} not executable (try /bin/csh)" && exit 1
# No more edits
IMAGE=$1
# Make dirs
mkdir -p tmp; mkdir -p mnt1; mkdir -p mnt2
# Decompress IMAGE
gzip -dc < ${IMAGE} > tmp/${IMAGE}
# Mount IMAGE
mdconfig -a -t vnode -f tmp/${IMAGE} -u 90
mount /dev/md90a mnt1
# Decompress mfsroot
gzip -dc < mnt1/mfsroot.gz > tmp/${IMAGE}-mfsroot
# Mount mfsroot
mdconfig -a -t vnode -f tmp/${IMAGE}-mfsroot -u 91
mount /dev/md91 mnt2
# cd to 2nd mount and exec SHELL
cd mnt2
${SHELL}
# SHELL has exited -- clean up and compress
for vtmp in `find . | grep '~$'`; do
echo Removing: ${vtmp}
rm -f ${vtmp}
done
cd ../
umount mnt2
mdconfig -d -u 91
gzip -c9 < tmp/${IMAGE}-mfsroot > mnt1/mfsroot.gz
rm -f tmp/${IMAGE}-mfsroot
umount mnt1
mdconfig -d -u 90
gzip -c9 < tmp/${IMAGE} > ${IMAGE}
rm -f tmp/${IMAGE}