commit | author | age
|
98ec0b
|
1 |
#!/bin/bash |
G |
2 |
# This shell script used to fetch debian root file system |
|
3 |
|
|
4 |
# this project absolute path |
|
5 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
|
6 |
|
|
7 |
# top project absolute path |
|
8 |
TOP_PATH=$(realpath $PRJ_PATH/..) |
|
9 |
|
|
10 |
# config file path |
|
11 |
CONF_FILE=$TOP_PATH/config.json |
|
12 |
|
|
13 |
# rootfs configuration |
|
14 |
DEF_PASSWD=12345 |
|
15 |
|
|
16 |
# shell script will exit once get command error |
|
17 |
set -e |
|
18 |
|
|
19 |
#+-------------------------+ |
|
20 |
#| Shell script functions | |
|
21 |
#+-------------------------+ |
|
22 |
|
|
23 |
function pr_error() { |
|
24 |
echo -e "\033[40;31m $1 \033[0m" |
|
25 |
} |
|
26 |
|
|
27 |
function pr_warn() { |
|
28 |
echo -e "\033[40;33m $1 \033[0m" |
|
29 |
} |
|
30 |
|
|
31 |
function pr_info() { |
|
32 |
echo -e "\033[40;32m $1 \033[0m" |
|
33 |
} |
|
34 |
|
|
35 |
# parser configure file and export environment variable |
|
36 |
function export_env() |
|
37 |
{ |
|
38 |
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
39 |
export DIS_TYPE=`jq -r ".system.distro" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
40 |
export DIS_VER=`jq -r ".system.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
41 |
|
|
42 |
if [ $DIS_TYPE != debian ] ; then |
|
43 |
pr_error "ERROR: Distro type in configure is not debian" |
|
44 |
exit ; |
|
45 |
fi |
|
46 |
|
|
47 |
if [[ $BOARD =~ 6ull ]] ; then |
|
48 |
export ARCH=armhf |
|
49 |
else |
|
50 |
export ARCH=arm64 |
|
51 |
fi |
|
52 |
|
|
53 |
export ROOTFS_DIR=rootfs-$DIS_TYPE-$DIS_VER |
|
54 |
|
|
55 |
echo "" |
a83af1
|
56 |
pr_info "INFO: Start debootstrap fetch debian $DIS_VER($ARCH) root filesystem now." |
98ec0b
|
57 |
} |
G |
58 |
|
|
59 |
# Debian 12 depends on the new keyring |
|
60 |
# https://packages.debian.org/sid/all/debian-archive-keyring/download |
|
61 |
function update_keyring() |
|
62 |
{ |
|
63 |
debname=debian-archive-keyring |
|
64 |
debversion=2023.3 |
|
65 |
|
|
66 |
set +e |
|
67 |
dpkg -l $debname > /dev/null 2>&1 |
|
68 |
if [ $? == 0 ] ; then |
|
69 |
dpkg -s debian-archive-keyring | grep Version: | grep $debversion > /dev/null 2>&1 |
|
70 |
if [ $? != 0 ] ; then |
|
71 |
pr_info "updating $debname" |
|
72 |
apt purge -y $debname |
|
73 |
else |
|
74 |
pr_info "$debname is latest" |
|
75 |
return; |
|
76 |
fi |
|
77 |
fi |
|
78 |
set -e |
|
79 |
|
|
80 |
pr_info "install $debname now" |
|
81 |
wget http://ftp.us.debian.org/debian/pool/main/d/$debname/${debname}_${debversion}_all.deb > /dev/null |
|
82 |
dpkg -i ${debname}_${debversion}_all.deb |
|
83 |
rm -f ${debname}_${debversion}_all.deb |
|
84 |
} |
|
85 |
|
|
86 |
function do_install() |
|
87 |
{ |
|
88 |
pr_warn "\ninstall system tools" |
|
89 |
|
|
90 |
update_keyring |
|
91 |
|
|
92 |
debootstrap --version > /dev/null 2>&1 |
|
93 |
if [ $? == 0 ] ; then |
|
94 |
pr_info "system tools installed already" |
|
95 |
return ; |
|
96 |
fi |
|
97 |
|
|
98 |
apt install binfmt-support qemu qemu-user-static debootstrap |
|
99 |
} |
|
100 |
|
|
101 |
function do_fetch() |
|
102 |
{ |
|
103 |
pr_warn "\ndebootstrap fetch" |
|
104 |
|
|
105 |
if [ -f ${ROOTFS_DIR}/bin/bash ] ; then |
|
106 |
pr_info "debain rootfs fetched already" |
|
107 |
return ; |
|
108 |
fi |
a83af1
|
109 |
|
98ec0b
|
110 |
debootstrap --arch=${ARCH} --foreign ${DIS_VER} ${ROOTFS_DIR} http://ftp.debian.org/debian/ |
G |
111 |
|
|
112 |
cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/ |
|
113 |
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} debootstrap/debootstrap --second-stage |
|
114 |
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} dpkg --configure -a |
|
115 |
rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static |
|
116 |
} |
|
117 |
|
|
118 |
function modify_rootfs() |
|
119 |
{ |
|
120 |
pr_warn "\nmodify rootfs environment" |
|
121 |
|
|
122 |
# update hostnmae and issue |
|
123 |
BOARD=igkboard |
|
124 |
echo $BOARD > ${ROOTFS_DIR}/etc/hostname |
|
125 |
echo "Debian GNU/Linux $VERSION \n \l, default password '$DEF_PASSWD'" > ${ROOTFS_DIR}/etc/issue |
|
126 |
|
|
127 |
# update dns server |
|
128 |
echo "nameserver 223.5.5.5" > ${ROOTFS_DIR}/etc/resolv.conf |
|
129 |
echo "nameserver 114.114.114.114" >> ${ROOTFS_DIR}/etc/resolv.conf |
|
130 |
|
|
131 |
# update NTP server |
|
132 |
sed -i "s|^#NTP=.*|NTP=pool.ntp.org|g" ${ROOTFS_DIR}/etc/systemd/timesyncd.conf |
|
133 |
|
|
134 |
set +e |
|
135 |
# add ls alias for display with color |
|
136 |
grep "color=auto" ${ROOTFS_DIR}/etc/profile > /dev/null 2>&1 |
|
137 |
if [ $? != 0 ] ; then |
|
138 |
echo "alias ls='ls --color=auto'" >> ${ROOTFS_DIR}/etc/profile |
|
139 |
fi |
|
140 |
|
|
141 |
grep "^PermitRootLogin" ${ROOTFS_DIR}/etc/ssh/sshd_config > /dev/null 2>&1 |
|
142 |
if [ $? != 0 ] ; then |
|
143 |
echo "PermitRootLogin yes" >> ${ROOTFS_DIR}/etc/ssh/sshd_config |
|
144 |
fi |
|
145 |
set -e |
|
146 |
} |
|
147 |
|
|
148 |
function do_conf() |
|
149 |
{ |
|
150 |
EXTRA_APPS="vim net-tools network-manager tree file parted locales lsb-release tzdata wireless-tools openssh-server systemd-timesyncd" |
|
151 |
|
|
152 |
pr_warn "\ndebootstrap configure" |
|
153 |
|
|
154 |
cp -f /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/ |
|
155 |
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} apt update |
|
156 |
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} apt install -y ${EXTRA_APPS} |
|
157 |
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${ROOTFS_DIR} sh -c "echo root:${DEF_PASSWD} | chpasswd" |
|
158 |
rm -f ${ROOTFS_DIR}/usr/bin/qemu-arm-static |
|
159 |
|
|
160 |
modify_rootfs |
|
161 |
} |
|
162 |
|
|
163 |
function do_pack() |
|
164 |
{ |
|
165 |
pr_warn "\npackage $ROOTFS_DIR" |
|
166 |
|
|
167 |
cd $PRJ_PATH/$ROOTFS_DIR |
|
168 |
tar -cJf ../$ROOTFS_DIR.tar.xz * |
|
169 |
} |
|
170 |
|
|
171 |
#+-------------------------+ |
|
172 |
#| Shell script body start | |
|
173 |
#+-------------------------+ |
|
174 |
|
|
175 |
if [ `id -u` != 0 ] ; then |
|
176 |
pr_error "ERRROR: This shell script must excuted as root privilege." |
|
177 |
exit 0; |
|
178 |
fi |
|
179 |
|
|
180 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
181 |
pr_warn "start clean debian rootfs" |
|
182 |
rm -rf rootfs-debian-* |
|
183 |
exit; |
|
184 |
fi |
|
185 |
|
|
186 |
export_env |
|
187 |
|
|
188 |
do_install |
|
189 |
|
|
190 |
do_fetch |
|
191 |
|
|
192 |
do_conf |
|
193 |
|
|
194 |
do_pack |