On Wed, Dec 09, 2020 at 09:12:03AM +0800, Wang Chenglong wrote:
the function is called by script on host. it contains get the password, download and load the docker image copy the image package to the host, create the links of vmlinuz and initrd.
Signed-off-by: Wang Chenglong 18509160991@163.com
container/docker-rootfs/common | 148 +++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100755 container/docker-rootfs/common
diff --git a/container/docker-rootfs/common b/container/docker-rootfs/common new file mode 100755 index 0000000..1d0e667 --- /dev/null +++ b/container/docker-rootfs/common @@ -0,0 +1,148 @@
local allow_docker_img_suffix docker_img_name docker_img_suffix
local $1 local $2 local $3
it's better to get paras name
allow_docker_img_suffix=('tar.xz')
docker_img_name=$(basename "$1")
docker_img_suffix=${docker_img_name##*.}
blank line here
+init_rootfs_dir() +{
[ -d "$1" ] && return
local limit_prompt_times current_prompt_time
limit_prompt_times=3
current_prompt_time=0
blank line here
while true
do
read -r -p "[WARNING] Do you want to create \"$1\"? [y|n]> " if_create
[ "$if_create" == 'y' ] && break
[ "$if_create" == 'n' ] && echo "[ERROR] User cancelled running." && exit
done
- mkdir -p $1
+}
redundant blank line
+check_passwd_file() +{
export ROOT_NEW_PASSWD=
[ -f "$1" ] || {
echo "[INFO] No password file specified and root password kept."
return
}
export ROOT_NEW_PASSWD=$(cat "$1")
+}
+load_docker_img() +{
- echo "Loading docker image..."
- docker_repos_tag=$(docker load -i $1)
- docker_name_tag=${docker_repos_tag#*:}
+}
+cp_rootfs() +{
- docker cp -a rootfs-docker:/tmp/$1 /tmp/
- cd $2
- zcat /tmp/$1 |cpio -idmv
ditto
+}
+create_get_initrd() {
echo "Creating initrd.lkp via container/dracut-initrd..."
cd "$CCI_SRC/container/dracut-initrd" || {
echo "Failed to change into $CCI_SRC/container/dracut-initrd"
exit 6
}
./run "$ROOTFS_DIR/lib/modules/$ROOTFS_KERNEL"
echo "Finding initrd.lkp under $ROOTFS_DIR/boot ..."
cd "$ROOTFS_DIR" || {
echo "Failed to change into dir \"$ROOTFS_DIR\""
exit 7
}
local initrd_lkp
initrd_lkp=$(find ./boot -name "initramfs.lkp*") && export ROOTFS_INITRD_LKP=$initrd_lkp
[ -f "$ROOTFS_INITRD_LKP" ] || {
echo "Failed to generate \"$ROOTFS_INITRD_LKP\""
exit 8
}
echo
echo "initrd_lkp: $ROOTFS_INITRD_LKP"
+}
+get_rootfs_kernel() {
echo "Finding vmlinuz under $ROOTFS_DIR/boot ..."
cd "$ROOTFS_DIR" || {
echo "Failed to change into dir \"$ROOTFS_DIR\""
exit 5
}
local vmlinuz_file vmlinuz kernel
local $1 local $2 local $3
vmlinuz_file=$(find ./boot -name "vmlinuz-*" |grep -v rescue) && export ROOTFS_VMLINUZ_FILE=$vmlinuz_file
vmlinuz=$(basename "$vmlinuz_file") && export ROOTFS_VMLINUZ=$vmlinuz
kernel=${vmlinuz:8} && export ROOTFS_KERNEL=$kernel
echo "vmlinuz: $ROOTFS_VMLINUZ_FILE"
echo "kernel: $ROOTFS_KERNEL"
+}
+create_links_vmlinuz_initrd() +{
- export ROOTFS_DIR=$1
- get_rootfs_kernel
create_get_initrd
wrong indent
echo "Creating links to initrd.lkp and vmlinuz..."
ditto
- cd $ROOTFS_DIR
- ln -fs $ROOTFS_INITRD_LKP initrd.lkp
- cd $ROOTFS_DIR/boot
ln -fs $ROOTFS_VMLINUZ vmlinuz
ditto
echo "[INFO] Create links to initrd.lkp and vmlinuz success!"
ditto
Thanks, Yong
+}
2.23.0