head	1.13;
access;
symbols
	RELENG_8_4:1.13.0.2
	RELENG_9_1_0_RELEASE:1.12.2.1.4.2
	RELENG_9_1:1.12.2.1.0.4
	RELENG_9_1_BP:1.12.2.1
	RELENG_8_3_0_RELEASE:1.11.2.2.4.1
	RELENG_8_3:1.11.2.2.0.4
	RELENG_8_3_BP:1.11.2.2
	RELENG_9_0_0_RELEASE:1.12.2.1.2.1
	RELENG_9_0:1.12.2.1.0.2
	RELENG_9_0_BP:1.12.2.1
	RELENG_9:1.12.0.2
	RELENG_9_BP:1.12
	RELENG_7_4_0_RELEASE:1.7.2.2.8.1
	RELENG_8_2_0_RELEASE:1.11.2.2.2.1
	RELENG_7_4:1.7.2.2.0.8
	RELENG_7_4_BP:1.7.2.2
	RELENG_8_2:1.11.2.2.0.2
	RELENG_8_2_BP:1.11.2.2
	RELENG_8_1_0_RELEASE:1.11.2.1.4.1
	RELENG_8_1:1.11.2.1.0.4
	RELENG_8_1_BP:1.11.2.1
	RELENG_7_3_0_RELEASE:1.7.2.2.6.1
	RELENG_7_3:1.7.2.2.0.6
	RELENG_7_3_BP:1.7.2.2
	RELENG_8_0_0_RELEASE:1.11.2.1.2.1
	RELENG_8_0:1.11.2.1.0.2
	RELENG_8_0_BP:1.11.2.1
	RELENG_8:1.11.0.2
	RELENG_8_BP:1.11
	RELENG_7_2_0_RELEASE:1.7.2.2.4.1
	RELENG_7_2:1.7.2.2.0.4
	RELENG_7_2_BP:1.7.2.2
	RELENG_7_1_0_RELEASE:1.7.2.2.2.1
	RELENG_6_4_0_RELEASE:1.1.2.1.6.1
	RELENG_7_1:1.7.2.2.0.2
	RELENG_7_1_BP:1.7.2.2
	RELENG_6_4:1.1.2.1.0.6
	RELENG_6_4_BP:1.1.2.1
	RELENG_7_0_0_RELEASE:1.7
	RELENG_6_3_0_RELEASE:1.1.2.1
	RELENG_7_0:1.7.0.4
	RELENG_7_0_BP:1.7
	RELENG_6_3:1.1.2.1.0.4
	RELENG_6_3_BP:1.1.2.1
	RELENG_7:1.7.0.2
	RELENG_7_BP:1.7
	RELENG_6_2_0_RELEASE:1.1.2.1
	RELENG_6_2:1.1.2.1.0.2
	RELENG_6_2_BP:1.1.2.1
	RELENG_6:1.1.0.2;
locks; strict;
comment	@# @;


1.13
date	2012.11.17.01.54.12;	author svnexp;	state Exp;
branches
	1.13.2.1;
next	1.12;

1.12
date	2009.11.25.19.00.30;	author julian;	state Exp;
branches
	1.12.2.1;
next	1.11;

1.11
date	2009.06.20.20.35.50;	author remko;	state Exp;
branches
	1.11.2.1;
next	1.10;

1.10
date	2008.03.20.22.36.49;	author remko;	state Exp;
branches;
next	1.9;

1.9
date	2008.03.20.12.56.49;	author remko;	state Exp;
branches;
next	1.8;

1.8
date	2008.03.08.15.41.06;	author remko;	state Exp;
branches;
next	1.7;

1.7
date	2007.08.22.18.44.59;	author remko;	state Exp;
branches
	1.7.2.1;
next	1.6;

1.6
date	2006.11.01.01.25.49;	author julian;	state Exp;
branches;
next	1.5;

1.5
date	2006.10.30.19.47.05;	author julian;	state Exp;
branches;
next	1.4;

1.4
date	2006.10.11.21.46.53;	author julian;	state Exp;
branches;
next	1.3;

1.3
date	2006.10.11.21.39.19;	author julian;	state Exp;
branches;
next	1.2;

1.2
date	2006.10.04.22.16.40;	author julian;	state Exp;
branches;
next	1.1;

1.1
date	2006.09.20.22.24.17;	author julian;	state Exp;
branches
	1.1.2.1;
next	;

1.13.2.1
date	2012.11.17.01.54.12;	author svnexp;	state dead;
branches;
next	1.13.2.2;

1.13.2.2
date	2013.03.28.13.05.59;	author svnexp;	state Exp;
branches;
next	;

1.12.2.1
date	2011.09.23.00.51.37;	author kensmith;	state Exp;
branches
	1.12.2.1.2.1
	1.12.2.1.4.1;
next	1.12.2.2;

1.12.2.2
date	2012.11.17.11.37.36;	author svnexp;	state Exp;
branches;
next	;

1.12.2.1.2.1
date	2011.11.11.04.20.22;	author kensmith;	state Exp;
branches;
next	1.12.2.1.2.2;

1.12.2.1.2.2
date	2012.11.17.08.37.33;	author svnexp;	state Exp;
branches;
next	;

1.12.2.1.4.1
date	2012.08.05.23.54.33;	author kensmith;	state Exp;
branches;
next	1.12.2.1.4.2;

1.12.2.1.4.2
date	2012.11.17.08.48.24;	author svnexp;	state Exp;
branches;
next	;

1.11.2.1
date	2009.08.03.08.13.06;	author kensmith;	state Exp;
branches
	1.11.2.1.2.1
	1.11.2.1.4.1;
next	1.11.2.2;

1.11.2.2
date	2010.10.25.06.28.19;	author julian;	state Exp;
branches
	1.11.2.2.2.1
	1.11.2.2.4.1;
next	1.11.2.3;

1.11.2.3
date	2012.11.17.10.37.15;	author svnexp;	state Exp;
branches;
next	;

1.11.2.1.2.1
date	2009.10.25.01.10.29;	author kensmith;	state Exp;
branches;
next	;

1.11.2.1.4.1
date	2010.06.14.02.09.06;	author kensmith;	state Exp;
branches;
next	;

1.11.2.2.2.1
date	2010.12.21.17.09.25;	author kensmith;	state Exp;
branches;
next	;

1.11.2.2.4.1
date	2012.03.03.06.15.13;	author kensmith;	state Exp;
branches;
next	1.11.2.2.4.2;

1.11.2.2.4.2
date	2012.11.17.08.25.48;	author svnexp;	state Exp;
branches;
next	;

1.7.2.1
date	2008.03.11.19.19.14;	author remko;	state Exp;
branches;
next	1.7.2.2;

1.7.2.2
date	2008.03.24.10.39.34;	author remko;	state Exp;
branches
	1.7.2.2.2.1
	1.7.2.2.4.1
	1.7.2.2.6.1
	1.7.2.2.8.1;
next	1.7.2.3;

1.7.2.3
date	2011.01.27.20.39.19;	author remko;	state Exp;
branches;
next	1.7.2.4;

1.7.2.4
date	2012.11.17.08.08.17;	author svnexp;	state Exp;
branches;
next	;

1.7.2.2.2.1
date	2008.11.25.02.59.29;	author kensmith;	state Exp;
branches;
next	;

1.7.2.2.4.1
date	2009.04.15.03.14.26;	author kensmith;	state Exp;
branches;
next	;

1.7.2.2.6.1
date	2010.02.10.00.26.20;	author kensmith;	state Exp;
branches;
next	;

1.7.2.2.8.1
date	2010.12.21.17.10.29;	author kensmith;	state Exp;
branches;
next	1.7.2.2.8.2;

1.7.2.2.8.2
date	2012.11.17.08.17.41;	author svnexp;	state Exp;
branches;
next	;

1.1.2.1
date	2006.09.28.21.09.07;	author julian;	state Exp;
branches
	1.1.2.1.6.1;
next	1.1.2.2;

1.1.2.2
date	2012.11.17.07.45.31;	author svnexp;	state Exp;
branches;
next	;

1.1.2.1.6.1
date	2008.10.02.02.57.24;	author kensmith;	state Exp;
branches;
next	;


desc
@@


1.13
log
@Switching exporter and resync
@
text
@#!/bin/sh -
# Copyright (c) 2006 Jean Milanez Melo <jmelo@@freebsdbrasil.com.br>
#				       <jmelo@@FreeBSD.org>
#		     Patrick Tracanelli <eksffa@@freebsdbrasil.com.br>
#
# $FreeBSD: head/tools/tools/tinybsd/tinybsd 199812 2009-11-25 19:00:30Z julian $
#set -xv
CURRENTDIR=/usr/src/tools/tools/tinybsd
if [ ! -d $CURRENTDIR ]
then
  CURRENTDIR=`pwd`
else
  cd $CURRENTDIR
fi

WORKDIR=/usr/obj/tinybsdbuild
KERNCONF=TINYBSD
BASEFILE="tinybsd.basefiles"
PORTSFILE="tinybsd.ports"
PORTSDIR=/usr/ports
DEFINSTARGS="-o 0 -g 0 -m 555"
TINYARCH=$(uname -p)

TS="=====>"

splitarg1 () {
   local IFS
   IFS='='
   set $1
   echo $1
}

splitarg2 () {
   local IFS
   IFS='='
   set $1
   echo $2
}

getargs () {
 ARGS="$*"
 for arg in $* 
 do
   ARG=`splitarg1 $arg`
   VAL=`splitarg2 $arg`
   case $ARG in
     sectors)
        SECTUNIT=$VAL
        ;;
     heads)
        TRACKCYL=$VAL 
        ;;
     spt)
        SECTRACK=$VAL
        ;;
     conf)
        CONF=$VAL
        ;;
     mfsroot)
        MFSROOT=$VAL
        ;;
     image)
        IMG=$VAL
        ;;
     batch)
        NO_PROMPTS="YES"
        ;;
     new)
        NO_READ="YES"
        ;;
     *)
         usage
         ;;
    esac
 done
}

usage () {
    echo "Woops
    Usage: $0 sectors=<size of media> [80000]
              heads=<heads according to firmware>  [4]
              spt=<sectors per track according to firmware> [32]
              conf=<configuration name> (see conf/name) [default]
              mfsroot[=<yes|no>] [no]
              image=<tinybsd image name> [tinybsd.bin]
              batch[=<anything>]  (do not ask interactively)
              new[=<anything>]  (do not read previous values)

     Examples:
    $0 sectors=65536 heads=8 spt=16 conf=wireless mfsroot=yes image=myimage.img batch

     Default values are set in the program.
     Environment values override defaults.
     Previous values override environment values but can be disabled.
     Command arguments override previous values.
     Interactive values override command arguments but can be disabled. 

     Run diskinfo(8) -v against your CF device to get correct information
     about your disk. USB keys do not need any specific geometry"
    exit 1
}

########
# Load variables from stdin (could be a file)
# Look for lines that match foo=bar
# do not run the file.. that is asking for trouble
########
loadvars () {
  while :
  do
    OIFS=$IFS
    IFS="="
    if read PART1 PART2
    then
      IFS="$OIFS"
      case "$PART1" in
      \#*)
        ;;
      "")
        ;;
      *)
        set "${PART1}"
        if [ $# = "1" ]
        then
          eval "${PART1}='${PART2}'"
        fi
        ;;
      esac
    else
      IFS="$OIFS"
      return 0
    fi
  done
}

########
# get values from the user
########
confirm_action(){
    local ANSWER
    local MESSAGE
    ANSWER=$1
    MESSAGE=$2
    if [ "$NO_PROMPTS" != "YES" ]
    then
        echo -n "$MESSAGE [$ANSWER] " > /dev/tty
        read result
        [ "$result" != "" ] && ANSWER=$result
    fi

    ANSWER=`eval "echo $ANSWER"`
    echo $ANSWER
}

########
# These are only used the VERY first time you run the program (on this machine)
########
setdefaults () {
  NO_PROMPTS=${NO_PROMPTS:-NO}
  NO_READ=${NO_READ:-NO}
  SECTUNIT=${SECTUNIT:-80000}; export SECTUNIT
  TRACKCYL=${TRACKCYL:-4}; export TRACKCYL
  SECTRACK=${SECTRACK:-32}; export SECTRACK
  CONF=${CONF:-default}; export CONF
  MFSROOT=${MFSROOT:-NO}; export MFSROOT
  IMG=${IMG:-tinybsd.bin}; export IMG

}

#######
# get ourselves set up.
# Partly by reading config files and partly from asking questions.
#######
loadconfig () {
  if [ "${NO_READ}" = "YES" ]
  then
    return
  fi

  HOSTNAME=`hostname`
  HOSTPART=${HOSTNAME%%.*}
  FILENAME=".tinybsd.${HOSTPART}.${USER}"
  FULLFILENAME=$HOME/$FILENAME

  if [ -f ${FULLFILENAME} ]
  then
    loadvars <${FULLFILENAME}
  fi

  SECTUNIT=`confirm_action "$SECTUNIT" "512 byte sectors per unit?"`
  TRACKCYL=`confirm_action "$TRACKCYL" "Tracks per cylinder?"`
  SECTRACK=`confirm_action "$SECTRACK" "Sectors per track?"`
  while :
  do
    echo "The following configurations exist:"
    ls -l conf|awk '/^d/{print "    ",$9}'|grep -v CVS
    CONF=`confirm_action "$CONF" "Configuration name?"`
    if [ ! -d "${CURRENTDIR}/conf/$CONF" ]
    then
      echo "${TS} Error: Could not find config (${CONF})"
      if [ "$NO_PROMPTS" = "YES" ]
      then
        exit 1
      fi
    else
      break
    fi
  done
  MFSROOT=`confirm_action "$MFSROOT" "Use an MFSROOT? (YES/NO)"`
  IMG=`confirm_action "$IMG" "Image file to generate?"`

# example of formatted value (NNN in this case)
#  #condition and format the number
#  if [ -z "${BUILDNUM}" ]
#  then
#    echo "Starting with build 001"
#    BUILDNUM="001"
#  else
#    BUILDNUM=`printf "%03d\n" $(($BUILDNUM))`
#  fi


}

saveconfig () {
  HOSTNAME=`hostname`
  HOSTPART=${HOSTNAME%%.*}
  FILENAME=".tinybsd.${HOSTPART}.${USER}"
  FULLFILENAME=$HOME/$FILENAME
  (
    echo "# written by tinybsd" `date` 
    echo "SECTUNIT=${SECTUNIT}"
    echo "TRACKCYL=${TRACKCYL}"
    echo "SECTRACK=${SECTRACK}"
    echo "CONF=${CONF}"
    echo "MFSROOT=${MFSROOT:-NO}"
    echo "IMG=${IMG}"
  ) >${FULLFILENAME}
}

check_alt_imgname() {
	if [ ${IMG} = 'tinybsd.bin' ]
	then
		echo "${TS} Alternative image name not set; defaulting to 'tinybsd.bin'"
	fi
}

rotate_buidlog() {
	mv -f ${HOME}/tinybsd.log ${HOME}/tinybsd.log.old
}

remove_workdir() {
	# Before removing check if there is not a mount under $WORKDIR anymore
	MOUNT_CHECK=`mount|egrep "on ${WORKDIR}"`

	if [ ! -z "${MOUNT_CHECK}" ]; then
		echo "There are mounts under the workdir (${WORKDIR}). Please umount them before running this script"
		exit 1
	else
		chflags -R noschg ${WORKDIR}
		echo "${TS} Removing "${WORKDIR}
		rm -rf ${WORKDIR}
		echo "${TS} Removing Build Kernel Directory"
		rm -rf /usr/obj/usr/src/sys/${KERNCONF}
		echo "${TS}  done."
	fi
}


prework() {
	remove_workdir
	mkdir -p ${WORKDIR}
}


create_tree() {
	echo "${TS} Creating directory hierarchy... "
	mtree -deU -f /etc/mtree/BSD.root.dist -p ${WORKDIR}
	mtree -deU -f /etc/mtree/BIND.chroot.dist -p ${WORKDIR}
	mtree -deU -f /etc/mtree/BSD.usr.dist -p ${WORKDIR}/usr
	mtree -deU -f /etc/mtree/BSD.local.dist -p ${WORKDIR}/usr/local
	mtree -deU -f /etc/mtree/BSD.var.dist -p ${WORKDIR}/var
}

copy_binaries() {
	cd ${CURRENTDIR}/conf/${CONF}

	for file in `cat ${CURRENTDIR}/conf/${CONF}/${BASEFILE} | grep -v "#" | \
		cut -f1 -d":" | sort | uniq` ; do
		echo "${TS} Copying "/${file}" to "${WORKDIR}/${file} 
		cp -fp /${file} ${WORKDIR}/${file} ;
	done
}

install_ports() {
	for portname in `cat ${CURRENTDIR}/conf/${CONF}/${PORTSFILE} | grep -v '#'` ; do
		if [ ! -d "${WORKDIR}/usr/ports" ]; then
			mkdir -p "${WORKDIR}/usr/ports"
		fi

		PNAME=`/usr/bin/basename "${portname}"`
		PORT_OPTION_FILE="/var/db/ports/${PNAME}/options"

		if [ -f "${PORT_OPTION_FILE}" ]; then
			mkdir -p "${WORKDIR}/var/db/ports/${PNAME}"
			cp "${PORT_OPTION_FILE}" "${WORKDIR}/var/db/ports/${PNAME}/"
		fi

		mount_nullfs /lib "${WORKDIR}/lib"
		mount_nullfs /usr/bin "${WORKDIR}/usr/bin"
		mount_nullfs /usr/sbin "${WORKDIR}/usr/sbin"
		mount_nullfs /usr/ports "${WORKDIR}/usr/ports"
		mount_nullfs /usr/share "${WORKDIR}/usr/share"
		mount_nullfs /usr/libexec "${WORKDIR}/usr/libexec"
		mount_nullfs /usr/lib "${WORKDIR}/usr/lib"
		mount_nullfs /usr/include "${WORKDIR}/usr/include"

		cd ${PORTSDIR}/${portname}
		make fetch-recursive
		make DESTDIR_ENV_LIST=PATH DESTDIR="${WORKDIR}" install
		make clean

		umount "${WORKDIR}/lib"
		umount "${WORKDIR}/usr/ports"
		umount "${WORKDIR}/usr/bin"
		umount "${WORKDIR}/usr/sbin"
		umount "${WORKDIR}/usr/share"
		umount "${WORKDIR}/usr/libexec"
		umount "${WORKDIR}/usr/lib"
		umount "${WORKDIR}/usr/include"
	done
}

make_kernel() {
	echo "${TS} Building customized tiny beastie kernel... "
	cp -p ${CURRENTDIR}/conf/${CONF}/${KERNCONF} /usr/src/sys/${TINYARCH}/conf
	cd /usr/src
	make buildkernel KERNCONF=${KERNCONF} || exit 1
	gzip -9 /usr/obj/usr/src/sys/${KERNCONF}/kernel
	install ${DEFINSTARGS} /usr/obj/usr/src/sys/${KERNCONF}/kernel.gz ${WORKDIR}/boot/kernel/
	install ${DEFINSTARGS} \
	  /usr/obj/usr/src/sys/${KERNCONF}/modules/usr/src/sys/modules/acpi/acpi/acpi.ko \
	    ${WORKDIR}/boot/kernel
	install -o 0 -g 0 -m 444 /sys/${TINYARCH}/conf/GENERIC.hints ${WORKDIR}/boot/device.hints
}

copy_libraries() {
	TDEPFILE="`mktemp -t deps`"
	TDEPFILES="`mktemp -t depsymlnk`"

	find "${WORKDIR}" -type f |while read file; do
		ldd -f "%p\n" ${file} >> ${TDEPFILE} ; # don't worry on progs been "not dynamic"
	done

	for libdeplib in `cat ${TDEPFILE} | sort | uniq`; do
		ldd -f "%p\n" /${libdeplib} >> ${TDEPFILE} ;
	done

	for pamdep in `ls -1 /usr/lib/pam*`; do
		echo $pamdep >> ${TDEPFILE} ;
		ldd -f "%p\n" /${pamdep} >> ${TDEPFILE} ;
	done	

	for lib in `cat ${TDEPFILE} | sort | uniq`; do
		echo "${TS} Copying "${lib}" to "${WORKDIR}${lib}
		cp -fp ${lib} ${WORKDIR}${lib} ;
	done

	for depsymlink in `cat ${TDEPFILE}`; do
		echo "${TS} Checking if ${depsymlink} is a symbolic link"
		/bin/ls -l $depsymlink | grep "\->" | awk '{print $11":"$9}' >> ${TDEPFILES}
	done

	for i in `cat ${TDEPFILES}`; do
                SOURCE_FILE=`echo $i | awk -F ":" '{print $1}'`
                TARGET_FILE=`echo $i | awk -F ":" '{print $2}'`

		echo "${TS} Unlinking ${WORKDIR}${TARGET_FILE}"
		chroot ${WORKDIR} /bin/chflags 0 ${TARGET_FILE}
                chroot ${WORKDIR} /bin/rm -f ${TARGET_FILE}

		echo "${TS} Symlinking ${SOURCE_FILE} to ${TARGET_FILE}"
                chroot ${WORKDIR} /bin/ln -s ${SOURCE_FILE} ${TARGET_FILE}
        done

	echo -n "${TS} Unlinking "
	rm -fv ${TDEPFILE} ${TDEPFILES}
}

create_etc() {
	cd /usr/src/etc/sendmail/
	make freebsd.cf freebsd.submit.cf

	cd /usr/src/etc/
	mkdir -p ${WORKDIR}/var/named/etc/namedb
	make distribution DESTDIR=${WORKDIR} || exit 1
}

create_ssh_keys() {
	echo "Creating ssh keys..."
	ssh-keygen -t rsa1 -b 1024  -f ${WORKDIR}/etc/ssh/ssh_host_key -N ''
	ssh-keygen -t dsa -f ${WORKDIR}/etc/ssh/ssh_host_dsa_key -N ''
	ssh-keygen -t rsa -f ${WORKDIR}/etc/ssh/ssh_host_rsa_key -N ''
}

personal_conf() {
	echo "${TS} Copying your custom configuration on conf/ ..."
	for custom in `find ${CURRENTDIR}/conf/${CONF}/ -type d -depth 1 \! -name CVS`; do
		cp -Rp ${custom}/* ${WORKDIR}/${custom#${CURRENTDIR}/conf/${CONF}/}/
	done

	if [ -f ${CURRENTDIR}/conf/${CONF}/boot.config ]; then
		cp ${CURRENTDIR}/conf/${CONF}/boot.config ${WORKDIR}/boot.config
	fi
}

symlinks() {
#set -xv
	for i in `cat ${CURRENTDIR}/conf/${CONF}/${BASEFILE}| grep -v "#" | grep ":"`; do
		SOURCE_FILE=`echo $i | awk -F ":" {'print $1'}`
		TARGET_FILE=`echo $i | awk -F ":" {'print $2'}`
		chroot ${WORKDIR} /bin/ln -vs /${SOURCE_FILE} ${TARGET_FILE}
	done
#set +xv
}


create_image() {
	VNODEFILE=`mktemp -t tinybsd`
	IMGMNT=`mktemp -d -t tinybsd`

	dd if=/dev/zero of=${VNODEFILE} count=${SECTUNIT}

	MD=`mdconfig -a -t vnode -f ${VNODEFILE} -x ${SECTRACK} -y ${TRACKCYL}`

	diskinfo -v /dev/${MD}

	fdisk -I /dev/${MD}
	fdisk /dev/${MD}

	cp -p /boot/boot0 ${WORKDIR}/boot/boot0
	bsdlabel -w -B /dev/${MD}
	newfs -O2 -U /dev/${MD}a

	mount /dev/${MD}a ${IMGMNT}

	if [ ${MFSROOT} = 'yes' ]
	then
		echo "${TS} Creating MFS root..."
		# Update is not done yet
		#mkdir -p ${WORKDIR}/usr/local/bin/
		#cp -p ${CURRENTDIR}/update/update ${WORKDIR}/usr/local/bin/
		rm ${WORKDIR}/etc/fstab
		cd ${WORKDIR} && find . -print | sed '/kernel/ d' | cpio -dump ${IMGMNT} || true
		umount ${IMGMNT}
		dd if=/dev/${MD} of=${CURRENTDIR}/mfsroot.img		
		gzip -9 < ${CURRENTDIR}/mfsroot.img > ${CURRENTDIR}/mfsroot.gz
		rm ${CURRENTDIR}/mfsroot.img
		mount /dev/${MD}a ${IMGMNT}
		rm -rf ${IMGMNT}/*
		cp -rp ${WORKDIR}/boot ${IMGMNT}
		rm ${IMGMNT}/boot/device.hints
		( \
		echo 'set vfs.root.mountfrom="ufs:/dev/md0a"' ; \
		echo 'set bootfile="/boot/kernel/kernel"' ; \
		sed -e  '/^#/ d' -e 's/^/set /' < ${WORKDIR}/boot/device.hints ; \
		echo 'load /boot/kernel/kernel' ; \
		echo 'echo Loading mfsroot' ; \
		echo 'load -t mfs_root /mfsroot' ;\
		echo 'boot' ; \
		) > ${IMGMNT}/boot/loader.rc
		mv ${CURRENTDIR}/mfsroot.gz ${IMGMNT}
	else
		( cd ${WORKDIR} && find . -print | cpio -dump ${IMGMNT} ) || true
	fi

	df ${IMGMNT}
	sleep 1
	umount ${IMGMNT}

	dd if=/dev/${MD} of=${CURRENTDIR}/${IMG} bs=64k

	rm -vf ${VNODEFILE}
	rm -rvf ${IMGMNT}
	mdconfig -d -u ${MD}
	echo ""
	echo "${TS} Done!"
	echo "${TS} Your configuration options were saved in ${FULLFILENAME}"
	echo "${TS} You can see your build log in ${HOME}/tinybsd.log"
	echo "${TS} Your final image is in ${CURRENTDIR}/${IMG}"
	echo "${TS} Now use dd(1) to write it."
}

##########################
# run things

##########################################
## The actual program
##########################################
getargs $*
setdefaults
# Load as many of the configuration options as we can
loadconfig
saveconfig

# Rotate build log
rotate_buidlog

# Now start logging.
(
  # Do the build
  prework
  check_alt_imgname
  create_tree
  copy_binaries
  create_etc
  install_ports
  make_kernel
  copy_libraries
  symlinks
  create_ssh_keys
  personal_conf
  create_image
#set +xv
) 2>&1 |tee -a  ${HOME}/tinybsd.log

@


1.13.2.1
log
@file tinybsd was added on branch RELENG_8_4 on 2013-03-28 13:05:59 +0000
@
text
@d1 526
@


1.13.2.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248810
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 526
#!/bin/sh -
# Copyright (c) 2006 Jean Milanez Melo <jmelo@@freebsdbrasil.com.br>
#				       <jmelo@@FreeBSD.org>
#		     Patrick Tracanelli <eksffa@@freebsdbrasil.com.br>
#
# $FreeBSD: releng/8.4/tools/tools/tinybsd/tinybsd 214317 2010-10-25 06:28:19Z julian $
#set -xv
CURRENTDIR=/usr/src/tools/tools/tinybsd
if [ ! -d $CURRENTDIR ]
then
  CURRENTDIR=`pwd`
else
  cd $CURRENTDIR
fi

WORKDIR=/usr/obj/tinybsdbuild
KERNCONF=TINYBSD
BASEFILE="tinybsd.basefiles"
PORTSFILE="tinybsd.ports"
PORTSDIR=/usr/ports
DEFINSTARGS="-o 0 -g 0 -m 555"
TINYARCH=$(uname -p)

TS="=====>"

splitarg1 () {
   local IFS
   IFS='='
   set $1
   echo $1
}

splitarg2 () {
   local IFS
   IFS='='
   set $1
   echo $2
}

getargs () {
 ARGS="$*"
 for arg in $* 
 do
   ARG=`splitarg1 $arg`
   VAL=`splitarg2 $arg`
   case $ARG in
     sectors)
        SECTUNIT=$VAL
        ;;
     heads)
        TRACKCYL=$VAL 
        ;;
     spt)
        SECTRACK=$VAL
        ;;
     conf)
        CONF=$VAL
        ;;
     mfsroot)
        MFSROOT=$VAL
        ;;
     image)
        IMG=$VAL
        ;;
     batch)
        NO_PROMPTS="YES"
        ;;
     new)
        NO_READ="YES"
        ;;
     *)
         usage
         ;;
    esac
 done
}

usage () {
    echo "Woops
    Usage: $0 sectors=<size of media> [80000]
              heads=<heads according to firmware>  [4]
              spt=<sectors per track according to firmware> [32]
              conf=<configuration name> (see conf/name) [default]
              mfsroot[=<yes|no>] [no]
              image=<tinybsd image name> [tinybsd.bin]
              batch[=<anything>]  (do not ask interactively)
              new[=<anything>]  (do not read previous values)

     Examples:
    $0 sectors=65536 heads=8 spt=16 conf=wireless mfsroot=yes image=myimage.img batch

     Default values are set in the program.
     Environment values override defaults.
     Previous values override environment values but can be disabled.
     Command arguments override previous values.
     Interactive values override command arguments but can be disabled. 

     Run diskinfo(8) -v against your CF device to get correct information
     about your disk. USB keys do not need any specific geometry"
    exit 1
}

########
# Load variables from stdin (could be a file)
# Look for lines that match foo=bar
# do not run the file.. that is asking for trouble
########
loadvars () {
  while :
  do
    OIFS=$IFS
    IFS="="
    if read PART1 PART2
    then
      IFS="$OIFS"
      case "$PART1" in
      \#*)
        ;;
      "")
        ;;
      *)
        set "${PART1}"
        if [ $# = "1" ]
        then
          eval "${PART1}='${PART2}'"
        fi
        ;;
      esac
    else
      IFS="$OIFS"
      return 0
    fi
  done
}

########
# get values from the user
########
confirm_action(){
    local ANSWER
    local MESSAGE
    ANSWER=$1
    MESSAGE=$2
    if [ "$NO_PROMPTS" != "YES" ]
    then
        echo -n "$MESSAGE [$ANSWER] " > /dev/tty
        read result
        [ "$result" != "" ] && ANSWER=$result
    fi

    ANSWER=`eval "echo $ANSWER"`
    echo $ANSWER
}

########
# These are only used the VERY first time you run the program (on this machine)
########
setdefaults () {
  NO_PROMPTS=${NO_PROMPTS:-NO}
  NO_READ=${NO_READ:-NO}
  SECTUNIT=${SECTUNIT:-80000}; export SECTUNIT
  TRACKCYL=${TRACKCYL:-4}; export TRACKCYL
  SECTRACK=${SECTRACK:-32}; export SECTRACK
  CONF=${CONF:-default}; export CONF
  MFSROOT=${MFSROOT:-NO}; export MFSROOT
  IMG=${IMG:-tinybsd.bin}; export IMG

}

#######
# get ourselves set up.
# Partly by reading config files and partly from asking questions.
#######
loadconfig () {
  if [ "${NO_READ}" = "YES" ]
  then
    return
  fi

  HOSTNAME=`hostname`
  HOSTPART=${HOSTNAME%%.*}
  FILENAME=".tinybsd.${HOSTPART}.${USER}"
  FULLFILENAME=$HOME/$FILENAME

  if [ -f ${FULLFILENAME} ]
  then
    loadvars <${FULLFILENAME}
  fi

  SECTUNIT=`confirm_action "$SECTUNIT" "512 byte sectors per unit?"`
  TRACKCYL=`confirm_action "$TRACKCYL" "Tracks per cylinder?"`
  SECTRACK=`confirm_action "$SECTRACK" "Sectors per track?"`
  while :
  do
    echo "The following configurations exist:"
    ls -l conf|awk '/^d/{print "    ",$9}'|grep -v CVS
    CONF=`confirm_action "$CONF" "Configuration name?"`
    if [ ! -d "${CURRENTDIR}/conf/$CONF" ]
    then
      echo "${TS} Error: Could not find config (${CONF})"
      if [ "$NO_PROMPTS" = "YES" ]
      then
        exit 1
      fi
    else
      break
    fi
  done
  MFSROOT=`confirm_action "$MFSROOT" "Use an MFSROOT? (YES/NO)"`
  IMG=`confirm_action "$IMG" "Image file to generate?"`

# example of formatted value (NNN in this case)
#  #condition and format the number
#  if [ -z "${BUILDNUM}" ]
#  then
#    echo "Starting with build 001"
#    BUILDNUM="001"
#  else
#    BUILDNUM=`printf "%03d\n" $(($BUILDNUM))`
#  fi


}

saveconfig () {
  HOSTNAME=`hostname`
  HOSTPART=${HOSTNAME%%.*}
  FILENAME=".tinybsd.${HOSTPART}.${USER}"
  FULLFILENAME=$HOME/$FILENAME
  (
    echo "# written by tinybsd" `date` 
    echo "SECTUNIT=${SECTUNIT}"
    echo "TRACKCYL=${TRACKCYL}"
    echo "SECTRACK=${SECTRACK}"
    echo "CONF=${CONF}"
    echo "MFSROOT=${MFSROOT:-NO}"
    echo "IMG=${IMG}"
  ) >${FULLFILENAME}
}

check_alt_imgname() {
	if [ ${IMG} = 'tinybsd.bin' ]
	then
		echo "${TS} Alternative image name not set; defaulting to 'tinybsd.bin'"
	fi
}

rotate_buidlog() {
	mv -f ${HOME}/tinybsd.log ${HOME}/tinybsd.log.old
}

remove_workdir() {
	# Before removing check if there is not a mount under $WORKDIR anymore
	MOUNT_CHECK=`mount|egrep "on ${WORKDIR}"`

	if [ ! -z "${MOUNT_CHECK}" ]; then
		echo "There are mounts under the workdir (${WORKDIR}). Please umount them before running this script"
		exit 1
	else
		chflags -R noschg ${WORKDIR}
		echo "${TS} Removing "${WORKDIR}
		rm -rf ${WORKDIR}
		echo "${TS} Removing Build Kernel Directory"
		rm -rf /usr/obj/usr/src/sys/${KERNCONF}
		echo "${TS}  done."
	fi
}


prework() {
	remove_workdir
	mkdir -p ${WORKDIR}
}


create_tree() {
	echo "${TS} Creating directory hierarchy... "
	mtree -deU -f /etc/mtree/BSD.root.dist -p ${WORKDIR}
	mtree -deU -f /etc/mtree/BIND.chroot.dist -p ${WORKDIR}
	mtree -deU -f /etc/mtree/BSD.usr.dist -p ${WORKDIR}/usr
	mtree -deU -f /etc/mtree/BSD.local.dist -p ${WORKDIR}/usr/local
	mtree -deU -f /etc/mtree/BSD.var.dist -p ${WORKDIR}/var
}

copy_binaries() {
	cd ${CURRENTDIR}/conf/${CONF}

	for file in `cat ${CURRENTDIR}/conf/${CONF}/${BASEFILE} | grep -v "#" | \
		cut -f1 -d":" | sort | uniq` ; do
		echo "${TS} Copying "/${file}" to "${WORKDIR}/${file} 
		cp -fp /${file} ${WORKDIR}/${file} ;
	done
}

install_ports() {
	for portname in `cat ${CURRENTDIR}/conf/${CONF}/${PORTSFILE} | grep -v '#'` ; do
		if [ ! -d "${WORKDIR}/usr/ports" ]; then
			mkdir -p "${WORKDIR}/usr/ports"
		fi

		PNAME=`/usr/bin/basename "${portname}"`
		PORT_OPTION_FILE="/var/db/ports/${PNAME}/options"

		if [ -f "${PORT_OPTION_FILE}" ]; then
			mkdir -p "${WORKDIR}/var/db/ports/${PNAME}"
			cp "${PORT_OPTION_FILE}" "${WORKDIR}/var/db/ports/${PNAME}/"
		fi

		mount_nullfs /lib "${WORKDIR}/lib"
		mount_nullfs /usr/bin "${WORKDIR}/usr/bin"
		mount_nullfs /usr/sbin "${WORKDIR}/usr/sbin"
		mount_nullfs /usr/ports "${WORKDIR}/usr/ports"
		mount_nullfs /usr/share "${WORKDIR}/usr/share"
		mount_nullfs /usr/libexec "${WORKDIR}/usr/libexec"
		mount_nullfs /usr/lib "${WORKDIR}/usr/lib"
		mount_nullfs /usr/include "${WORKDIR}/usr/include"

		cd ${PORTSDIR}/${portname}
		make fetch-recursive
		make DESTDIR_ENV_LIST=PATH DESTDIR="${WORKDIR}" install
		make clean

		umount "${WORKDIR}/lib"
		umount "${WORKDIR}/usr/ports"
		umount "${WORKDIR}/usr/bin"
		umount "${WORKDIR}/usr/sbin"
		umount "${WORKDIR}/usr/share"
		umount "${WORKDIR}/usr/libexec"
		umount "${WORKDIR}/usr/lib"
		umount "${WORKDIR}/usr/include"
	done
}

make_kernel() {
	echo "${TS} Building customized tiny beastie kernel... "
	cp -p ${CURRENTDIR}/conf/${CONF}/${KERNCONF} /usr/src/sys/${TINYARCH}/conf
	cd /usr/src
	make buildkernel KERNCONF=${KERNCONF} || exit 1
	gzip -9 /usr/obj/usr/src/sys/${KERNCONF}/kernel
	install ${DEFINSTARGS} /usr/obj/usr/src/sys/${KERNCONF}/kernel.gz ${WORKDIR}/boot/kernel/
	install ${DEFINSTARGS} \
	  /usr/obj/usr/src/sys/${KERNCONF}/modules/usr/src/sys/modules/acpi/acpi/acpi.ko \
	    ${WORKDIR}/boot/kernel
	install -o 0 -g 0 -m 444 /sys/${TINYARCH}/conf/GENERIC.hints ${WORKDIR}/boot/device.hints
}

copy_libraries() {
	TDEPFILE="`mktemp -t deps`"
	TDEPFILES="`mktemp -t depsymlnk`"

	find "${WORKDIR}" -type f |while read file; do
		ldd -f "%p\n" ${file} >> ${TDEPFILE} ; # don't worry on progs been "not dynamic"
	done

	for libdeplib in `cat ${TDEPFILE} | sort | uniq`; do
		ldd -f "%p\n" /${libdeplib} >> ${TDEPFILE} ;
	done

	for pamdep in `ls -1 /usr/lib/pam*`; do
		echo $pamdep >> ${TDEPFILE} ;
		ldd -f "%p\n" /${pamdep} >> ${TDEPFILE} ;
	done	

	for lib in `cat ${TDEPFILE} | sort | uniq`; do
		echo "${TS} Copying "${lib}" to "${WORKDIR}${lib}
		cp -fp ${lib} ${WORKDIR}${lib} ;
	done

	for depsymlink in `cat ${TDEPFILE}`; do
		echo "${TS} Checking if ${depsymlink} is a symbolic link"
		/bin/ls -l $depsymlink | grep "\->" | awk '{print $11":"$9}' >> ${TDEPFILES}
	done

	for i in `cat ${TDEPFILES}`; do
                SOURCE_FILE=`echo $i | awk -F ":" '{print $1}'`
                TARGET_FILE=`echo $i | awk -F ":" '{print $2}'`

		echo "${TS} Unlinking ${WORKDIR}${TARGET_FILE}"
		chroot ${WORKDIR} /bin/chflags 0 ${TARGET_FILE}
                chroot ${WORKDIR} /bin/rm -f ${TARGET_FILE}

		echo "${TS} Symlinking ${SOURCE_FILE} to ${TARGET_FILE}"
                chroot ${WORKDIR} /bin/ln -s ${SOURCE_FILE} ${TARGET_FILE}
        done

	echo -n "${TS} Unlinking "
	rm -fv ${TDEPFILE} ${TDEPFILES}
}

create_etc() {
	cd /usr/src/etc/sendmail/
	make freebsd.cf freebsd.submit.cf

	cd /usr/src/etc/
	mkdir -p ${WORKDIR}/var/named/etc/namedb
	make distribution DESTDIR=${WORKDIR} || exit 1
}

create_ssh_keys() {
	echo "Creating ssh keys..."
	ssh-keygen -t rsa1 -b 1024  -f ${WORKDIR}/etc/ssh/ssh_host_key -N ''
	ssh-keygen -t dsa -f ${WORKDIR}/etc/ssh/ssh_host_dsa_key -N ''
	ssh-keygen -t rsa -f ${WORKDIR}/etc/ssh/ssh_host_rsa_key -N ''
}

personal_conf() {
	echo "${TS} Copying your custom configuration on conf/ ..."
	for custom in `find ${CURRENTDIR}/conf/${CONF}/ -type d -depth 1 \! -name CVS`; do
		cp -Rp ${custom}/* ${WORKDIR}/${custom#${CURRENTDIR}/conf/${CONF}/}/
	done

	if [ -f ${CURRENTDIR}/conf/${CONF}/boot.config ]; then
		cp ${CURRENTDIR}/conf/${CONF}/boot.config ${WORKDIR}/boot.config
	fi
}

symlinks() {
#set -xv
	for i in `cat ${CURRENTDIR}/conf/${CONF}/${BASEFILE}| grep -v "#" | grep ":"`; do
		SOURCE_FILE=`echo $i | awk -F ":" {'print $1'}`
		TARGET_FILE=`echo $i | awk -F ":" {'print $2'}`
		chroot ${WORKDIR} /bin/ln -vs /${SOURCE_FILE} ${TARGET_FILE}
	done
#set +xv
}


create_image() {
	VNODEFILE=`mktemp -t tinybsd`
	IMGMNT=`mktemp -d -t tinybsd`

	dd if=/dev/zero of=${VNODEFILE} count=${SECTUNIT}

	MD=`mdconfig -a -t vnode -f ${VNODEFILE} -x ${SECTRACK} -y ${TRACKCYL}`

	diskinfo -v /dev/${MD}

	fdisk -I /dev/${MD}
	fdisk /dev/${MD}

	cp -p /boot/boot0 ${WORKDIR}/boot/boot0
	bsdlabel -w -B /dev/${MD}
	newfs -O2 -U /dev/${MD}a

	mount /dev/${MD}a ${IMGMNT}

	if [ ${MFSROOT} = 'yes' ]
	then
		echo "${TS} Creating MFS root..."
		# Update is not done yet
		#mkdir -p ${WORKDIR}/usr/local/bin/
		#cp -p ${CURRENTDIR}/update/update ${WORKDIR}/usr/local/bin/
		rm ${WORKDIR}/etc/fstab
		cd ${WORKDIR} && find . -print | sed '/kernel/ d' | cpio -dump ${IMGMNT} || true
		umount ${IMGMNT}
		dd if=/dev/${MD} of=${CURRENTDIR}/mfsroot.img		
		gzip -9 < ${CURRENTDIR}/mfsroot.img > ${CURRENTDIR}/mfsroot.gz
		rm ${CURRENTDIR}/mfsroot.img
		mount /dev/${MD}a ${IMGMNT}
		rm -rf ${IMGMNT}/*
		cp -rp ${WORKDIR}/boot ${IMGMNT}
		rm ${IMGMNT}/boot/device.hints
		( \
		echo 'set vfs.root.mountfrom="ufs:/dev/md0a"' ; \
		echo 'set bootfile="/boot/kernel/kernel"' ; \
		sed -e  '/^#/ d' -e 's/^/set /' < ${WORKDIR}/boot/device.hints ; \
		echo 'load /boot/kernel/kernel' ; \
		echo 'echo Loading mfsroot' ; \
		echo 'load -t mfs_root /mfsroot' ;\
		echo 'boot' ; \
		) > ${IMGMNT}/boot/loader.rc
		mv ${CURRENTDIR}/mfsroot.gz ${IMGMNT}
	else
		( cd ${WORKDIR} && find . -print | cpio -dump ${IMGMNT} ) || true
	fi

	df ${IMGMNT}
	sleep 1
	umount ${IMGMNT}

	dd if=/dev/${MD} of=${CURRENTDIR}/${IMG} bs=64k

	rm -vf ${VNODEFILE}
	rm -rvf ${IMGMNT}
	mdconfig -d -u ${MD}
	echo ""
	echo "${TS} Done!"
	echo "${TS} Your configuration options were saved in ${FULLFILENAME}"
	echo "${TS} You can see your build log in ${HOME}/tinybsd.log"
	echo "${TS} Your final image is in ${CURRENTDIR}/${IMG}"
	echo "${TS} Now use dd(1) to write it."
}

##########################
# run things

##########################################
## The actual program
##########################################
getargs $*
setdefaults
# Load as many of the configuration options as we can
loadconfig
saveconfig

# Rotate build log
rotate_buidlog

# Now start logging.
(
  # Do the build
  prework
  check_alt_imgname
  create_tree
  copy_binaries
  create_etc
  install_ports
  make_kernel
  copy_libraries
  symlinks
  create_ssh_keys
  personal_conf
  create_image
#set +xv
) 2>&1 |tee -a  ${HOME}/tinybsd.log

@


1.12
log
@SVN rev 199812 on 2009-11-25 19:00:30Z by julian

exit if "make distribition" fails

Submitted by:	patrick tracanelli
MFC after:	1 week
@
text
@d6 1
a6 1
# $FreeBSD$
@


1.12.2.1
log
@SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.12.2.2
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242902
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242902 | dteske | 2012-11-11 23:29:45 +0000 (Sun, 11 Nov 2012) | 10 lines
## SVN ##
## SVN ## Fix a regression introduced by SVN r211417 that saw the breakage of a feature
## SVN ## documented in usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## Reviewed by:	adrian (co-mentor)
## SVN ## Approved by:	adrian (co-mentor)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d6 1
a6 1
# $FreeBSD: stable/9/tools/tools/tinybsd/tinybsd 199812 2009-11-25 19:00:30Z julian $
@


1.12.2.1.4.1
log
@SVN rev 239080 on 2012-08-05 23:54:33Z by kensmith

Copy stable/9 to releng/9.1 as part of the 9.1-RELEASE release process.

Approved by:	re (implicit)
@
text
@@


1.12.2.1.4.2
log
@Switch importer
@
text
@d6 1
a6 1
# $FreeBSD: releng/9.1/tools/tools/tinybsd/tinybsd 199812 2009-11-25 19:00:30Z julian $
@


1.12.2.1.2.1
log
@SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)
@
text
@@


1.12.2.1.2.2
log
@Switch importer
@
text
@d6 1
a6 1
# $FreeBSD: releng/9.0/tools/tools/tinybsd/tinybsd 199812 2009-11-25 19:00:30Z julian $
@


1.11
log
@SVN rev 194558 on 2009-06-20 20:35:50Z by remko

Add architecture support for TinyBSD

PR:		135301
Submitted by:	Olivier Cochard-Labbe <olivier at cochard dot me>
Reviewed by:	Jean Milanez Melo <jmelo at freebsdbrasil dot com dot br> (maintainer)
Approved by:	imp (mentor, implicit)
MFC after:	1 week
@
text
@d396 1
a396 1
	make distribution DESTDIR=${WORKDIR}
@


1.11.2.1
log
@SVN rev 196045 on 2009-08-03 08:13:06Z by kensmith

Copy head to stable/8 as part of 8.0 Release cycle.

Approved by:	re (Implicit)
@
text
@@


1.11.2.2
log
@SVN rev 214317 on 2010-10-25 06:28:19Z by julian

MFC of 199812
allow tinybsd to abort of a step fails.
@
text
@d396 1
a396 1
	make distribution DESTDIR=${WORKDIR} || exit 1
@


1.11.2.3
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242909
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242909 | dim | 2012-11-12 07:47:19 +0000 (Mon, 12 Nov 2012) | 20 lines
## SVN ##
## SVN ## MFC r242625:
## SVN ##
## SVN ## Remove duplicate const specifiers in many drivers (I hope I got all of
## SVN ## them, please let me know if not).  Most of these are of the form:
## SVN ##
## SVN ## static const struct bzzt_type {
## SVN ##       [...list of members...]
## SVN ## } const bzzt_devs[] = {
## SVN ##       [...list of initializers...]
## SVN ## };
## SVN ##
## SVN ## The second const is unnecessary, as arrays cannot be modified anyway,
## SVN ## and if the elements are const, the whole thing is const automatically
## SVN ## (e.g. it is placed in .rodata).
## SVN ##
## SVN ## I have verified this does not change the binary output of a full kernel
## SVN ## build (except for build timestamps embedded in the object files).
## SVN ##
## SVN ## Reviewed by:	yongari, marius
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d6 1
a6 1
# $FreeBSD: stable/8/tools/tools/tinybsd/tinybsd 214317 2010-10-25 06:28:19Z julian $
@


1.11.2.2.4.1
log
@SVN rev 232438 on 2012-03-03 06:15:13Z by kensmith

Copy stable/8 to releng/8.3 as part of 8.3-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.11.2.2.4.2
log
@Switch importer
@
text
@d6 1
a6 1
# $FreeBSD: releng/8.3/tools/tools/tinybsd/tinybsd 214317 2010-10-25 06:28:19Z julian $
@


1.11.2.2.2.1
log
@SVN rev 216617 on 2010-12-21 17:09:25Z by kensmith

Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.

Approved by:	re (implicit)
@
text
@@


1.11.2.1.4.1
log
@SVN rev 209145 on 2010-06-14 02:09:06Z by kensmith

Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.

Approved by:	re (implicit)
@
text
@@


1.11.2.1.2.1
log
@SVN rev 198460 on 2009-10-25 01:10:29Z by kensmith

Copy stable/8 to releng/8.0 as part of 8.0-RELEASE release procedure.

Approved by:	re (implicit)
@
text
@@


1.10
log
@The last commit was:

Approved by:	imp (mentor)
Noticed by:	rink
@
text
@d22 2
d336 1
a336 1
	cp -p ${CURRENTDIR}/conf/${CONF}/${KERNCONF} /usr/src/sys/i386/conf
d344 1
a344 1
	install -o 0 -g 0 -m 444 /sys/i386/conf/GENERIC.hints ${WORKDIR}/boot/device.hints
@


1.9
log
@Alert properly when we have stale mounts left after interupting
a tinybsd build.  If we do not do this, we can accidentally remove
critical files from directories like /lib (if mounted).

PR:		misc/121763
Submitted by:	Richard Arends < richard at unixguru dot nl >
MFC after:	3 days
@
text
@@


1.8
log
@Improve handling of the tinybsd application wrt ports.  Ports that
have dependencies or need to install a new user/group, are not
problematic anymore.

PR:		121367
Submitted by:	Richard Arends < richard at unixguru dot nl >
MFC after:	3 days
@
text
@d251 14
a264 6
	chflags -R noschg ${WORKDIR}
	echo "${TS} Removing "${WORKDIR}
	rm -rf ${WORKDIR}
	echo "${TS} Removing Build Kernel Directory"
	rm -rf /usr/obj/usr/src/sys/${KERNCONF}
	echo "${TS}  done."
@


1.7
log
@Bring in two fixes for TinyBSD:

- Add the bind mtree to the TinyBSD build so that files
  can be installed there (else the build fails)
- Change GEOM_GPT to GEOM_PART_GPT since that had been
  renamed in current. The kernel configuration provided
  by TinyBSD will not build without these changes.

PR:		misc/115484
PR:		misc/115405
Submitted by:	Richard Arends <richard at unixguru dot nl>
Approved by:	re (bmah)
Approved by:	imp (mentor)
@
text
@d15 1
a20 2
PKGDIRS=/tmp/pkg.dirs
PKGFILES=/tmp/pkg.files
d278 1
a278 1
	for file in `cat ${BASEFILE} | grep -v "#" | \
d286 35
a320 23
	for portname in `cat ${PORTSFILE} | grep -v '#'` ; do
	    cd ${PORTSDIR}/${portname}
	    pkgname=`make -V PKGNAME`
	    pkg_info -VQ ${pkgname}
	    install=`echo $?`
            if [ ${install} -eq 0 ] ; then
	       echo "$portname is already installed..."
	       create_missingdir
	       copy_ports
	      else
	        make install clean
		create_missingdir
	        copy_ports
	    fi
	done
}

create_missingdir() {
pkg_info -L ${pkgname} | egrep -v '(Information|Files|www|share|doc|man|include)' | sort | uniq >> ${PKGDIRS}
	for dir in `cat ${PKGDIRS}`; do
   	  if [ ! -d `dirname ${WORKDIR}/${dir}` ] ; then
    	    mkdir -p `dirname ${WORKDIR}/${dir}`
   	  fi
a321 9
	rm ${PKGDIRS}
}

copy_ports() {
pkg_info -L ${pkgname} | egrep -v '(Information|Files|www|share|doc|man|include)' >> ${PKGFILES}
        for port in `cat ${PKGFILES}` ; do
                echo "${TS} Copying "${port}" to "${WORKDIR}${port}
                cp -fp ${port} ${WORKDIR}${port} ;
        done
d341 2
a342 3
	cd ${CURRENTDIR}/conf/${CONF}
	for file in `cat ${BASEFILE} ${PKGFILES} | grep -v "#" | cut -f1 -d":"`; do
		ldd -f "%p\n" /${file} >> ${TDEPFILE} ; # don't worry on progs been "not dynamic"
a344 2
	rm ${PKGFILES}

a379 9
deinstall_ports() {
	for portname in `cat ${PORTSFILE} | grep -v '#'` ; do
            cd ${PORTSDIR}/${portname}    
             if [ $? -ne ${install} ] ; then
               make deinstall
             fi
	done
}

d409 1
a409 1
	for i in `cat ${BASEFILE} ${PORTSFILE} | grep -v "#" | grep ":"`; do
a481 1

d506 1
a510 2
  deinstall_ports
  create_etc
@


1.7.2.1
log
@MFC rev 1.8 tinybsd

  Improve handling of the tinybsd application wrt ports.  Ports that
  have dependencies or need to install a new user/group, are not
  problematic anymore.

  PR:             121367
  Submitted by:   Richard Arends < richard at unixguru dot nl >
  MFC after:      3 days

Approved by:	imp (mentor, implicit)
@
text
@a14 1

d20 2
d279 1
a279 1
	for file in `cat ${CURRENTDIR}/conf/${CONF}/${BASEFILE} | grep -v "#" | \
d287 23
a309 35
	for portname in `cat ${CURRENTDIR}/conf/${CONF}/${PORTSFILE} | grep -v '#'` ; do
		if [ ! -d "${WORKDIR}/usr/ports" ]; then
			mkdir -p "${WORKDIR}/usr/ports"
		fi

		PNAME=`/usr/bin/basename "${portname}"`
		PORT_OPTION_FILE="/var/db/ports/${PNAME}/options"

		if [ -f "${PORT_OPTION_FILE}" ]; then
			mkdir -p "${WORKDIR}/var/db/ports/${PNAME}"
			cp "${PORT_OPTION_FILE}" "${WORKDIR}/var/db/ports/${PNAME}/"
		fi

		mount_nullfs /lib "${WORKDIR}/lib"
		mount_nullfs /usr/bin "${WORKDIR}/usr/bin"
		mount_nullfs /usr/sbin "${WORKDIR}/usr/sbin"
		mount_nullfs /usr/ports "${WORKDIR}/usr/ports"
		mount_nullfs /usr/share "${WORKDIR}/usr/share"
		mount_nullfs /usr/libexec "${WORKDIR}/usr/libexec"
		mount_nullfs /usr/lib "${WORKDIR}/usr/lib"
		mount_nullfs /usr/include "${WORKDIR}/usr/include"

		cd ${PORTSDIR}/${portname}
		make fetch-recursive
		make DESTDIR_ENV_LIST=PATH DESTDIR="${WORKDIR}" install
		make clean

		umount "${WORKDIR}/lib"
		umount "${WORKDIR}/usr/ports"
		umount "${WORKDIR}/usr/bin"
		umount "${WORKDIR}/usr/sbin"
		umount "${WORKDIR}/usr/share"
		umount "${WORKDIR}/usr/libexec"
		umount "${WORKDIR}/usr/lib"
		umount "${WORKDIR}/usr/include"
d311 9
d339 3
a341 2
	find "${WORKDIR}" -type f |while read file; do
		ldd -f "%p\n" ${file} >> ${TDEPFILE} ; # don't worry on progs been "not dynamic"
d344 2
d381 9
d419 1
a419 1
	for i in `cat ${CURRENTDIR}/conf/${CONF}/${BASEFILE}| grep -v "#" | grep ":"`; do
d492 1
a516 1
  create_etc
d521 2
@


1.7.2.2
log
@MFC rev 1.9 tinybsd

  Alert properly when we have stale mounts left after interupting
  a tinybsd build.  If we do not do this, we can accidentally remove
  critical files from directories like /lib (if mounted).

  PR:             misc/121763
  Submitted by:   Richard Arends < richard at unixguru dot nl >
  MFC after:      3 days

Approved by:	imp (mentor, implicit)
@
text
@d251 6
a256 14
	# Before removing check if there is not a mount under $WORKDIR anymore
	MOUNT_CHECK=`mount|egrep "on ${WORKDIR}"`

	if [ ! -z "${MOUNT_CHECK}" ]; then
		echo "There are mounts under the workdir (${WORKDIR}). Please umount them before running this script"
		exit 1
	else
		chflags -R noschg ${WORKDIR}
		echo "${TS} Removing "${WORKDIR}
		rm -rf ${WORKDIR}
		echo "${TS} Removing Build Kernel Directory"
		rm -rf /usr/obj/usr/src/sys/${KERNCONF}
		echo "${TS}  done."
	fi
@


1.7.2.3
log
@SVN rev 217978 on 2011-01-27 20:39:19Z by remko

MFC r194558

Add architecture support for TinyBSD

  PR:	 135301
  Submitted by:	Olivier Cochard-Labbe <olivier at cochard dot me>
  Reviewed by:	Jean Milanez Melo <jmelo at freebsdbrasil dot com dot br> (maintainer)
  Approved by:	imp (mentor, implicit)
  MFC after:	1 week

PR:		135301
@
text
@a21 2
TINYARCH=$(uname -p)

d334 1
a334 1
	cp -p ${CURRENTDIR}/conf/${CONF}/${KERNCONF} /usr/src/sys/${TINYARCH}/conf
d342 1
a342 1
	install -o 0 -g 0 -m 444 /sys/${TINYARCH}/conf/GENERIC.hints ${WORKDIR}/boot/device.hints
@


1.7.2.4
log
@Switch importer
@
text
@d6 1
a6 1
# $FreeBSD: stable/7/tools/tools/tinybsd/tinybsd 217978 2011-01-27 20:39:19Z remko $
@


1.7.2.2.8.1
log
@SVN rev 216618 on 2010-12-21 17:10:29Z by kensmith

Copy stable/7 to releng/7.4 in preparation for FreeBSD-7.4 release.

Approved by:	re (implicit)
@
text
@@


1.7.2.2.8.2
log
@Switch importer
@
text
@d6 1
a6 1
# $FreeBSD: releng/7.4/tools/tools/tinybsd/tinybsd 177542 2008-03-24 10:39:34Z remko $
@


1.7.2.2.6.1
log
@SVN rev 203736 on 2010-02-10 00:26:20Z by kensmith

Copy stable/7 to releng/7.3 as part of the 7.3-RELEASE process.

Approved by:	re (implicit)
@
text
@@


1.7.2.2.4.1
log
@SVN rev 191087 on 2009-04-15 03:14:26Z by kensmith

Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.

Approved by:	re (implicit)
@
text
@@


1.7.2.2.2.1
log
@SVN rev 185281 on 2008-11-25 02:59:29Z by kensmith

Create releng/7.1 in preparation for moving into RC phase of 7.1 release
cycle.

Approved by:	re (implicit)
@
text
@@


1.6
log
@Reworking of how to add ports.

submitted by: Jean Milanez Melo
@
text
@d270 1
@


1.5
log
@Add some code to support including files ffrom packages in the image.

Submitted by: Jeremie Le Hen and tested by Jean Milanez Melo.
@
text
@d18 4
a21 1
LOCALFILE="tinybsd.localfiles"
d278 1
a278 1
	for file in `cat ${BASEFILE} ${LOCALFILE} | grep -v "#" | \
d285 36
a333 1

a334 1
#set -xv
d339 1
a339 1
	for file in `cat ${BASEFILE} ${LOCALFILE} | grep -v "#" | cut -f1 -d":"`; do
d343 2
d348 1
a348 1
	
a377 1
#set +xv
d380 8
d417 2
a418 2
set -xv
	for i in `cat ${BASEFILE} ${LOCALFILE} | grep -v "#" | grep ":"`; do
d423 1
a423 1
set +xv
d516 1
d520 1
@


1.4
log
@Might as well move to the right place if we are not there.
The whole question of how much to rely on teh sources being in /usr/src
needs visiting.
@
text
@d17 2
d244 4
d259 1
a259 1
	remove_workdir	
d268 1
d272 2
d275 1
a275 3
copy_binaries() {
#set -xv
	for file in `cat ${CURRENTDIR}/conf/${CONF}/tinybsd.basefiles | grep -v "#" | \
a279 1
#set +xv
d302 1
a302 1
	for file in `cat tinybsd.basefiles | grep -v "#" | cut -f1 -d":"`; do
d314 1
a314 1
	
d330 1
d359 1
a359 1
personal_directories() {
d361 1
a361 1
	for custom in `find ${CURRENTDIR}/conf/${CONF}/ -type d -depth 1`; do
d364 4
d371 2
a372 2
#set -xv
	for i in `cat tinybsd.basefiles | grep -v "#" | grep ":"`; do
d377 1
a377 1
#set +xv
a381 2
	#set -ex

d460 3
d475 1
a475 1
  personal_directories
@


1.3
log
@let the user know what configurations are available when asking for it.
@
text
@d12 2
@


1.2
log
@Large rewrite of the tinybsd script.

This allows the user to specify that the root filoesystem should be
an MFS or teh actual medium itself.
Also a new command syntax, along with an interactive mode by default,
with crossinvocation memory of the last used values as defaults for the
current invocation.

Submitted by:jmeloatfreebsdbrasil,com-br
@
text
@d9 4
a109 1
        echo "comment"
d138 1
a138 1
        echo -n "$MESSAGE [$ANSWER] use 'none' to clear ? " > /dev/tty
a140 1
        [ "$result" = "none" ] && ANSWER=""
d185 17
a201 2
  CONF=`confirm_action "$CONF" "Configuration name?"`
  MFSROOT=`confirm_action "$MFSROOT" "Use an MFSROOT?"`
a232 7
check_conf() {
        if [ ${CONF} = 'default' ]
        then
                echo "${TS} Alternative conf name not set; defaulting to 'default'"
        fi
}

a452 1
  check_conf
@


1.1
log
@In the spirit of nanoBSD and PicoBSD, add TinyBSD.
Submitted by jmeloatfreebsdbrasil,com-br
(Jean Milanez Melo)
As PicoBSD becomes slightly less useful, TinyBSD fills the gap below nanoBSD.
@
text
@a11 5
SECTUNIT=$1
TRACKCYL=$2 
SECTRACK=$3
CONF=$4
IMG=$5
d14 201
a214 16
if [ "$#" -lt 3 ]
then
  echo "Woops!
   Usage: $0 <mediasize in sectors> <heads according to firmware> 
   <sectors according to firmware> <conf> [<tinybsd image name>]

   Example: $0 62592 4 32 

	or

  $0 62592 4 32 wireless

   Run diskinfo(8) -v against your CF device to get correct information
   about your disk."
  exit 1
fi
d217 1
a217 1
        if [ -z ${CONF} ]
a218 1
                CONF="default"
d224 1
a224 1
	if [ -z ${IMG} ]
a225 1
		IMG="tinybsd.bin"
d333 7
d379 29
a407 1
	( cd ${WORKDIR} && find . -print | cpio -dump ${IMGMNT} ) || true
d410 1
d418 7
d429 25
a453 11
prework
check_conf
check_alt_imgname
create_tree
copy_binaries
make_kernel
copy_libraries
symlinks
create_etc
personal_directories
create_image
d455 1
@


1.1.2.1
log
@MFC: Make the tinybsd framework a peer of nanobsd and picobsd in the tree
Some patches to come.
Approved by: re (ken)
@
text
@@


1.1.2.2
log
@Switch importer
@
text
@d6 1
a6 1
# $FreeBSD: stable/6/tools/tools/tinybsd/tinybsd 162748 2006-09-28 21:09:10Z julian $
@


1.1.2.1.6.1
log
@SVN rev 183531 on 2008-10-02 02:57:24Z by kensmith

Create releng/6.4 from stable/6 in preparation for 6.4-RC1.

Approved by:	re (implicit)
@
text
@@


