-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomize-debian
executable file
·87 lines (62 loc) · 1012 Bytes
/
customize-debian
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
#!/bin/bash
set -eu
SCRIPT=$0
function usage()
{
echo "$SCRIPT IMAGE PART SCRIPT"
exit 1
}
test $# -eq 3 || usage
test -f $1 || usage
test -s $1 || usage
test -x $3 || usage
IMAGE=$1
PART=$2
SCRIPT=$3
set -x
MP=$(mktemp -d)
function get_nbd()
{
local size nbd
modprobe nbd
(
cd /sys/devices/virtual/block/
for nbd in $(ls -d nbd*) ; do
size=$(cat $nbd/size)
test $size -eq 0 && break
done
echo "/dev/$nbd"
)
}
NBD=$(get_nbd)
qemu-nbd -c $NBD $IMAGE
udevadm settle; sync
mount ${NBD}p${PART} $MP -o subvol=@rootfs
trap '
cd /tmp
umount ${NBD}p${PART}
qemu-nbd -d $NBD
' EXIT
chattr -R -c $MP/boot
cd $MP
$SCRIPT
chroot $MP /bin/bash <<EOF
set -exu
trap '
umount /proc
umount /dev
umount /sys
' EXIT
mount none -t sysfs /sys
mount none -t devtmpfs /dev
mount none -t proc /proc
echo 'root:root' | chpasswd
cd /etc
mv resolv.conf{,.save}
cat - <<EORC > resolv.conf
nameserver 192.168.9.1
nameserver 192.168.9.6
nameserver 192.168.9.4
EORC
EOF
exit 0