#!/bin/bash SUITE=stretch BD=$(date +%Y%m%d) PKGS="debian-keyring,debian-archive-keyring,gnupg,dirmngr" MIRROR="http://archive.debian.org/debian/" BOARDS="ax1 aiotg3 aiotg3l degugw a600" die(){ echo ERROR: $@ 1>&2 exit 1 } abort(){ BUILDDIR=$ABSP echo "Abort and remove temporary filesystem." kill_inside_chroot $BUILDDIR umount -lf $BUILDDIR/proc > /dev/null 2>&1 umount -lf $BUILDDIR/sys > /dev/null 2>&1 rm -rf $BUILDDIR } kill_inside_chroot(){ CHROOT_PATH=$1 for ROOT in /proc/*/root; do LINK=$(readlink $ROOT) if [ "x$LINK" != "x" ]; then if [ "x${LINK:0:${#CHROOT_PATH}}" = "x$CHROOT_PATH" ]; then PID=$(basename $(dirname "$ROOT")) kill -9 "$PID" fi fi done } usage(){ echo -e """Usage: build.sh [OPTION].. [BOARD] -h, --help \t show this message BOARD: ${BOARDS} (default: aiotg3) """ } TEMP=$(getopt -u -o h --longoptions help -n $0 -- "$@") if [ $? != 0 ]; then exit 1 fi set -- $TEMP while [ $1 != -- ] do case $1 in -h|--help) usage exit 1 esac shift done if [ ! -e /usr/bin/qemu-arm-static ] ;then echo "qemu-arm-static is not installed yet." exit 1 fi if [ $(whoami) != "root" ] ;then echo "ERROR: Please run script with sudo" exit 1 fi shift # skip -- BOARD=$1 if [ -z $BOARD ]; then BOARD="aiotg3" fi for i in $BOARDS; do if [ s$BOARD = s$i ]; then echo Product: $BOARD fb=$BOARD fi done if [ -z $fb ]; then die $BOARD is not support board fi TARG="./debian-${SUITE}-armhf_${BOARD}" ABSP=$(echo $TARG | sed "s;./;${PWD}/;") RES="./${BOARD}_resources" if [ -e $TARG ] ;then while : ;do echo -n temporary filesystem $TARG is already exist. Remove it? [y/N]: read ans case $ans in "yes"|"YES"|"y"|"Y") rm -rf $TARG break;; ""|"no"|"NO"|"n"|"N") exit 1;; esac done fi trap 'abort; exit 1' 1 2 13 15 debootstrap --arch=armhf --variant=minbase --include=$PKGS --foreign $SUITE $ABSP $MIRROR #Copy emulator cp /usr/bin/qemu-arm-static $ABSP/usr/bin #Copy resources and fixup cp -r $RES/* $ABSP chroot $ABSP sh -c "/debootstrap/debootstrap --second-stage" mv $ABSP/sbin/start-stop-daemon $ABSP/sbin/start-stop-daemon.REAL echo \ "#!/bin/sh echo echo \"Warning: Fake start-stop-daemon called, doing nothing\"" > "$ABSP/sbin/start-stop-daemon" chmod 755 "$ABSP/sbin/start-stop-daemon" mount -t proc proc $ABSP/proc; mount -t sysfs sysfs $ABSP/sys; DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot $ABSP sh -c "/resources/fixup" chroot $ABSP sh -c "apt-get clean" chroot $ABSP sh -c "LANG=C COLUMNS=150 dpkg -l > /resources/installed_pkgs.list" kill_inside_chroot $ABSP umount $ABSP/proc || umount -lf $ABSP/proc umount $ABSP/sys mv $ABSP/sbin/start-stop-daemon.REAL $ABSP/sbin/start-stop-daemon #Remove emulator rm $ABSP/usr/bin/qemu-arm-static #Remove resources cp $ABSP/resources/installed_pkgs.list ./installed_pkgs_$BD.list chown ${SUDO_USER} ./installed_pkgs_$BD.list rm -rf $ABSP/resources #Archive userland (cd $ABSP; tar zcf ../$(basename $ABSP)_$BD.tar.gz * ; chown ${SUDO_USER} ../$(basename $ABSP)_$BD.tar.gz) #Remove working dir rm -rf $ABSP