From b0cd99d409f38e1aafcd67fef85a95f913b8ffbd Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Mon, 03 Jan 2022 20:51:19 +0800
Subject: [PATCH] update imx6ull bsp tarball buid.sh fix 127.0.0.1 bug

---
 bsp/rootfs/build.sh |   48 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/bsp/rootfs/build.sh b/bsp/rootfs/build.sh
index eae9bae..33aeabd 100755
--- a/bsp/rootfs/build.sh
+++ b/bsp/rootfs/build.sh
@@ -3,11 +3,8 @@
 PRJ_PATH=`pwd`
 PRJ_NAME=`basename ${PRJ_PATH}`
 
+# update by top build.sh
 BOARD=igkboard
-
-# SYSTEM  should be: buildroot, yocto or debian
-# DISTRO  should be: 2021.02, hardknott, buster or bullseye
-# SYSNAME should be: buildroot, yocto, buster or bullseye
 SYSTEM=buildroot
 DISTRO=2021.02
 SYSNAME=buildroot
@@ -15,9 +12,9 @@
 ROOTFS_DIR=rootfs_${SYSNAME}
 
 TAR_PATH=${PRJ_PATH}/../tarball
-DRV_PATH=${PRJ_PATH}/driver
 
 # rootfs configuration
+DEBIAN_URL=http://ftp.cn.debian.org/debian/
 ARCH=armhf
 DEF_USER=lingyun
 DEF_PASSWD=12345
@@ -91,8 +88,8 @@
     export LANG=C
 
     printf "\n\n -- debootstrap fetch start --\n\n"
-    echo "debootstrap --arch=${ARCH} --foreign ${DISTRO} ${ROOTFS_DIR} http://ftp.cn.debian.org/debian/"
-    debootstrap --arch=${ARCH} --foreign ${DISTRO} ${ROOTFS_DIR} http://ftp.cn.debian.org/debian/
+    echo "debootstrap --arch=${ARCH} --foreign ${DISTRO} ${ROOTFS_DIR} ${DEBIAN_URL}"
+    debootstrap --arch=${ARCH} --foreign ${DISTRO} ${ROOTFS_DIR} ${DEBIAN_URL}
 
     chroot ${ROOTFS_DIR} debootstrap/debootstrap --second-stage
     printf "\n\n -- debootstrap config start --\n\n"
@@ -102,6 +99,10 @@
 
     # Clear the MD5 value to install extra apps
     sed -i -e "s|.*md5apt.*|\t\"md5apt\":\"MD5_Auto_Generate_Here\"|g" $APPS_CONF
+
+    cd ${ROOTFS_DIR}
+    tar -cjf ../${ROOTFS_DIR}.orig.tar.bz2 *
+    cd -
 }
 
 
@@ -138,6 +139,7 @@
 
     chroot ${ROOTFS_DIR} apt update
     chroot ${ROOTFS_DIR} apt install -y ${extra_apps}
+    chroot ${ROOTFS_DIR} apt autoremove
 
     umount ${ROOTFS_DIR}/{sys,proc,dev/pts,dev}
 
@@ -148,15 +150,14 @@
     # modify root password
     chroot ${ROOTFS_DIR} sh -c "echo root:${DEF_PASSWD} | chpasswd"
 
-    # add extra user account
+    # add default user account
     set +e
     grep "$DEF_USER" ${ROOTFS_DIR}/etc/passwd > /dev/null 2>&1
     if [ $? != 0 ] ; then
         printf "\n\n -- setup default user account --\n\n"
         chroot ${ROOTFS_DIR} sh -c "useradd -m -s /bin/bash ${DEF_USER}"
         chroot ${ROOTFS_DIR} sh -c "echo ${DEF_USER}:${DEF_PASSWD} | chpasswd"
-        chroot ${ROOTFS_DIR} sh -c "usermod -G video,audio,sudo avnet"
-        echo "${DEF_USER}    ALL=(ALL:ALL) NOPASSWD:ALL" >> ${ROOTFS_DIR}/etc/sudoers
+        chroot ${ROOTFS_DIR} sh -c "usermod -aG video,audio,sudo ${DEF_USER}"
     fi
     set -e
 }
@@ -176,9 +177,10 @@
     mkdir -p ${dst}
 
     # parser to get .tar.gz .tar.bz2 .tar.xz
-    tar=`echo "${src#*.}"`
+    fname=`basename ${src}`
+    suffix=`echo "${fname#*.}"`
 
-    case $tar in
+    case $suffix in
         tar.gz)
             tar -xzf ${src} -C ${dst}
             ;;
@@ -192,7 +194,7 @@
             ;;
 
         *)
-            rm -rf ${dst}/`basename ${src}`
+            rm -rf ${dst}/${fname}
             cp -rf ${src} ${dst}
             ;;
 
@@ -218,6 +220,23 @@
     done
 }
 
+
+function update_debian()
+{
+    if [ $SYSTEM != debian ] ; then
+        return;
+    fi
+
+    # update PATH environment in /etc/profile
+    sed -i 's|PATH=.*|PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"|g' ${ROOTFS_DIR}/etc/profile
+
+    # update sudo without passwd
+    sed -i "s|^%sudo.*|%sudo   ALL=(ALL:ALL) NOPASSWD:ALL|g" ${ROOTFS_DIR}/etc/sudoers
+
+    # enable ping command for all user
+    chmod 4755 ${ROOTFS_DIR}/usr/bin/ping*
+}
+
 function do_modify()
 {
     msg_banner " modify rootfs environment"
@@ -240,7 +259,6 @@
     sed -i "s|PS1='# '|PS1='\\\u@\\\h:\\\w# '|g" ${ROOTFS_DIR}/etc/profile
     sed -i "s|PS1='$ '|PS1='\\\u@\\\h:\\\w$ '|g" ${ROOTFS_DIR}/etc/profile
 
-
     # add ls alias for display with color
     grep "^alias ls=" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1
     if [ $? != 0 ] ; then
@@ -251,6 +269,8 @@
     sed -i "s|^#PermitRootLogin.*|PermitRootLogin yes|g" ${ROOTFS_DIR}/etc/ssh/sshd_config
     sed -i "s|^#PasswordAuthentication.*|PasswordAuthentication yes|g" ${ROOTFS_DIR}/etc/ssh/sshd_config
 
+    update_debian
+
     # add vim alias for buildroot and yocto
     if [ $SYSTEM != "debian" ] ; then
         grep "alias vim=" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1

--
Gitblit v1.9.1