forked from Loongson-Cloud-Community/docker-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkimage-ocs.sh
executable file
·187 lines (158 loc) · 5.33 KB
/
mkimage-ocs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh
#
# for AnolisOS 23
# create rootfs.tar from repository
#
#set -x
set -e
arch=loongarch64
#release=$1
releasever=23
version=23
if [ -z $version ]
then
echo "releasever or version is empty!!!"
exit 1
fi
output="opencloudos-${version}.rootfs.${arch}.tar.gz"
repos_baseos_url="http://10.130.0.6/opencloudos-stream/RPMS/"
#repos_baseos_url_1="http://10.130.0.6/opencloudos-stream/euler/"
#repos_baseos_url_2="http://10.130.0.6/opencloudos-stream/python"
trap cleanup TERM EXIT
work_dir=$(mktemp -d $(pwd)/rootfs-image.XXXXXX)
rootfs=${work_dir}/rootfs
repo_dir="${work_dir}/yum.repo.d"
repo_conf="${repo_dir}/AnolisOS.repo"
setting_scripts=setting.sh
pkg_list="
basesystem bash ca-certificates opencloudos-stream-release
opencloudos-stream-repos chkconfig cracklib crypto-policies dnf passwd
expat gawk glib2 gdbm gmp gnupg2 gpgme grep ima-evm-utils
json-c mpfr ncurses-base procps git findutils dnf-plugins-core
npth p11-kit p11-kit-trust pcre pcre2 popt readline rootfiles
sed setup systemd systemd-libs tzdata util-linux xz yum vim-minimal
"
#pkg_list="
# acl basesystem bash ca-certificates anolis-gpg-keys anolis-release
# anolis-repos chkconfig cracklib crypto-policies dnf
# expat gawk gdbm glib2 glibc gmp gnupg2 gpgme grep ima-evm-utils
# ipcalc iputils json-c kexec-tools kmod langpacks-en less lzo mpfr ncurses-base
# npth p11-kit p11-kit-trust pam pcre pcre2 popt procps-ng readline rootfiles
# rpm sed setup systemd-libs tzdata util-linux vim-minimal xz yum
#"
####################################################################
cleanup()
{
rm -rf ${work_dir}
}
####################################################################
mkdir -pv ${rootfs} || :
mkdir -pv ${repo_dir} || :
####################################################################
# gen repos conf
####################################################################
cat > ${repo_conf} << EOF
[baseos]
name=AnolisOS-$releasever
baseurl=${repos_baseos_url}
gpgcheck=0
enabled=1
priority=1
excludepkgs="${exclude_pkgs}"
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-LOONGNIX
#[baseos-1]
#name=AnolisOS-$releasever-1
#baseurl=${repos_baseos_url_1}
#gpgcheck=0
#enabled=1
#priority=1
#excludepkgs="${exclude_pkgs}"
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-LOONGNIX
#[baseos-2]
#name=AnolisOS-$releasever-2
#baseurl=${repos_baseos_url_2}
#gpgcheck=0
#enabled=1
#priority=1
#excludepkgs="${exclude_pkgs}"
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-LOONGNIX
EOF
####################################################################
####################################################################
DNF_OPTS="\
--setopt=install_weak_deps=False \
--setopt=reposdir=${repo_dir} \
--releasever=${releasever} \
--installroot=${rootfs} \
--nodocs"
echo "Install packages : $pkg_list"
rpmdb --root=${rootfs} --initdb
dnf ${DNF_OPTS} makecache --refresh
dnf ${DNF_OPTS} -y install ${pkg_list}
####################################################################
####################################################################
cat > ${rootfs}/${setting_scripts} << EOF
#!/bin/bash
## config TERM is linux
echo 'export TERM=linux' >> etc/bash.bashrc
echo 'container' > /etc/dnf/vars/infra
#Generate installtime file record
/bin/date +%Y%m%d_%H%M > /etc/BUILDTIME
# Limit languages to help reduce size.
LANG="en_US"
echo "%_install_langs $LANG" > /etc/rpm/macros.image-language-conf
echo "LANG=en_US.UTF-8" > /etc/locale.conf
pushd /usr/share/locale > /dev/null
ls | egrep -x -v "en|en@arabic|en@boldquot|en@cyrillic|en@greek|en@hebrew|en@piglatin|en@quot|en@shaw|en_CA|en_GB|en_US|locale.alias" | xargs rm -rf
popd > /dev/null
# systemd fixes
:> /etc/machine-id
systemd-tmpfiles --create --boot
# mask mounts and login bits
systemctl mask systemd-logind.service getty.target console-getty.service
systemctl mask sys-fs-fuse-connections.mount systemd-remount-fs.service dev-hugepages.mount
# Remove things we don't need
yum clean all > /dev/null
rm -rf /etc/udev/hwdb.bin
rm -rf /usr/lib/udev/hwdb.d/
rm -rf /boot
rm -rf /var/lib/dnf/history.*
rm -rf /usr/src/
rm -rf /home/*
rm -rf /var/log/*
rm -rf /var/cache/*
rm -rf /var/lib/yum/*
## Introduced by binutils
rm -rf /usr/bin/gdb
rm -f \$0
###########################################################################
EOF
####################################################################
chmod +x ${rootfs}/${setting_scripts}
chroot ${rootfs} /${setting_scripts}
##解决在rootfs中su命令没有权限问题
#file_list="fingerprint-auth password-auth postlogin smartcard-auth system-auth user-profile"
#for file in ${file_list}
#do
# chroot ${rootfs} authselect create-profile ${file}
# chroot ${rootfs} ln -s /etc/authselect/custom/${file} /etc/pam.d/${file}
#done
##解决在chroot中/dev/null没有权限问题
chroot ${rootfs} rm -rf /dev/null
chroot ${rootfs} mknod /dev/null c 1 3
chroot ${rootfs} chmod 666 /dev/null
cur_dir=$(pwd)
pushd ${rootfs} > /dev/null
if [ -e "${cur_dir}/${output}" ]; then
echo "Remove old ${output}"
rm -rf "${cur_dir}/${output}"
fi
echo "Generating ${output} ...."
# tar --numeric-owner --exclude='dev/*' -acf "${cur_dir}/${output}" .
tar --numeric-owner -acf "${cur_dir}/${output}" .
popd > /dev/null
echo "Generating ${output} md5sum...."
sync && md5sum ${output} > ${output}.md5
######################################
sync && echo -e "\n^^^^^^ done ^^^^^^^^^^\n"
######################################