#!/bin/bash # This shell script used to fetch debian root file system # this project absolute path PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) # the target board name and ARCH(armel/armhf/arm64) BOARD=igkboard ARCH=armhf ARCH=arm64 # Debian 11 (bullseye) CODENAME=bullseye VERSION=11 # Debian 12 (bookworm) CODENAME=bookworm VERSION=12 # rootfs directory name ROOTFS_DIR=rootfs-debian-$CODENAME # rootfs configuration DEF_PASSWD=12345 # shell script will exit once get command error set -e #+-------------------------+ #| Shell script functions | #+-------------------------+ function pr_error() { echo -e "\033[40;31m $1 \033[0m" } function pr_warn() { echo -e "\033[40;33m $1 \033[0m" } function pr_info() { echo -e "\033[40;32m $1 \033[0m" } # Debian 12 depends on the new keyring # https://packages.debian.org/sid/all/debian-archive-keyring/download function update_keyring() { debname=debian-archive-keyring debversion=2023.3 set +e dpkg -l $debname > /dev/null 2>&1 if [ $? == 0 ] ; then dpkg -s debian-archive-keyring | grep Version: | grep $debversion > /dev/null 2>&1 if [ $? != 0 ] ; then pr_info "updating $debname" apt purge -y $debname else pr_info "$debname is latest" return; fi fi set -e pr_info "install $debname now" wget http://ftp.us.debian.org/debian/pool/main/d/$debname/${debname}_${debversion}_all.deb > /dev/null dpkg -i ${debname}_${debversion}_all.deb rm -f ${debname}_${debversion}_all.deb } function do_install() { pr_warn "\ninstall system tools" update_keyring debootstrap --version > /dev/null 2>&1 if [ $? == 0 ] ; then pr_info "system tools installed already" return ; fi apt install binfmt-support qemu qemu-user-static debootstrap } function do_fetch() { pr_warn "\ndebootstrap fetch" if [ -f ${ROOTFS_DIR}/bin/bash ] ; then pr_info "debain rootfs fetched already" return ; fi debootstrap --arch=${ARCH} --foreign ${CODENAME} ${ROOTFS_DIR} http://ftp.debian.org/debian/ cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/ DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} debootstrap/debootstrap --second-stage DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} dpkg --configure -a rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static } function modify_rootfs() { pr_warn "\nmodify rootfs environment" # update hostnmae and issue echo $BOARD > ${ROOTFS_DIR}/etc/hostname echo "Debian GNU/Linux $VERSION \n \l, default password '$DEF_PASSWD'" > ${ROOTFS_DIR}/etc/issue # update dns server echo "nameserver 223.5.5.5" > ${ROOTFS_DIR}/etc/resolv.conf echo "nameserver 114.114.114.114" >> ${ROOTFS_DIR}/etc/resolv.conf set +e # add ls alias for display with color grep "color=auto" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1 if [ $? != 0 ] ; then echo "alias ls='ls --color=auto'" >> ${ROOTFS_DIR}/etc/profile fi grep "^PermitRootLogin" ${ROOTFS_DIR}/etc/ssh/sshd_config > /dev/null 2>&1 if [ $? != 0 ] ; then echo "PermitRootLogin yes" >> ${ROOTFS_DIR}/etc/ssh/sshd_config fi set -e } function do_conf() { EXTRA_APPS="vim net-tools network-manager tree file parted locales lsb-release tzdata wireless-tools openssh-server" pr_warn "\ndebootstrap configure" cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/ DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} apt update DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} apt install -y ${EXTRA_APPS} DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} sh -c "echo root:${DEF_PASSWD} | chpasswd" rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static modify_rootfs } function do_pack() { pr_warn "\npackage $ROOTFS_DIR" cd $PRJ_PATH/$ROOTFS_DIR tar -cJf ../$ROOTFS_DIR.tar.xz * } #+-------------------------+ #| Shell script body start | #+-------------------------+ if [ `id -u` != 0 ] ; then pr_error "ERRROR: This shell script must excuted as root privilege." exit 0; fi do_install do_fetch do_conf do_pack