Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Building with custom or random DUID instead of static value.

  • Loading branch information...
commit daaf1c9e1a9e29e520c52ec0dcf024d33953d5dc 1 parent 2882a54
@jryberg jryberg authored
View
17 build-bindist.sh
@@ -1,5 +1,16 @@
#!/bin/sh
+# Functions
+function getrandomduid {
+ # Generates a 16 chars long hex string
+ tempduid=`cat /dev/urandom | tr -dc "a-f0-9" | fold -w 16 | head -1`
+ echo ${tempduid}
+}
+
+DUID=`getrandomduid`
+
+export DUID
+
mkdir bindist
DISTNAME=WRAP12
@@ -66,6 +77,12 @@ cp obj/bsd.gz bindist/${DISTNAME}.bsd
gzip image
mv image.gz bindist/${DISTNAME}.image
+DISTNAME=PENDRIVE
+./build-usbkernel.sh GENERIC-RD ${DUID}
+./build-usbimage.sh pendrive ${DUID}
+gzip pendrive
+mv pendrive.gz bindist/${DISTNAME}.image
+
DISTNAME=LIVECD
sh ./build-livecd.sh GENERIC-RD
mv obj/live_cd*.iso bindist/
View
16 build-usbimage.sh
@@ -8,6 +8,7 @@ SUDO=sudo
DEVICE=svnd0
MOUNTPOINT=/mnt
TEMPFILE=/tmp/build-diskimage.tmp.$$
+DUID=${2}
# This is for boot.conf and should match the kernel ttyspeed.
# Which should be 9600 for GENERIC-RD, 38400 for WRAP12 and 19200 for the rest.
@@ -39,10 +40,9 @@ cylinders=980 # "cylinders:"
#trackscylinder=16 # "tracks/cylinder:"
#cylinders=994 # "cylinders:"
-
# Don't start without a imagefile as a parameter
-if [ "$1" = "" ]; then
- echo "usage: $0 imagefile"
+if [ "$1" = "" ] || [ "$DUID" = "" ]; then
+ echo "usage: $0 imagefile duid"
exit 1
fi
@@ -54,6 +54,12 @@ if [ ! -r $KERNELFILE ]; then
exit 1
fi
+# Check DUID format (hex and 16 char long string)
+if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
+ echo "DUID: ${DUID} is not a 16-character hexadecimal string"
+ exit
+fi;
+
echo "Cleanup if something failed the last time... (ignore any not currently mounted and Device not configured warnings)"
${SUDO} umount $MOUNTPOINT
${SUDO} vnconfig -u $DEVICE
@@ -107,10 +113,10 @@ ${SUDO} disklabel -R $DEVICE $TEMPFILE
rm $TEMPFILE
echo ""
-echo "Setting duid with disklabel..."
+echo "Setting duid to ${DUID} with disklabel..."
${SUDO} disklabel -E $DEVICE << __EOC >/dev/null
i
-0123456789abcdef
+${DUID}
write
quit
__EOC
View
13 build-usbkernel-injail.sh
@@ -1,5 +1,11 @@
#!/bin/sh
+# Check DUID format (hex and 16 char long string)
+if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
+ echo "DUID: ${DUID} is not a 16-character hexadecimal string"
+ exit
+fi;
+
# Create dir if not there
mkdir -p obj
@@ -18,13 +24,18 @@ COPY ${DESTDIR}/sbin/mount_cd9660 sbin/mount_cd9660\
rm list.temp
mv list.temp2 list.temp
+# Modify fstab.initial.usb and replace predefined UID with the defined one
+sed 's/0123456789abcdef/'"${1}"'/g' initial-conf/fstab.initial.usb > initial-conf/fstab.initial.usb.tmp
+rm initial-conf/fstab.initial.usb
+mv initial-conf/fstab.initial.usb.tmp initial-conf/fstab.initial.usb
+
# Cleanup just in case the previous build failed
umount /mnt
vnconfig -u svnd0
make KCONF=${KERNEL} clean
# Make kernel
-make termdefs bsd KCONF=${KERNEL} LIST=/list.temp NBLKS=${NBLKS} DISKPROTO=/disktabs/${DISKTAB} $2 $3 $4
+make termdefs bsd KCONF=${KERNEL} LIST=/list.temp NBLKS=${NBLKS} DISKPROTO=/disktabs/${DISKTAB}
exit
View
32 build-usbkernel.sh
@@ -2,18 +2,31 @@
#
# Builds a 48MB kernel to put on a USB-stick
+# Functions
+function getrandomduid {
+ # Generates a 16 chars long hex string
+ tempduid=`cat /dev/urandom | tr -dc "a-f0-9" | fold -w 16 | head -1`
+ echo ${tempduid}
+}
+
CWD=`pwd`
WORKDIR=sandbox
DISKTAB=disktab.48mb
NBLKS=98304
SRCDIR=${BSDSRCDIR:-/usr/src}
DESTDIR=${DESTDIR:-${CWD}/${WORKDIR}}
-
-export SRCDIR DESTDIR CWD WORKDIR DISKTAB NBLKS
+DUID=${2:-`getrandomduid`}
+export SRCDIR DESTDIR CWD WORKDIR DISKTAB NBLKS DUID
# Don't start without a kernel as a parameter
if [ "$1" = "" ]; then
- echo "usage: $0 kernel"
+ echo "usage: $0 kernel [duid]"
+ echo
+ echo "The options are as follows:"
+ echo "[duid]: Optional 16-character hexadecimal string used as"
+ echo " disklabel UID for the storage device mounted as /flash"
+ echo " If unset a random number is generated and printed at"
+ echo " the end of the script"
exit 1
fi
@@ -29,6 +42,12 @@ if ! [ -d ${CWD}/${WORKDIR}/dev ]; then
exit
fi
+# Check DUID format (hex and 16 char long string)
+if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
+ echo "DUID: ${DUID} is not a 16-character hexadecimal string"
+ exit
+fi;
+
# Which kernel to use?
export KERNEL=$1
@@ -65,7 +84,7 @@ mkdir -p ${CWD}/obj
umount /mnt
echo "Going into chroot to build kernel"
-/usr/sbin/chroot ${CWD}/${WORKDIR} ./build-usbkernel-injail.sh
+/usr/sbin/chroot ${CWD}/${WORKDIR} ./build-usbkernel-injail.sh ${DUID}
echo "Comming back from chroot"
@@ -79,7 +98,7 @@ echo "Building file system"
cd ${CWD}/${WORKDIR}/
# From Makefile that could not run in a chroot
-make mr.fs rdsetroot KCONF=${KERNEL} LIST=${CWD}/${WORKDIR}/list.temp NBLKS=${NBLKS} DISKPROTO=${CWD}/${WORKDIR}/disktabs/${DISKTAB} $2 $3 $4
+make mr.fs rdsetroot KCONF=${KERNEL} LIST=${CWD}/${WORKDIR}/list.temp NBLKS=${NBLKS} DISKPROTO=${CWD}/${WORKDIR}/disktabs/${DISKTAB}
cp ${CWD}/${WORKDIR}/obj/bsd ${CWD}/${WORKDIR}/obj/bsd.rd
${CWD}/${WORKDIR}/obj/rdsetroot ${CWD}/${WORKDIR}/obj/bsd.rd < ${CWD}/${WORKDIR}/obj/mr.fs
gzip -c9 ${CWD}/${WORKDIR}/obj/bsd.rd > ${CWD}/${WORKDIR}/obj/bsd.gz
@@ -95,3 +114,6 @@ mv ${CWD}/${WORKDIR}/obj/* ${CWD}/obj/
# Done
echo "Your kernel is stored here ${CWD}/obj/"
+echo "The UID that are used in the ramdisk kernel is ${DUID}"
+echo "You *MUST* pass this UID to build-usbimage.sh as the second parameter"
+echo "or the image will fail to mount /flash."
Please sign in to comment.
Something went wrong with that request. Please try again.