From a969be49a2c2bf9159e5c2e9ac64291b56d5a07f Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Thu, 20 Jun 2013 16:47:22 +1200 Subject: [PATCH] Move functions to common-functions for reuse. Change-Id: I12a5687d94df678d7f7e8c0b075ee4aba1082156 --- bin/ramdisk-image-create | 2 +- lib/common-functions | 41 ++++++++++++++++++++++++++++++++++++++++ lib/img-functions | 40 --------------------------------------- lib/ramdisk-functions | 2 +- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/bin/ramdisk-image-create b/bin/ramdisk-image-create index 65f590af..24894f97 100755 --- a/bin/ramdisk-image-create +++ b/bin/ramdisk-image-create @@ -87,7 +87,7 @@ TMP_MOUNT_PATH=$TMP_BUILD_DIR/mnt echo "working in $TMP_MOUNT_PATH" -create_base +create_ramdisk_base populate_lib populate_busybox populate_init diff --git a/lib/common-functions b/lib/common-functions index 7d8fc6a5..bf431b61 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -187,3 +187,44 @@ function arg_to_elements() { echo "Expanded element dependencies to: $IMAGE_ELEMENT" } + +function create_base () { + mkdir $TMP_BUILD_DIR/mnt + export TMP_MOUNT_PATH=$TMP_BUILD_DIR/mnt + # Copy data in to the root. + TARGET_ROOT=$TMP_MOUNT_PATH run_d root + if [ -z "$(ls $TMP_MOUNT_PATH | grep -v lost+found)" ] ; then + # Nothing copied in, use Ubuntu. + echo "Adding ubuntu element as / had no contents" + IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT ubuntu) + generate_hooks + echo "Now building: $IMAGE_ELEMENT" + TARGET_ROOT=$TMP_MOUNT_PATH run_d root + fi + + # Configure Image + # Setup resolv.conf so we can chroot to install some packages + if [ -L $TMP_MOUNT_PATH/etc/resolv.conf ] || [ -f $TMP_MOUNT_PATH/etc/resolv.conf ] ; then + sudo mv $TMP_MOUNT_PATH/etc/resolv.conf $TMP_MOUNT_PATH/etc/resolv.conf.ORIG + fi + + # Recreate resolv.conf + sudo touch $TMP_MOUNT_PATH/etc/resolv.conf + sudo chmod 777 $TMP_MOUNT_PATH/etc/resolv.conf + # use system configured resolv.conf if available to support internal proxy resolving + if [ -e /etc/resolv.conf ] + then + cat /etc/resolv.conf > $TMP_MOUNT_PATH/etc/resolv.conf + else + echo nameserver 8.8.8.8 > $TMP_MOUNT_PATH/etc/resolv.conf + fi + mount_proc_dev_sys +} + +function mount_proc_dev_sys () { + # supporting kernel file systems + sudo mount -t proc none $TMP_MOUNT_PATH/proc + sudo mount --bind /dev $TMP_MOUNT_PATH/dev + sudo mount -t sysfs none $TMP_MOUNT_PATH/sys +} + diff --git a/lib/img-functions b/lib/img-functions index 65414365..ca95c44e 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -53,46 +53,6 @@ function ensure_sudo () { sudo echo "Ensuring sudo is available" } -function create_base () { - mkdir $TMP_BUILD_DIR/mnt - export TMP_MOUNT_PATH=$TMP_BUILD_DIR/mnt - # Copy data in to the root. - TARGET_ROOT=$TMP_MOUNT_PATH run_d root - if [ -z "$(ls $TMP_MOUNT_PATH | grep -v lost+found)" ] ; then - # Nothing copied in, use Ubuntu. - echo "Adding ubuntu element as / had no contents" - IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT ubuntu) - generate_hooks - echo "Now building: $IMAGE_ELEMENT" - TARGET_ROOT=$TMP_MOUNT_PATH run_d root - fi - - # Configure Image - # Setup resolv.conf so we can chroot to install some packages - if [ -L $TMP_MOUNT_PATH/etc/resolv.conf ] || [ -f $TMP_MOUNT_PATH/etc/resolv.conf ] ; then - sudo mv $TMP_MOUNT_PATH/etc/resolv.conf $TMP_MOUNT_PATH/etc/resolv.conf.ORIG - fi - - # Recreate resolv.conf - sudo touch $TMP_MOUNT_PATH/etc/resolv.conf - sudo chmod 777 $TMP_MOUNT_PATH/etc/resolv.conf - # use system configured resolv.conf if available to support internal proxy resolving - if [ -e /etc/resolv.conf ] - then - cat /etc/resolv.conf > $TMP_MOUNT_PATH/etc/resolv.conf - else - echo nameserver 8.8.8.8 > $TMP_MOUNT_PATH/etc/resolv.conf - fi - mount_proc_dev_sys -} - -function mount_proc_dev_sys () { - # supporting kernel file systems - sudo mount -t proc none $TMP_MOUNT_PATH/proc - sudo mount --bind /dev $TMP_MOUNT_PATH/dev - sudo mount -t sysfs none $TMP_MOUNT_PATH/sys -} - # Helper function to run a command inside the chroot function run_in_target () { # Force the inclusion of /usr/local/bin in PATH, this is needed for some diff --git a/lib/ramdisk-functions b/lib/ramdisk-functions index a2ff9c1a..ea4dfc2e 100644 --- a/lib/ramdisk-functions +++ b/lib/ramdisk-functions @@ -56,7 +56,7 @@ function ensure_binaries() { export BINARY_DEPS } -function create_base () { +function create_ramdisk_base () { echo "Creating base system" mkdir -p "$TMP_MOUNT_PATH/bin"