|
@@ -7,84 +7,86 @@ smallyes() {
|
|
|
while echo "$YES" 2>/dev/null; do :; done
|
|
|
}
|
|
|
|
|
|
+########## functions for first stage ##########
|
|
|
+conditional_cp() {
|
|
|
+ if [ ! -e "$2/$1" ]; then
|
|
|
+ if [ -L "$1" ] && [ -e "$1" ]; then
|
|
|
+ cat "$1" >"$2/$1"
|
|
|
+ elif [ -e "$1" ]; then
|
|
|
+ cp "$1" "$2/$1"
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+setup_merged_usr() {
|
|
|
+ link_dir="bin sbin lib lib32 lib64 libx32"
|
|
|
+ local dir
|
|
|
+ for dir in $link_dir; do
|
|
|
+ mkdir -p "$TARGET/usr/$dir"
|
|
|
+ ln -s usr/"$dir" "$TARGET/$dir"
|
|
|
+ done
|
|
|
+}
|
|
|
+
|
|
|
+extract_dpkg_deb_data() {
|
|
|
+ DEB_LIST1=/data/temp/01-kylin-rootfs-first-and-second/1.txt
|
|
|
+ # DEB_DIR=/data/temp/kylin-rootfs
|
|
|
+ if [ -f "${DEB_LIST1}" ]; then
|
|
|
+ for i in $(cat ${DEB_LIST1}); do
|
|
|
+ # i="${DEB_DIR}${i}"
|
|
|
+ i="$(dirname ${DEB_LIST1})${i}"
|
|
|
+ echo $i
|
|
|
+ dpkg-deb --fsys-tarfile $i | tar -k -xf -
|
|
|
+ done
|
|
|
+ else
|
|
|
+ echo "${DEB_LIST1} is not exist!!"
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+# Create a device node if it does not exist. By default, the mode is 666.
|
|
|
+mknod_if_needed() {
|
|
|
+ local device type major minor mode
|
|
|
+ device="$1"
|
|
|
+ type="$2"
|
|
|
+ major="$3"
|
|
|
+ minor="$4"
|
|
|
+ mode="${5:-666}"
|
|
|
+
|
|
|
+ if [ ! -e "$device" ]; then
|
|
|
+ mknod -m "$mode" "$device" "$type" "$major" "$minor"
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+setup_devices_simple() {
|
|
|
+ # The list of devices that can be created in a container comes from
|
|
|
+ # src/core/cgroup.c in the systemd source tree.
|
|
|
+ mknod_if_needed "$TARGET/dev/null" c 1 3
|
|
|
+ mknod_if_needed "$TARGET/dev/zero" c 1 5
|
|
|
+ mknod_if_needed "$TARGET/dev/full" c 1 7
|
|
|
+ mknod_if_needed "$TARGET/dev/random" c 1 8
|
|
|
+ mknod_if_needed "$TARGET/dev/urandom" c 1 9
|
|
|
+ mknod_if_needed "$TARGET/dev/tty" c 5 0
|
|
|
+ if [ ! "$CONTAINER" = "systemd-nspawn" ]; then
|
|
|
+ mknod_if_needed "$TARGET/dev/console" c 5 1
|
|
|
+ fi
|
|
|
+ # To avoid pre-exist directory causes error, specify "-p" option
|
|
|
+ mkdir -p "$TARGET/dev/pts/" "$TARGET/dev/shm/"
|
|
|
+ # Inside a container, we might not be allowed to create /dev/ptmx.
|
|
|
+ # If not, do the next best thing.
|
|
|
+ if ! mknod_if_needed "$TARGET/dev/ptmx" c 5 2; then
|
|
|
+ warning MKNOD "Could not create /dev/ptmx, falling back to symlink. This chroot will require /dev/pts mounted with ptmxmode=666"
|
|
|
+ ln -sf pts/ptmx "$TARGET/dev/ptmx"
|
|
|
+ fi
|
|
|
+ ln -sf /proc/self/fd "$TARGET/dev/fd"
|
|
|
+ ln -sf /proc/self/fd/0 "$TARGET/dev/stdin"
|
|
|
+ ln -sf /proc/self/fd/1 "$TARGET/dev/stdout"
|
|
|
+ ln -sf /proc/self/fd/2 "$TARGET/dev/stderr"
|
|
|
+}
|
|
|
+########## functions for first stage ##########
|
|
|
+
|
|
|
first_stage_setup() {
|
|
|
TARGET=$(pwd)
|
|
|
echo "TARGET=${TARGET}"
|
|
|
|
|
|
- setup_merged_usr() {
|
|
|
- link_dir="bin sbin lib lib32 lib64 libx32"
|
|
|
- local dir
|
|
|
- for dir in $link_dir; do
|
|
|
- mkdir -p "$TARGET/usr/$dir"
|
|
|
- ln -s usr/"$dir" "$TARGET/$dir"
|
|
|
- done
|
|
|
- }
|
|
|
-
|
|
|
- conditional_cp() {
|
|
|
- if [ ! -e "$2/$1" ]; then
|
|
|
- if [ -L "$1" ] && [ -e "$1" ]; then
|
|
|
- cat "$1" >"$2/$1"
|
|
|
- elif [ -e "$1" ]; then
|
|
|
- cp "$1" "$2/$1"
|
|
|
- fi
|
|
|
- fi
|
|
|
- }
|
|
|
-
|
|
|
- extract_dpkg_deb_data() {
|
|
|
- DEB_LIST1=/data/temp/01-kylin-rootfs-first-and-second/1.txt
|
|
|
- # DEB_DIR=/data/temp/kylin-rootfs
|
|
|
- if [ -f "${DEB_LIST1}" ]; then
|
|
|
- for i in $(cat ${DEB_LIST1}); do
|
|
|
- # i="${DEB_DIR}${i}"
|
|
|
- i="$(dirname ${DEB_LIST1})${i}"
|
|
|
- echo $i
|
|
|
- dpkg-deb --fsys-tarfile $i | tar -k -xf -
|
|
|
- done
|
|
|
- else
|
|
|
- echo "${DEB_LIST1} is not exist!!"
|
|
|
- fi
|
|
|
- }
|
|
|
-
|
|
|
- # Create a device node if it does not exist. By default, the mode is 666.
|
|
|
- mknod_if_needed() {
|
|
|
- local device type major minor mode
|
|
|
- device="$1"
|
|
|
- type="$2"
|
|
|
- major="$3"
|
|
|
- minor="$4"
|
|
|
- mode="${5:-666}"
|
|
|
-
|
|
|
- if [ ! -e "$device" ]; then
|
|
|
- mknod -m "$mode" "$device" "$type" "$major" "$minor"
|
|
|
- fi
|
|
|
- }
|
|
|
-
|
|
|
- setup_devices_simple() {
|
|
|
- # The list of devices that can be created in a container comes from
|
|
|
- # src/core/cgroup.c in the systemd source tree.
|
|
|
- mknod_if_needed "$TARGET/dev/null" c 1 3
|
|
|
- mknod_if_needed "$TARGET/dev/zero" c 1 5
|
|
|
- mknod_if_needed "$TARGET/dev/full" c 1 7
|
|
|
- mknod_if_needed "$TARGET/dev/random" c 1 8
|
|
|
- mknod_if_needed "$TARGET/dev/urandom" c 1 9
|
|
|
- mknod_if_needed "$TARGET/dev/tty" c 5 0
|
|
|
- if [ ! "$CONTAINER" = "systemd-nspawn" ]; then
|
|
|
- mknod_if_needed "$TARGET/dev/console" c 5 1
|
|
|
- fi
|
|
|
- # To avoid pre-exist directory causes error, specify "-p" option
|
|
|
- mkdir -p "$TARGET/dev/pts/" "$TARGET/dev/shm/"
|
|
|
- # Inside a container, we might not be allowed to create /dev/ptmx.
|
|
|
- # If not, do the next best thing.
|
|
|
- if ! mknod_if_needed "$TARGET/dev/ptmx" c 5 2; then
|
|
|
- warning MKNOD "Could not create /dev/ptmx, falling back to symlink. This chroot will require /dev/pts mounted with ptmxmode=666"
|
|
|
- ln -sf pts/ptmx "$TARGET/dev/ptmx"
|
|
|
- fi
|
|
|
- ln -sf /proc/self/fd "$TARGET/dev/fd"
|
|
|
- ln -sf /proc/self/fd/0 "$TARGET/dev/stdin"
|
|
|
- ln -sf /proc/self/fd/1 "$TARGET/dev/stdout"
|
|
|
- ln -sf /proc/self/fd/2 "$TARGET/dev/stderr"
|
|
|
- }
|
|
|
-
|
|
|
setup_merged_usr
|
|
|
|
|
|
extract_dpkg_deb_data
|
|
@@ -108,78 +110,97 @@ first_stage_setup() {
|
|
|
echo "deb http://172.29.220.242/kylin v101 main restricted universe multiverse" >"$TARGET/etc/apt/sources.list"
|
|
|
}
|
|
|
|
|
|
-second_stage() {
|
|
|
- TARGET="/"
|
|
|
-
|
|
|
- in_target_failmsg() {
|
|
|
- local code msg arg
|
|
|
- code="$1"
|
|
|
- msg="$2"
|
|
|
- arg="$3"
|
|
|
- shift
|
|
|
- shift
|
|
|
- shift
|
|
|
- if ! PATH=/sbin:/usr/sbin:/bin:/usr/bin eval "$CHROOT_CMD \"\$@\""; then
|
|
|
- echo "$code" "$msg" "$arg" >>"$TARGET/debootstrap/debootstrap.log"
|
|
|
- # Try to point user at actual failing package.
|
|
|
- msg="See %s for details"
|
|
|
- if [ -e "$TARGET/debootstrap/debootstrap.log" ]; then
|
|
|
- arg="$TARGET/debootstrap/debootstrap.log"
|
|
|
- local pkg="$(grep '^dpkg: error processing ' "$TARGET/debootstrap/debootstrap.log" | head -n 1 | sed 's/\(error processing \)\(package \|archive \)/\1/' | cut -d ' ' -f 4)"
|
|
|
- if [ -n "$pkg" ]; then
|
|
|
- msg="$msg (possibly the package $pkg is at fault)"
|
|
|
- fi
|
|
|
- else
|
|
|
- arg="the log"
|
|
|
+########## functions for second stage ##########
|
|
|
+
|
|
|
+in_target_failmsg() {
|
|
|
+ local code msg arg
|
|
|
+ code="$1"
|
|
|
+ msg="$2"
|
|
|
+ arg="$3"
|
|
|
+ shift
|
|
|
+ shift
|
|
|
+ shift
|
|
|
+ if ! PATH=/sbin:/usr/sbin:/bin:/usr/bin eval "$CHROOT_CMD \"\$@\""; then
|
|
|
+ echo "$code" "$msg" "$arg" >>"$TARGET/debootstrap/debootstrap.log"
|
|
|
+ # Try to point user at actual failing package.
|
|
|
+ msg="See %s for details"
|
|
|
+ if [ -e "$TARGET/debootstrap/debootstrap.log" ]; then
|
|
|
+ arg="$TARGET/debootstrap/debootstrap.log"
|
|
|
+ local pkg="$(grep '^dpkg: error processing ' "$TARGET/debootstrap/debootstrap.log" | head -n 1 | sed 's/\(error processing \)\(package \|archive \)/\1/' | cut -d ' ' -f 4)"
|
|
|
+ if [ -n "$pkg" ]; then
|
|
|
+ msg="$msg (possibly the package $pkg is at fault)"
|
|
|
fi
|
|
|
- echo "$code" "$msg" "$arg" >>"$TARGET/debootstrap/debootstrap.log"
|
|
|
- return 1
|
|
|
+ else
|
|
|
+ arg="the log"
|
|
|
fi
|
|
|
- return 0
|
|
|
- }
|
|
|
-
|
|
|
- in_target() {
|
|
|
- in_target_failmsg IN_TARGET_FAIL "Failure trying to run: %s" "$CHROOT_CMD $*" "$@"
|
|
|
- }
|
|
|
-
|
|
|
- debfor() {
|
|
|
- (
|
|
|
- while read pkg path; do
|
|
|
- for p in "$@"; do
|
|
|
- [ "$p" = "$pkg" ] || continue
|
|
|
- echo "$path"
|
|
|
- mylog "====== $path"
|
|
|
- done
|
|
|
- done <"$TARGET/debootstrap/debpaths"
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- x_feign_install() {
|
|
|
- local pkg="$1"
|
|
|
- local deb="$(debfor $pkg)"
|
|
|
- mylog "deb=${deb}"
|
|
|
- local ver="$(in_target dpkg-deb -f "$deb" Version)"
|
|
|
- mylog "ver=${ver}"
|
|
|
-
|
|
|
- mkdir -p "$TARGET/var/lib/dpkg/info"
|
|
|
-
|
|
|
- echo "Package: $pkg
|
|
|
+ echo "$code" "$msg" "$arg" >>"$TARGET/debootstrap/debootstrap.log"
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+in_target() {
|
|
|
+ in_target_failmsg IN_TARGET_FAIL "Failure trying to run: %s" "$CHROOT_CMD $*" "$@"
|
|
|
+}
|
|
|
+
|
|
|
+debfor() {
|
|
|
+ (
|
|
|
+ while read pkg path; do
|
|
|
+ for p in "$@"; do
|
|
|
+ [ "$p" = "$pkg" ] || continue
|
|
|
+ echo "$path"
|
|
|
+ mylog "====== $path"
|
|
|
+ done
|
|
|
+ done <"$TARGET/debootstrap/debpaths"
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+x_feign_install() {
|
|
|
+ local pkg="$1"
|
|
|
+ local deb="$(debfor $pkg)"
|
|
|
+ mylog "deb=${deb}"
|
|
|
+ local ver="$(in_target dpkg-deb -f "$deb" Version)"
|
|
|
+ mylog "ver=${ver}"
|
|
|
+
|
|
|
+ mkdir -p "$TARGET/var/lib/dpkg/info"
|
|
|
+
|
|
|
+ echo "Package: $pkg
|
|
|
Version: $ver
|
|
|
Maintainer: unknown
|
|
|
Status: install ok installed" >>"$TARGET/var/lib/dpkg/status"
|
|
|
|
|
|
- touch "$TARGET/var/lib/dpkg/info/${pkg}.list"
|
|
|
- }
|
|
|
+ touch "$TARGET/var/lib/dpkg/info/${pkg}.list"
|
|
|
+}
|
|
|
|
|
|
- x_feign_install dpkg
|
|
|
+x_core_install() {
|
|
|
+ smallyes '' | in_target dpkg --force-depends --install $(debfor "$@")
|
|
|
+}
|
|
|
|
|
|
- # x_core_install() {
|
|
|
- # dpkg --force-depends --install $(debfor "$@")
|
|
|
- # }
|
|
|
+setup_dselect_method() {
|
|
|
+ case "$1" in
|
|
|
+ apt)
|
|
|
+ mkdir -p "$TARGET/var/lib/dpkg"
|
|
|
+ echo "apt apt" >"$TARGET/var/lib/dpkg/cmethopt"
|
|
|
+ chmod 644 "$TARGET/var/lib/dpkg/cmethopt"
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ error 1 UNKNOWNDSELECT "unknown dselect method"
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+}
|
|
|
|
|
|
- x_core_install() {
|
|
|
- smallyes '' | in_target dpkg --force-depends --install $(debfor "$@")
|
|
|
- }
|
|
|
+setup_available() {
|
|
|
+ for p in "$@"; do
|
|
|
+ sed -n "/^Package: ${p}$/,/^$/p" /var/lib/apt/lists/*_Packages
|
|
|
+ done >"$TARGET/var/lib/dpkg/available"
|
|
|
+}
|
|
|
+
|
|
|
+########## functions for second stage ##########
|
|
|
+
|
|
|
+second_stage() {
|
|
|
+ TARGET="/"
|
|
|
+
|
|
|
+ x_feign_install dpkg
|
|
|
|
|
|
DEBIAN_FRONTEND=noninteractive
|
|
|
DEBCONF_NONINTERACTIVE_SEEN=true
|
|
@@ -221,28 +242,9 @@ Status: install ok installed" >>"$TARGET/var/lib/dpkg/status"
|
|
|
echo "Warning: Fake start-stop-daemon called, doing nothing" >"$TARGET/sbin/start-stop-daemon"
|
|
|
chmod 755 "$TARGET/sbin/start-stop-daemon"
|
|
|
|
|
|
- setup_dselect_method() {
|
|
|
- case "$1" in
|
|
|
- apt)
|
|
|
- mkdir -p "$TARGET/var/lib/dpkg"
|
|
|
- echo "apt apt" >"$TARGET/var/lib/dpkg/cmethopt"
|
|
|
- chmod 644 "$TARGET/var/lib/dpkg/cmethopt"
|
|
|
- ;;
|
|
|
- *)
|
|
|
- error 1 UNKNOWNDSELECT "unknown dselect method"
|
|
|
- ;;
|
|
|
- esac
|
|
|
- }
|
|
|
-
|
|
|
setup_dselect_method apt
|
|
|
|
|
|
dpkg --status-fd 8 --configure --pending --force-configure-any --force-depends 8>&1 1>&7 || echo EXITCODE $?
|
|
|
|
|
|
- setup_available() {
|
|
|
- for p in "$@"; do
|
|
|
- sed -n "/^Package: ${p}$/,/^$/p" /var/lib/apt/lists/*_Packages
|
|
|
- done >"$TARGET/var/lib/dpkg/available"
|
|
|
- }
|
|
|
-
|
|
|
setup_available $required $base
|
|
|
}
|