Blame mpackage.sh

2d011a
#!/bin/sh
2d011a
2d011a
usage()
2d011a
{
2d011a
	cat << EOF
2d011a
2d011a
USAGE:
2d011a
  --target  TARGEET            target triplet
2d011a
  --subset  SUBSET             the name of a file containing a list of packages
2d011a
                               to be added to the distribution; otherwise,
2d011a
                               the name of a project-provided subset; multiple
2d011a
                               subsets are allowed and may overlap in one or
2d011a
                               more packages
2d011a
2d011a
  --minroot MINIPIX_ROOT       location of the top-level minipix directory
2d011a
  --objroot OBJECT_ROOT        location of the top-level object directory
2d011a
2d011a
  --usrpkgs USER_PKGS          a folder containing user-provided distribution tarballs
2d011a
  --usrdata USER_DATA          a folder containing user-provided installation files
2d011a
2d011a
  --tmproot TEMPORARY_ROOT     where temporary files should be created
2d011a
  --pkgroot PACKAGE_ROOT       where package tarballs should be created
2d011a
  --sysroot SYSTEM_ROOT        where the live distribution should be created
2d011a
2d011a
  --zipfile ZIPFILE_NAME       name of the zipfile to be created (optional)
2d011a
6436cb
  --symbols                    do not strip PE binaries (distro)
6436cb
  --flysyms                    do not strip PE binaries (live environment)
6436cb
6e8f88
  --defroot                    default location to which the distribution should
6e8f88
                                       be installed (substitutes @sysroot@)
6e8f88
  --product                    name of the distribution to be installed
6e8f88
                                       (substitutes @product@)
acd2fc
  --radmins                    provide members of the builtin administrators group
acd2fc
                                       with root-like access to the sysroot directory
acd2fc
                                       (substitutes @radmins@)
6e8f88
2d011a
EOF
2d011a
	exit 1
2d011a
}
2d011a
2d011a
error_msg()
2d011a
{
2d011a
	echo $@ >&2
2d011a
	exit 2
2d011a
}
2d011a
2d011a
init_vars()
2d011a
{
2d011a
	# project
2d011a
	mb_project_dir=$(cd `dirname $0` ; pwd)
2d011a
	mb_pwd=`pwd`
2d011a
2d011a
	# subsets
2d011a
	mb_subset=
2d011a
	mb_subsets=
2d011a
	mb_pkglist=
2d011a
2d011a
	# target
2d011a
	mb_target=$TARGET
2d011a
2d011a
	# midipix_build directories
2d011a
	mb_minroot=$MINIPIX_ROOT
2d011a
	mb_objroot=$OBJECT_ROOT
2d011a
2d011a
	# user directories
2d011a
	mb_usrpkgs=$USER_PKGS
2d011a
	mb_usrdata=$USER_DATA
2d011a
2d011a
	# mpackage directories
2d011a
	mb_tmproot=$TEMPORARY_ROOT
2d011a
	mb_pkgroot=$PACKAGE_ROOT
2d011a
	mb_sysroot=$SYSTEM_ROOT
2d011a
6436cb
	# symbols
6436cb
	mb_symbols='no'
6436cb
	mb_flysyms='no'
6436cb
6e8f88
	# setup
6e8f88
	mb_defroot=@sysroot@
6e8f88
	mb_product=@product@
acd2fc
	mb_radmins='no'
6e8f88
2d011a
	# and voila
2d011a
	mb_zipfile=$ZIPFILE_NAME
2d011a
}
2d011a
2d011a
validate_args()
2d011a
{
2d011a
	[ -z "$mb_target" ]  && error_msg "!! target not set, quitting..."
2d011a
2d011a
	[ -z "$mb_minroot" ] && error_msg "!! minroot not set, quitting..."
2d011a
	[ -z "$mb_objroot" ] && error_msg "!! objroot not set, quitting..."
2d011a
2d011a
	[ -z "$mb_tmproot" ] && error_msg "!! tmproot not set, quitting..."
2d011a
	[ -z "$mb_pkgroot" ] && error_msg "!! pkgroot not set, quitting..."
2d011a
	[ -z "$mb_sysroot" ] && error_msg "!! sysroot not set, quitting..."
2d011a
2d011a
2d011a
	if ! [ -d "$mb_minroot" ]; then
2d011a
		error_msg "!! $mb_minroot: minroot directory not found, quitting..."
2d011a
	fi
2d011a
2d011a
	if ! [ -d "$mb_objroot" ]; then
2d011a
		error_msg "!! $mb_objroot: objroot directory not found, quitting..."
2d011a
	fi
2d011a
2d011a
94baf9
	if ! [ -z "$mb_usrpkgs" ] && ! [ -d "$mb_usrpkgs" ]; then
2d011a
		error_msg "!! $mb_usrpkgs: usrpkgs directory does not exist, quitting..."
2d011a
	fi
2d011a
94baf9
	if ! [ -z "$mb_usrdata" ] && ! [ -d "$mb_usrdata" ]; then
2d011a
		error_msg "!! $mb_usrdata: usrdata directory does not exist, quitting..."
2d011a
	fi
2d011a
2d011a
	if ! [ -z "$mb_zipfile" ] && ! [ -d `dirname "$mb_zipfile"` ]; then
2d011a
		error_msg "!! $mb_zipfile: zipfile directory does not exist, quitting..."
2d011a
	fi
2d011a
2d011a
2d011a
	if [ -d "$mb_tmproot" ]; then
2d011a
		error_msg "!! $mb_tmproot: tmproot directory already exists, quitting..."
2d011a
	fi
2d011a
2d011a
	if [ -d "$mb_pkgroot" ]; then
2d011a
		error_msg "!! $mb_pkgroot: pkgroot directory already exists, quitting..."
2d011a
	fi
2d011a
2d011a
	if [ -d "$mb_sysroot" ]; then
2d011a
		error_msg "!! $mb_sysroot: sysroot directory already exists, quitting..."
2d011a
	fi
2d011a
}
2d011a
2d011a
init_dirs()
2d011a
{
2d011a
	mkdir "$mb_tmproot" || exit 2
2d011a
	mkdir "$mb_pkgroot" || exit 2
2d011a
	mkdir "$mb_sysroot" || exit 2
2d011a
2d011a
	mb_minroot=$(cd "$mb_minroot" ; pwd)
2d011a
	mb_objroot=$(cd "$mb_objroot" ; pwd)
2d011a
2d011a
	mb_tmproot=$(cd "$mb_tmproot" ; pwd)
2d011a
	mb_pkgroot=$(cd "$mb_pkgroot" ; pwd)
2d011a
	mb_sysroot=$(cd "$mb_sysroot" ; pwd)
2d011a
2d011a
	if ! [ -z "$mb_usrpkgs" ]; then
2d011a
		mb_usrpkgs=$(cd "$mb_usrpkgs" ; pwd)
2d011a
	fi
2d011a
2d011a
	if ! [ -z "$mb_usrpkgs" ]; then
2d011a
		mb_usrdata=$(cd "$mb_usrdata" ; pwd)
2d011a
	fi
2d011a
2d011a
	if ! [ -z "$mb_zipfile" ]; then
2d011a
		mb_zipdir=$(cd `dirname "$mb_zipfile"` ; pwd)
2d011a
		mb_zipbase=`basename "$mb_zipfile"`
2d011a
		mb_zipfile="$mb_zipdir/$mb_zipbase"
2d011a
	fi
2d011a
}
2d011a
2d011a
init_pkglist()
2d011a
{
2d011a
	if [ -z "$mb_subsets" ]; then
2d011a
		mb_pkglist=''
2d011a
	else
2d011a
		mb_srclist=''
2d011a
2d011a
		for subset in $mb_subsets; do
2d011a
			if [ -f $subset ]; then
2d011a
				mb_srclist="$mb_srclist $subset"
2d011a
			elif [ -f "$mb_project_dir/subset/$subset" ]; then
2d011a
				mb_srclist="$mb_srclist $mb_project_dir/subset/$subset"
2d011a
			else
2d011a
				error_msg "!! $subset: subset not found, quitting..."
2d011a
			fi
2d011a
		done
2d011a
2d011a
		mb_pkglist=`cat $mb_srclist | grep -v '#' | sort --unique`
2d011a
2d011a
		echo "$mb_pkglist"
2d011a
	fi
2d011a
}
2d011a
6436cb
strip_symbols()
6436cb
{
6436cb
	( perk -y $f 2>/dev/null | grep -v '\-obj\-' >/dev/null ) \
6436cb
		&& ( strip $1 || exit 2 )
6436cb
}
6436cb
6e8f88
gen_setup()
6e8f88
{
6e8f88
	pkgdir="$mb_tmproot/once"
6e8f88
	objdir="$mb_project_dir/once"
6e8f88
6e8f88
	cp  -av "$objdir" "$pkgdir"     || exit 2
6e8f88
	cd "$pkgdir"                    || exit 2
6e8f88
6e8f88
	for f in $(find -type f); do
6e8f88
		sed -e 's#@sysroot@#'"$mb_defroot"'#g' \
6e8f88
		    -e 's#@product@#'"$mb_product"'#g' \
acd2fc
		    -e 's#@radmins@#'"$mb_radmins"'#g' \
60b4ac
		    -e 's#@SYSROOT@#'"@sysroot@"'#g'   \
6e8f88
		   $f  >  $f.tmp        || exit 2
57fadf
57fadf
		cat $f.tmp > $f         || exit 2
57fadf
		rm $f.tmp               || exit 2
6e8f88
	done
6e8f88
}
6e8f88
2d011a
gen_tarballs()
2d011a
{
2d011a
	for pkg in $mb_pkglist; do
2d011a
		pkgdir="$mb_tmproot/$pkg"
2d011a
		objdir="$mb_objroot/$pkg-native-$mb_target/destdir"
2d011a
2d011a
		cp  -av "$objdir" "$pkgdir"           || exit 2
2d011a
		cd "$pkgdir"                          || exit 2
6436cb
6436cb
		for f in $(find -type f); do
6436cb
			if [ $mb_symbols = 'no' ]; then
6436cb
				strip_symbols $f
6436cb
			fi
6436cb
		done
6436cb
2d011a
		tar -cvzf "$mb_pkgroot/$pkg.tar.gz" * || exit 2
2d011a
	done
2d011a
2d011a
	# common, distro
2d011a
	for pkg in common distro; do
2d011a
		cd "$mb_project_dir/$pkg"
2d011a
		tar -cvzf "$mb_pkgroot/$pkg.tar.gz" * || exit 2
2d011a
	done
2d011a
}
2d011a
2d011a
gen_sysroot()
2d011a
{
2d011a
	# layout
2d011a
	mkdir "$mb_sysroot/tarballs"    || exit 2
2d011a
	mkdir "$mb_sysroot/updates"     || exit 2
2d011a
2d011a
	# minipix
2d011a
	cd "$mb_minroot"                || exit 2
2d011a
	cp -av * "$mb_sysroot"          || exit 2
6436cb
	cd "$mb_sysroot"                || exit 2
6436cb
6436cb
	for f in $(find -type f); do
6436cb
		if [ $mb_flysyms = 'no' ]; then
6436cb
			strip_symbols $f
6436cb
		fi
6436cb
	done
2d011a
2d011a
	# common
2d011a
	cd "$mb_project_dir/common"     || exit 2
2d011a
	cp -av * "$mb_sysroot"          || exit 2
2d011a
2d011a
	# once
6e8f88
	cd "$mb_tmproot/once"           || exit 2
2d011a
	cp -av * "$mb_sysroot"          || exit 2
2d011a
2d011a
	# tarballs
2d011a
	cd "$mb_pkgroot"                || exit 2
2d011a
	cp -av * "$mb_sysroot/tarballs" || exit 2
2d011a
2d011a
	# user packages
2d011a
	if ! [ -z "$mb_usrpkgs" ]; then
2d011a
		cd "$mb_usrpkgs"                || exit 2
2d011a
		cp -av * "$mb_sysroot/tarballs" || exit 2
2d011a
	fi
2d011a
2d011a
	# user installation scripts
2d011a
	if ! [ -z "$mb_usrdata" ]; then
2d011a
		cd "$mb_usrdata"                || exit 2
2d011a
		cp -av * "$mb_sysroot"          || exit 2
2d011a
	fi
2d011a
}
2d011a
2d011a
gen_zipfile()
2d011a
{
2d011a
	if [ -z "$mb_zipfile" ]; then
2d011a
		return 0
2d011a
	fi
2d011a
2d011a
	cd "$mb_sysroot"         || exit 2
2d011a
	zip -rv9 "$mb_zipfile" * || exit 2
2d011a
}
2d011a
2d011a
# one: vars
2d011a
init_vars
2d011a
2d011a
# two: args
2d011a
for arg ; do
2d011a
	case "$arg" in
2d011a
		--help)	usage
2d011a
			;;
2d011a
		--target=*)
2d011a
			mb_target=${arg#*=}
2d011a
			;;
2d011a
		--minroot=*)
2d011a
			mb_minroot=${arg#*=}
2d011a
			;;
2d011a
		--objroot=*)
2d011a
			mb_objroot=${arg#*=}
2d011a
			;;
2d011a
		--usrpkgs=*)
2d011a
			mb_usrpkgs=${arg#*=}
2d011a
			;;
2d011a
		--usrdata=*)
2d011a
			mb_usrdata=${arg#*=}
2d011a
			;;
2d011a
		--tmproot=*)
2d011a
			mb_tmproot=${arg#*=}
2d011a
			;;
2d011a
		--pkgroot=*)
2d011a
			mb_pkgroot=${arg#*=}
2d011a
			;;
2d011a
		--sysroot=*)
2d011a
			mb_sysroot=${arg#*=}
2d011a
			;;
2d011a
		--zipfile=*)
2d011a
			mb_zipfile=${arg#*=}
2d011a
			;;
6e8f88
		--defroot=*)
6e8f88
			mb_defroot=${arg#*=}
6e8f88
			;;
6e8f88
		--product=*)
6e8f88
			mb_product=${arg#*=}
6e8f88
			;;
6436cb
		--symbols)
6436cb
			mb_symbols='yes'
6436cb
			;;
6436cb
		--flysyms)
6436cb
			mb_flysyms='yes'
6436cb
			;;
acd2fc
		--radmins)
acd2fc
			mb_radmins='yes'
acd2fc
			;;
2d011a
		--subset=*)
2d011a
			mb_subset=${arg#*=}
2d011a
			mb_subsets="$mb_subsets $mb_subset"
2d011a
			;;
2d011a
		*)
2d011a
			error_msg ${arg#}: "unsupported script argument."
2d011a
			exit 2
2d011a
			;;
2d011a
	esac
2d011a
done
2d011a
2d011a
# three: sanity
2d011a
validate_args
2d011a
2d011a
# four:  dirs, package list
2d011a
init_dirs
2d011a
init_pkglist
2d011a
6e8f88
# five:  tarballs, sysroot, setup
6e8f88
gen_setup
2d011a
gen_tarballs
2d011a
gen_sysroot
2d011a
2d011a
# six:   zipfile
2d011a
gen_zipfile
2d011a
2d011a
# all done
2d011a
exit 0