From 50080615000bc3c924e592a28ee03fbb422b0e86 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Thu, 8 Mar 2018 00:49:33 +0100 Subject: Move build_rootfs.sh to scripts subdir --- build.sh | 2 +- build_rootfs.sh | 144 ------------------------------------------------ scripts/build_rootfs.sh | 144 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 145 deletions(-) delete mode 100755 build_rootfs.sh create mode 100755 scripts/build_rootfs.sh diff --git a/build.sh b/build.sh index ca4cef0..d27f559 100755 --- a/build.sh +++ b/build.sh @@ -157,7 +157,7 @@ build_tarball() { export ARCH=${arch} export SUBARCH=${subarch} local opts="-m $metadata" - fakeroot ./build_rootfs.sh $rootfs $opts -o $lxc_tar --packages="${packages}" --files="${files}" + fakeroot scripts/build_rootfs.sh $rootfs $opts -o $lxc_tar --packages="${packages}" --files="${files}" } build_metadata() { diff --git a/build_rootfs.sh b/build_rootfs.sh deleted file mode 100755 index 3c30bb1..0000000 --- a/build_rootfs.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/sh - -set -e - -usage() { - echo "Usage: $0 [-o|--output ] [-p|--packages ] [-f|--files ] [-m|--metadata ] " - exit 1 -} - -dst_file=/dev/stdout - -temp=$(getopt -o "o:p:f:m:" -l "output:,packages:,files:,metadata:,help" -- "$@") -eval set -- "$temp" -while true; do - case "$1" in - -p|--packages) - packages="$2"; shift 2;; - -o|--output) - dst_file="$2"; shift 2;; - -f|--files) - files="$2"; shift 2;; - -m|--metadata) - metadata=`basename $2` - metadata_dir=`dirname $2` - shift 2;; - --help) - usage;; - --) - shift; break;; - esac -done - -if [ $# -ne 1 ]; then - usage -fi - -src_tar=$1 -base=`basename $src_tar` -dir=/tmp/build.$$ -files_dir=files/ -instroot=$dir/rootfs -cache=dl/packages/$ARCH/$SUBARCH - -test -e $cache || mkdir -p $cache -OPKG="env LD_PRELOAD= IPKG_NO_SCRIPT=1 IPKG_INSTROOT=$instroot $SDK/staging_dir/host/bin/opkg -o $instroot --cache $cache" - -unpack() { - mkdir -p $instroot - cat $src_tar | (cd $instroot && tar -xz) -} - -pack() { - echo Pack rootfs - if test -n "$metadata"; then - (cd $dir && tar -cz *) > $dst_file - else - (cd $dir/rootfs && tar -cz *) > $dst_file - fi -} - -pack_squashfs() { - echo Pack rootfs squashfs - mksquashfs $dir $dst_file -} - -disable_root() { - sed -i -e 's/^root::/root:*:/' $instroot/etc/shadow -} - -add_file() { - file=$1 - src_dir=$2 - dst_dir=$3 - - src=$src_dir/$file - dst=$dst_dir/$file - - if test -d $src; then - test -d $dst || mkdir -p $dst - elif test -f $src; then - cp $src $dst - foo=$(dirname $file) - if [ "$foo" = "./etc/init.d" ]; then - echo Enabling $file - set +e - env IPKG_INSTROOT=$instroot sh $instroot/etc/rc.common $dst enable - set -e - fi - fi -} - -add_files() { - src_dir=$1 - dst_dir=$2 - - for f in $(cd $src_dir && find); do - add_file $f $src_dir $dst_dir - done -} - -add_package() { - local ipkg=$1 - $OPKG install $ipkg -} - -add_packages() { - local dir=$1 - for f in $dir/*.ipk; do - add_package $f - done -} - -update_packages() { - $OPKG update - local upgradable="$($OPKG list-upgradable|cut -d ' ' -f 1)" - for pkg in $upgradable; do - echo Upgrading $pkg - $OPKG upgrade $pkg - done -} - -install_packages() { - local packages="$1" - for pkg in $packages; do - echo Install $pkg - $OPKG install $pkg - done -} - -unpack -disable_root -if test -n "$metadata"; then - add_file $metadata $metadata_dir $dir -fi -add_files templates/ $dir/templates/ -add_packages bin/packages/${ARCH}/${SUBARCH} -update_packages -install_packages "$packages" -add_files $files_dir $instroot -if test -n "$files"; then - add_files $files $instroot -fi -pack -#pack_squashfs diff --git a/scripts/build_rootfs.sh b/scripts/build_rootfs.sh new file mode 100755 index 0000000..3c30bb1 --- /dev/null +++ b/scripts/build_rootfs.sh @@ -0,0 +1,144 @@ +#!/bin/sh + +set -e + +usage() { + echo "Usage: $0 [-o|--output ] [-p|--packages ] [-f|--files ] [-m|--metadata ] " + exit 1 +} + +dst_file=/dev/stdout + +temp=$(getopt -o "o:p:f:m:" -l "output:,packages:,files:,metadata:,help" -- "$@") +eval set -- "$temp" +while true; do + case "$1" in + -p|--packages) + packages="$2"; shift 2;; + -o|--output) + dst_file="$2"; shift 2;; + -f|--files) + files="$2"; shift 2;; + -m|--metadata) + metadata=`basename $2` + metadata_dir=`dirname $2` + shift 2;; + --help) + usage;; + --) + shift; break;; + esac +done + +if [ $# -ne 1 ]; then + usage +fi + +src_tar=$1 +base=`basename $src_tar` +dir=/tmp/build.$$ +files_dir=files/ +instroot=$dir/rootfs +cache=dl/packages/$ARCH/$SUBARCH + +test -e $cache || mkdir -p $cache +OPKG="env LD_PRELOAD= IPKG_NO_SCRIPT=1 IPKG_INSTROOT=$instroot $SDK/staging_dir/host/bin/opkg -o $instroot --cache $cache" + +unpack() { + mkdir -p $instroot + cat $src_tar | (cd $instroot && tar -xz) +} + +pack() { + echo Pack rootfs + if test -n "$metadata"; then + (cd $dir && tar -cz *) > $dst_file + else + (cd $dir/rootfs && tar -cz *) > $dst_file + fi +} + +pack_squashfs() { + echo Pack rootfs squashfs + mksquashfs $dir $dst_file +} + +disable_root() { + sed -i -e 's/^root::/root:*:/' $instroot/etc/shadow +} + +add_file() { + file=$1 + src_dir=$2 + dst_dir=$3 + + src=$src_dir/$file + dst=$dst_dir/$file + + if test -d $src; then + test -d $dst || mkdir -p $dst + elif test -f $src; then + cp $src $dst + foo=$(dirname $file) + if [ "$foo" = "./etc/init.d" ]; then + echo Enabling $file + set +e + env IPKG_INSTROOT=$instroot sh $instroot/etc/rc.common $dst enable + set -e + fi + fi +} + +add_files() { + src_dir=$1 + dst_dir=$2 + + for f in $(cd $src_dir && find); do + add_file $f $src_dir $dst_dir + done +} + +add_package() { + local ipkg=$1 + $OPKG install $ipkg +} + +add_packages() { + local dir=$1 + for f in $dir/*.ipk; do + add_package $f + done +} + +update_packages() { + $OPKG update + local upgradable="$($OPKG list-upgradable|cut -d ' ' -f 1)" + for pkg in $upgradable; do + echo Upgrading $pkg + $OPKG upgrade $pkg + done +} + +install_packages() { + local packages="$1" + for pkg in $packages; do + echo Install $pkg + $OPKG install $pkg + done +} + +unpack +disable_root +if test -n "$metadata"; then + add_file $metadata $metadata_dir $dir +fi +add_files templates/ $dir/templates/ +add_packages bin/packages/${ARCH}/${SUBARCH} +update_packages +install_packages "$packages" +add_files $files_dir $instroot +if test -n "$files"; then + add_files $files $instroot +fi +pack +#pack_squashfs -- cgit v1.2.3