432 lines
11 KiB
Bash
Executable File
432 lines
11 KiB
Bash
Executable File
#
|
|
# makedist.sh - Distribution media (CD/DVD/..) creator
|
|
#
|
|
# Copyright (c) 2003-2011 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
|
# Copyright (c) 2003-2006 by Davide Madrisan <davide.madrisan@gmail.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
. ./VERSION
|
|
. ./functions.inc.sh
|
|
. /var/makedist/.defs.inc
|
|
|
|
copyleft="\
|
|
makedist media (CD/DVD/Images) creator (version $makedist_version)
|
|
Copyright (c) 2003-2011 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
|
Copyright (c) 2003-2005 by Davide Madrisan <davide.madrisan@gmail.com>
|
|
"
|
|
|
|
unset branch # can be 'stable', 'unstable', or 'devel'
|
|
makedist_me="${0##*/}"
|
|
|
|
UPDATE=none
|
|
unset KERNEL_VER
|
|
INTERACTIVE=false
|
|
PUREUPDATE=false
|
|
CDNUM=1
|
|
RPM=rpm
|
|
RPM2CPIO=rpm2cpio
|
|
|
|
function usage() {
|
|
echo "\
|
|
usage: $makedist_me [-y] [-u[=<opts>]] [-t target] bootcd initrd kernel branch
|
|
-y : switch to non interactive mode
|
|
-w : download only files and packages; do not create an ISO image
|
|
-t : build CD for specified target
|
|
netcd : build an ISO image for installation from network only
|
|
livecd: create the ISO image for $DISTRONAME live CD
|
|
|
|
i.e. $makedist_me -u SOURCE bootcd initrd stable
|
|
$makedist_me SOURCE bootcd initrd stable
|
|
$makedist_me -w -u SOURCE bootcd initrd devel
|
|
" >&2
|
|
}
|
|
|
|
# the following is the default in case of update and other non-target commands
|
|
MAKEDIST_TARGET=distrocd
|
|
|
|
while test -n "$1" ; do
|
|
case $1 in
|
|
-y) INTERACTIVE=false ;;
|
|
-w) PUREUPDATE=true ;;
|
|
-t) shift
|
|
MAKEDIST_TARGET=$1
|
|
[ -d $TARGETSDIR/$1 ] || {
|
|
echo "$makedist_me: unknown target '$1'"; exit 1
|
|
}
|
|
;;
|
|
-h) usage; exit ;;
|
|
-v) echo "$copyleft"; exit ;;
|
|
*) if test -z "$INITRDDIR" ; then INITRDDIR=$1
|
|
elif test -z "$branch" ; then branch=$1
|
|
elif test -z "$DEBUG" ; then DEBUG=$1
|
|
elif test -z "$MEDIA" ; then MEDIA=$1
|
|
elif test -z "$PLATFORM" ; then PLATFORM=$1
|
|
elif test -z "$LANGUAGE" ; then LANGUAGE=$1
|
|
fi ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
|
|
#test $UID = 0 ||
|
|
# { echo "$makedist_me: must be superuser." >&2
|
|
# { (exit 1); exit 1; }; }
|
|
|
|
unset error
|
|
test -z "$INITRDDIR" && error=true
|
|
test "$UPDATE" != "none" -a -z "$branch" && error=true
|
|
|
|
test x$error = xtrue &&
|
|
{ echo "$makedist_me: missing parameter";
|
|
usage; { (exit 1); exit 1; }; }
|
|
|
|
case "$branch" in
|
|
stable) branch_dir="stable/current" ;;
|
|
unstable) branch_dir="unstable/current" ;;
|
|
devel) branch_dir="devel" ;;
|
|
*) echo "unknown branch ($branch)"
|
|
echo "valid choices are: 'stable', 'unstable', 'devel'"
|
|
exit 1 ;;
|
|
esac
|
|
|
|
case "$LANGUAGE" in
|
|
it*) LANGUAGE=it
|
|
COUNTRY=IT ;;
|
|
en*) LANGUAGE=en
|
|
COUNTRY=US ;;
|
|
es*) LANGUAGE=es
|
|
COUNTRY=ES ;;
|
|
fr*) LANGUAGE=fr
|
|
COUNTRY=FR ;;
|
|
"") LANGUAGE=en
|
|
COUNTRY=US ;;
|
|
*) echo "Unsupported language: $LANGUAGE; aborting."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
TARGETDIR=$TARGETSDIR/$MAKEDIST_TARGET
|
|
MOUNTDIR=$LOCALSTATEDIR/root.tmp
|
|
# Auxiliary mountdir
|
|
MOUNTDIR2=$LOCALSTATEDIR/root2.tmp
|
|
MOUNTDIR_TMPFS_SIZE=8G
|
|
|
|
[ -d $MOUNTDIR ] && rm -rf $MOUNTDIR
|
|
mkdir -p $MOUNTDIR
|
|
|
|
[ -d $MOUNTDIR2 ] && rm -rf $MOUNTDIR2
|
|
mkdir -p $MOUNTDIR2
|
|
|
|
MOUNTFS=$LOCALSTATEDIR/rootfs.tmp
|
|
CHROOTCMD="chroot $MOUNTDIR"
|
|
|
|
# boot kernel is the SMP one
|
|
#KERNEL_EXTRAVER=smp
|
|
# note: some non-SMP machines are unable to boot with a SMP kernel
|
|
KERNEL_EXTRAVER=
|
|
|
|
#
|
|
# load some target specific settings
|
|
. $TARGETDIR/settings.inc
|
|
|
|
# default media is cd1
|
|
[ "$MEDIA" ] || MEDIA=cd1
|
|
|
|
if [ "$DISTRIBUTION" = "1" ]; then
|
|
DISKTAG=$PLATFORM-$MEDIA
|
|
else
|
|
DISKTAG=$MAKEDIST_TARGET
|
|
fi
|
|
|
|
ISOLINUXDIR=$MOUNTDIR2/isolinux
|
|
INITRD=$MOUNTDIR2/isolinux/initrd
|
|
|
|
FSIMAGE=$MOUNTDIR2/rootfs.img
|
|
COMPRESSEDIMAGE=$MOUNTDIR2/rootfs.compressed
|
|
COMPRESSEDFSSIZE=300000
|
|
COMPRESSEDFSBLOCKSIZE=1k
|
|
|
|
[ "$PASSED_RELEASE" ] && RELEASE=$PASSED_RELEASE
|
|
[ "$PASSED_DISTROMATIC" ] && DISTROMATIC=$PASSED_DISTROMATIC
|
|
[ "$PASSED_VARIANT" ] && VARIANT=$PASSED_VARIANT
|
|
|
|
echo "\
|
|
Configuration:
|
|
- distribution : $DISTRONAME
|
|
- target : $MAKEDIST_TARGET
|
|
- platform : $PLATFORM ($MAKEDIST_TARGET/platforms/$PLATFORM)
|
|
- variant : $VARIANT
|
|
- release : $RELEASE
|
|
- target media : $MEDIA
|
|
- target arch : $arch
|
|
- distromatic : $PASSED_DISTROMATIC"
|
|
|
|
[ "$arch_fallback" ] && echo "\
|
|
- fallback arch : $arch_fallback"
|
|
|
|
echo "\
|
|
- language : $LANGUAGE
|
|
- country : $COUNTRY
|
|
|
|
Repositories:"
|
|
|
|
for r in ${REPOSITORY[*]}; do
|
|
echo " - $r"
|
|
done
|
|
|
|
echo
|
|
|
|
# - utils directory : $UTILSDIR
|
|
# - initrd directory: $INITRDDIR
|
|
# - deps file : $DEPSFILE-$arch
|
|
# - auxiliary tmpdir: $MOUNTDIR2
|
|
|
|
#KERNEL_VER=`get_rpm_version kernel`
|
|
if [ ! "$KERNEL_IGNORE" ]; then
|
|
[ "$KERNEL_EXTRAVER" ] &&
|
|
KERNEL_VER=`get_rpm_version kernel-${KERNEL_EXTRAVER}${KERNEL_PLATFORM}` ||
|
|
{
|
|
echo "Error: undefined KERNEL_EXTRAVER! Aborting."; exit 1;
|
|
}
|
|
|
|
test -n "$KERNEL_VER" ||
|
|
{ echo "$makedist_me: cannot get KERNEL_VER" >&2
|
|
{ (exit 1); exit 1; }; }
|
|
echo "Found Linux kernel version ${KERNEL_VER}${KERNEL_EXTRAVER}"
|
|
if [ "${KERNEL_VER:0:1}" = "2" ]; then
|
|
# kernel major release = 2
|
|
KERNEL_MAJVER=`echo $KERNEL_VER | cut -d. -f1-3`
|
|
else
|
|
# kernel major release >= 3
|
|
KERNEL_MAJVER=`echo $KERNEL_VER | cut -d. -f1-2`
|
|
fi
|
|
echo "
|
|
KERNEL_PLATFORM=${KERNEL_PLATFORM}
|
|
KERNEL_EXTRAVER=${KERNEL_EXTRAVER}" >> /var/makedist/.defs.inc
|
|
if [ "$KERNEL_MORE_EXTRAVER" ]; then
|
|
echo "KERNEL_MORE_EXTRAVER=${KERNEL_MORE_EXTRAVER}" >> /var/makedist/.defs.inc
|
|
fi
|
|
else
|
|
echo "Skipping kernel check"
|
|
fi
|
|
|
|
# execute distromatic
|
|
[ "$DISTROMATIC" != "off" ] && exec_distromatic
|
|
|
|
function create_filesystem() {
|
|
# NOTE: this function is currently unmaintained
|
|
#
|
|
# create the filesystem
|
|
#
|
|
# parameters:
|
|
#
|
|
# $1: filesystem size
|
|
# $2: block size
|
|
# $3: filesystem type (defaults to ext2)
|
|
|
|
[ "$3" ] && FS=$3 || FS=ext2
|
|
echo "Creating $FS filesystem ($MOUNTFS)..."
|
|
umount /dev/loop2 2>/dev/null # FIXME
|
|
|
|
rm -f $FSIMAGE
|
|
losetup -d /dev/loop2 2>/dev/null
|
|
|
|
test -d $MOUNTFS || mkdir -p $MOUNTFS
|
|
dd if=/dev/zero of=$FSIMAGE bs=$2 count=$1
|
|
losetup /dev/loop2 $FSIMAGE
|
|
mkfs -t $FS -m 0 /dev/loop2 > /dev/null
|
|
mount /dev/loop2 $MOUNTFS || exit 1
|
|
}
|
|
|
|
function create_raw_filesystem() {
|
|
# create a raw filesystem
|
|
#
|
|
# parameters:
|
|
#
|
|
# $1: filesystem image name
|
|
# $2: filesystem size
|
|
# $3: block size
|
|
# $4: filesystem type (defaults to ext2)
|
|
|
|
[ "$1" -a "$2" -a "$3" ] || {
|
|
echo "create_raw_filesystem: invalid number of parameters; aborting."
|
|
exit 1;
|
|
}
|
|
|
|
[ "$4" ] && FS=$4 || FS=ext2
|
|
echo "Creating $FS filesystem ($1)..."
|
|
umount /dev/loop2 2>/dev/null # FIXME
|
|
|
|
rm -f $FSIMAGE
|
|
losetup -d /dev/loop2 2>/dev/null
|
|
|
|
dd if=/dev/zero of=$1 bs=$3 count=$2
|
|
losetup /dev/loop2 $1
|
|
mkfs -t $FS -m 0 /dev/loop2 > /dev/null
|
|
mount /dev/loop2 $MOUNTDIR || exit 1
|
|
}
|
|
|
|
function create_raw_disk_image() {
|
|
# create a raw disk image
|
|
#
|
|
# parameters:
|
|
#
|
|
# $1: disk image filename
|
|
# $2: disk size (MBytes)
|
|
# $3: block size
|
|
# $4: filesystem type (defaults to ext2)
|
|
|
|
[ "$1" -a "$2" -a "$3" ] || {
|
|
echo "create_raw_disk_image: invalid number of parameters; aborting."
|
|
exit 1;
|
|
}
|
|
|
|
[ "$4" ] && FS=$4 || FS=ext2
|
|
echo "Creating raw disk image ($1)..."
|
|
umount /dev/loop2 2>/dev/null # FIXME
|
|
|
|
rm -f $1
|
|
losetup -d /dev/loop2 2>/dev/null
|
|
|
|
test -d $MOUNTFS || mkdir -p $MOUNTFS
|
|
|
|
dd if=/dev/zero of=$1 bs=$3 count=$2
|
|
losetup /dev/loop2 $1
|
|
install-mbr /dev/loop2 --force
|
|
parted -s /dev/loop2 mkpart primary ext3 1 $2
|
|
|
|
# mkfs -t $FS -m 0 /dev/loop2 > /dev/null
|
|
# mount /dev/loop2 $MOUNTFS || exit 1
|
|
}
|
|
|
|
function create_devices() {
|
|
echo "Creating devices in /dev..."
|
|
mkdir -p $MOUNTDIR/dev
|
|
(cd $MOUNTDIR/dev
|
|
ln -sf /proc/self/fd fd
|
|
ln -sf /proc/self/fd/0 stdin
|
|
ln -sf /proc/self/fd/1 stdout
|
|
ln -sf /proc/self/fd/2 stderr
|
|
ln -sf /proc/kcore core
|
|
mkdir shm pts
|
|
mknod --mode=0600 initctl p
|
|
mknod -m666 null c 1 3
|
|
mknod -m600 console c 5 1
|
|
mknod -m444 urandom c 1 9
|
|
)
|
|
}
|
|
|
|
function create_fstab() {
|
|
# create the /etc/fstab file
|
|
#
|
|
# parameters:
|
|
#
|
|
# $1: root filesystem device (defaults to /dev/root)
|
|
# $2: root filesystem type (defaults to ext2)
|
|
|
|
[ -e $MOUNTDIR/etc ] || mkdir -p $MOUNTDIR/etc
|
|
|
|
[ "$1" ] && rootdev=$1
|
|
[ "$2" ] && rootfs=$2
|
|
|
|
cat > $MOUNTDIR/etc/fstab << _END
|
|
# Begin /etc/fstab
|
|
# filesystem mount-point fstype options dump fsck-order
|
|
proc /proc proc defaults 0 0
|
|
devpts /dev/pts devpts gid=4,mode=620 0 0
|
|
usbfs /proc/bus/usb usbfs defaults 0 0
|
|
none /sys sysfs defaults 0 0
|
|
_END
|
|
|
|
#tmpfs /dev/shm tmpfs defaults 0 0
|
|
|
|
[ "$rootdev" -a "$rootfs" ] && {
|
|
cat >> $MOUNTDIR/etc/fstab << _END
|
|
$rootdev / $rootfs defaults 0 0
|
|
_END
|
|
}
|
|
|
|
}
|
|
|
|
function rootfs_post_operations() {
|
|
|
|
echo "*** rootfs post install operations"
|
|
# running ldconfig
|
|
#
|
|
echo " + Configuring dynamic linker run time bindings..."
|
|
$CHROOTCMD ldconfig
|
|
|
|
# updating modules dependencies
|
|
#
|
|
echo " + Updating modules dependencies..."
|
|
update_modules_dependencies ${KERNEL_VER}${KERNEL_EXTRAVER}
|
|
|
|
# deactivate services
|
|
#
|
|
echo " + Deactivating unneded services..."
|
|
rm $MOUNTDIR/etc/rcsysinit.d/S??loadmodules \
|
|
$MOUNTDIR/etc/rcsysinit.d/S??checkfs \
|
|
$MOUNTDIR/etc/rc3.d/S??sysinit
|
|
|
|
if [ "$MULTITHREAD" = "0" ]; then
|
|
# force standard PosiX SysV5 init (multithreaded init off)
|
|
#
|
|
echo " + Forcing standard PosiX SysV5 init..."
|
|
sed -i 's/multithread=1/multithread=0/' $MOUNTDIR/etc/sysconfig/rc
|
|
fi
|
|
|
|
# set file /etc/<distroname>-release
|
|
#
|
|
[[ "$RELEASE" ]] || echo "$DISTRONAME $MAKEDIST_TARGET release $RELEASE for $arch" > $MOUNTDIR/etc/$DISTRONAME-release
|
|
|
|
# set rootfs HOSTNAME
|
|
#
|
|
[[ "$TARGET_HOSTNAME" ]] && sed -i "s|HOSTNAME=.*|HOSTNAME=$TARGET_HOSTNAME|" $MOUNTDIR/etc/sysconfig/network
|
|
|
|
# don't update dependencies at boot time
|
|
#
|
|
#echo "Forcing \`rc.sysinit' not to update dependencies at boot time..."
|
|
#sed -i 's/depmod/#depmod/g' $MOUNTDIR/etc/init.d/rc.sysinit
|
|
|
|
# remove unuseful files
|
|
echo " + Removing unuseful files..."
|
|
#rm -rf usr/share/{man,info,tmp} dev tmp var
|
|
rm -rf $MOUNTDIR/usr/share/tmp $MOUNTDIR/dev/ $MOUNTDIR/var/log/* \
|
|
$MOUNTDIR/tmp/*
|
|
|
|
echo " + Making absolute relative links to /etc and /var... "
|
|
# note (while loop):
|
|
# in) usr/X11R6/lib/X11/xbd -> ../../../../etc/X11/xkb
|
|
# out) usr/X11R6/lib/X11/xbd /etc/X11/xkb
|
|
# ln -s /etc/X11/xkb usr/X11R6/lib/X11/xkb
|
|
(cd $MOUNTDIR
|
|
for dir in /etc /var; do
|
|
find usr -type l -exec ls -l {} \; | \
|
|
grep "\.\.$dir" | gawk '{ print $8 " " $10 }' | \
|
|
while read f1 f2; do
|
|
echo "ln -sf /${f2//..\//} $f1"
|
|
rm -f $f1
|
|
ln -s "/${f2//..\//}" "$f1"
|
|
done
|
|
done )
|
|
|
|
}
|
|
|
|
echo "Executing scripts for \`$MAKEDIST_TARGET' target"
|
|
. $TARGETDIR/makedist.inc.sh
|
|
|
|
# that's all...
|
|
#
|
|
echo "Done."
|
|
|
|
exit 0
|