aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2006-07-16 14:53:32 +0200
committerWilly Tarreau <willy@wtap.(none)>2006-07-26 11:51:24 +0200
commita9ca11bf64f18a1671f0b0810cfcc5fa7d0acf6d (patch)
tree2cdef4487581c15d1c2723e735cc48816276c027 /scripts
parent[RELEASE] flxutils-0.1.17 (diff)
downloadflxutils-a9ca11bf64f18a1671f0b0810cfcc5fa7d0acf6d.tar.xz
[RELEASE] flxutils-0.1.18v0.1.18
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mkinstall995
-rwxr-xr-xscripts/mkinstall.old595
-rwxr-xr-xscripts/mkinstall21218
-rwxr-xr-xscripts/pkg370
4 files changed, 1719 insertions, 1459 deletions
diff --git a/scripts/mkinstall b/scripts/mkinstall
index 3ccd20e..7914987 100755
--- a/scripts/mkinstall
+++ b/scripts/mkinstall
@@ -1,6 +1,6 @@
-#!/bin/sh
+#!/bin/bash
#
-# /sbin/mkinstall - Formilux System Installer - version 1.0.0 - 2003-03-20
+# /sbin/mkinstall - System Installer - version 1.9.1 - 2003-08-02
# This file is part of the Formilux project : http://formilux.ant-computing.com/
#
# Copyright (C) 2001-2003 Benoit Dolez & Willy Tarreau
@@ -8,12 +8,432 @@
#
# This program is licenced under GPLv2 ( http://www.gnu.org/licenses/gpl.txt )
+cdlist=( )
+names=( )
+sizes=( )
+parts=( )
+
+# this utility uses a few temporary files :
+#
+# /tmp/fsmnt : <device><space><mount_point>
+# device=/dev/hda, /dev/sda1...
+# space=exactly one space
+# mount_mount=/home, /var, /, ..., mbr, cdrom, swap, <empty string when not affected>
+# /tmp/fsid : <device><space><hex_id><space><os_name>
+# /tmp/fstype : <device><space><fstype>
+# /tmp/fslist : <device>
+# /tmp/fssize : <device><space><size_in_kB>
+# /tmp/sourcepkg : symlink to the source packages directory
+
+# give it a number suffixed with a k,M,G,T, and it will return it reduced to
+# the nearest power of 1024 suffixed with k,M,G or T
+humansize() {
+ local pow val
+ local -a suff=( "" k M G T P )
+ case "${1##[0-9]*}" in
+ k) pow=1;;
+ M) pow=2;;
+ G) pow=3;;
+ T) pow=4;;
+ P) pow=5;;
+ *) pow=0;;
+ esac
+ val=${1%%[a-zA-Z]*}
+ # we don't return values lower than 10 when possible
+ while [ $val -ge 10240 ]; do
+ ((pow++))
+ ((val/=1024))
+ done
+ REPLY=$val${suff[$pow]}
+ echo -n $REPLY
+}
+
+detect_cdrom() {
+ cdlist=($(grep -i '^drive name:' /proc/sys/dev/cdrom/info |cut -f2 -d:))
+ CDROMS="${cdlist[*]}"
+}
+
+detect_disks() {
+ local i j major minor size name rest
+
+ names=( )
+ sizes=( )
+ parts=( )
+
+ rm -f /tmp/partitions
+ tail +3 /proc/partitions | sort -k4.1 >/tmp/partitions
+ while read major minor size name rest; do
+ if ((i >= 0)); then
+ names[i]=$name
+ sizes[i]=$size
+ parts[i]=1
+ fi
+ ((i++))
+ done < /tmp/partitions
+
+ i=0
+ while ((i < ${#names[@]})); do
+ if [ -n "${names[i]}" ]; then
+ j=0
+ while ((j < ${#names[@]})); do
+ if [ $i -ne $j -a -n "${names[j]}" -a -z "${names[j]##${names[i]}*}" ]; then
+ names[j]=""
+ ((parts[i]+=${parts[j]}))
+ fi
+ ((j++))
+ done
+ fi
+ ((i++))
+ done
+
+ i=0 j=0
+ while ((i < ${#names[@]})); do
+ if [ -n "${names[i]}" -a "${cdlist[*]##${names[i]}}" = "${cdlist[*]}" ]; then
+ names[j]=${names[i]}
+ sizes[j]=${sizes[i]}
+ ((parts[j]=${parts[i]}-1))
+ ((j++))
+ fi
+
+ if ((i >= j)); then
+ unset names[i] parts[i] sizes[i]
+ names=("${names[@]}") parts=("${parts[@]}") sizes=("${sizes[@]}")
+ else
+ ((i++))
+ fi
+ done
+ # now we have the list of the hard disks :
+ # names[] contains their name in /dev
+ # sizes[] contains their size in blocks (1 kB)
+ # parts[] contains their number of partitions
+}
+
# This function collects some information in /proc and other places.
# It should be called ASAP.
function init {
- #umount /mnt/cdrom >/dev/null 2>&1 # to avoid stupid recursive copying !
- CDROMS=$(grep -i '^drive name:' /proc/sys/dev/cdrom/info |cut -f2- -d:)
+ #umount /mnt/cdrom >/dev/null 2>&1 # to avoid stupid recursive copying !
+ detect_cdrom
+ detect_disks
+ mkdir -p $ROOTDIR >/dev/null 2>&1
+}
+
+# displays the main menu
+# if an arg is passed, it will be used as the name entry of the default action.
+# it returns the name of the entry in REPLY
+# returns 0 if OK, 1 if Cancel/Exit.
+function menu_main {
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-cancel --no-shadow ${1:+--default-item $1 }\
+ --menu "Installation Menu\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 14 \
+ "PART" "Configure Partitions and File Systems" \
+ "SOURCE" "Select Packages Source" \
+ "PKG" "Select which Packages to Install" \
+ "CONFIG" "Build Configuration" \
+ "SAVE" "Save Current Configuration" \
+ "LILO" "Run LILO" \
+ "UNMOUNT" "Unmount all File Systems" \
+ "SHELL" "Get Access to a Shell" \
+ "EXIT" "Exit this Utility" 2>&1 | grep -v EXIT)
+ [ -n "$REPLY" ]
+}
+
+
+# presents a list of hard disks and lets the user choose one.
+# the default one can be passed in $1
+# returns 0 if OK, 1 if Cancel/Exit.
+function menu_harddisk {
+ local -a args=( )
+ local i=0
+ local model
+ while ((i < ${#names[@]})); do
+ model='unknown model'
+ [ -e "/proc/ide/${names[i]}/model" ] && model=$(</proc/ide/${names[i]}/model)
+ args=("${args[@]}" "${names[i]}" "$model, $(humansize ${sizes[i]}k)B, ${parts[i]} part.")
+ ((i++))
+ done
+
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow ${1:+--default-item $1 } --menu "\nSelect a Hard Disk to Configure\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 12 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
+ [ -n "$REPLY" ]
+}
+
+# presents a list of hard disks partitions and lets the user choose one.
+# the disk is passed in $1
+# the default one can be passed in $2
+# returns 0 if OK, 1 if Cancel/Exit.
+function menu_partition {
+ local -a args=( )
+ local dev=$1
+ local disk=${1##/dev/}
+ local def=$2
+ local mnt
+ local device size id syst rest
+
+ for device in $(grep "^$dev" /tmp/fslist 2>/dev/null); do
+ size=$(grep "^$device " /tmp/fssize 2>/dev/null |cut -f2 -d' ')
+ mnt=$(grep "^$device " /tmp/fsmnt 2>/dev/null |cut -f2 -d' ')
+ id=$(grep "^$device " /tmp/fsid 2>/dev/null |cut -f2 -d' ')
+ syst=$(grep "^$device " /tmp/fsid 2>/dev/null |cut -f3 -d' ')
+ type=$(grep "^$device " /tmp/fstype 2>/dev/null |cut -f2 -d' ')
+ if [ -z "$mnt" ]; then
+ def=${def:-${device##/dev/}}
+ mnt="not assigned"
+ else
+ mnt="assigned to $mnt"
+ fi
+ if [ -z "$type" ]; then
+ def=${def:-${device##/dev/}}
+ type="not formated"
+ else
+ type="type $type"
+ fi
+ args=("${args[@]}" "${device##/dev/}" "$(humansize ${size}k)B, Id 0x$id($syst), $type, $mnt")
+ done
+
+ def=${def:-EXIT}
+ args=("${args[@]}" "CLEAR" "Clear ALL partitions on this disk" "FDISK" "Run fdisk on this disk")
+
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow ${def:+--default-item $def} --menu "\nSelect a Partition\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 12 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
+ [ -n "$REPLY" ]
+}
+
+# reads the partition table on a disk and updates the associated files :
+# /tmp/fslist, /tmp/fssize, /tmp/fsid, /tmp/fsmnt, /tmp/fstype
+# the disk device is passed in $1 (/dev/xxx). There's no return code.
+function disk_read_part {
+ local dev=$1
+ local disk=${1##/dev/}
+ local device begin end cyl size id syst rest file
+
+ rm -f /tmp/sfdisk.${disk//\//.}
+ for file in fslist fssize fsid; do
+ grep -v "^$dev" /tmp/$file 2>/dev/null >/tmp/${file}-; mv /tmp/${file}- /tmp/$file
+ done
+
+ for file in fsmnt fstype; do
+ grep "^$dev" /tmp/$file 2>/dev/null >/tmp/$file.${disk//\//.}
+ grep -v "^$dev" /tmp/$file 2>/dev/null >/tmp/${file}-; mv /tmp/${file}- /tmp/$file
+ done
+
+ sfdisk -l $dev | tr '*' ' ' | grep '^/dev/' >/tmp/sfdisk.${disk//\//.}
+ while read device begin end cyl size id syst rest; do
+ # let's ignore empty and extended partitions
+ [ "$id" = "0" -o "$id" = "5" ] && continue
+ size=${size%+}
+ echo "$device" >> /tmp/fslist
+ echo "$device $size" >> /tmp/fssize
+ echo "$device $id $syst" >> /tmp/fsid
+ if [ "$id" != "82" ] || grep -q "^$device " /tmp/fsmnt.${disk//\//.} && ! grep -q "^$device swap" /tmp/fsmnt.${disk//\//.} ; then
+ grep "^$device " /tmp/fsmnt.${disk//\//.} >> /tmp/fsmnt
+ grep "^$device " /tmp/fstype.${disk//\//.} >> /tmp/fstype
+ else
+ echo "$device swap" >> /tmp/fsmnt
+ # we want to keep a trace of the format status of the swap partition
+ # instead of assuming it has already been formated
+ grep "^$device " /tmp/fstype.${disk//\//.} >> /tmp/fstype
+ #echo "$device swap" >> /tmp/fstype
+ fi
+ done < /tmp/sfdisk.${disk//\//.}
+ rm -f /tmp/sfdisk.${disk//\//.}
+}
+
+# presents a list of possible actions for a partition :
+# - change its mount point
+# - format it
+# the partition is passed in $1
+# if a default choice should be proposed, its name must be in $2
+# returns 0 if OK, 1 if Cancel/Exit.
+function menu_setupfs {
+ local -a args=( )
+ local dev=$1
+ local def size type strext2s strext2l strext3 strreiser
+ local mnt
+
+ def=$2
+ mnt=$(grep "^$dev " /tmp/fsmnt 2>/dev/null |cut -f2 -d' ')
+ [ -z "$mnt" ] && { mnt="not assigned" ; def=${def:-"MNT"}; }
+
+ type=$(grep "^$dev " /tmp/fstype 2>/dev/null |cut -f2 -d' ')
+ [ -z "$type" ] && type="not formated"
+
+ size=$[ ($(grep "^$dev " /tmp/fssize 2>/dev/null | cut -f2 -d' ')+0) / 1024 ]
+
+ args=("MNT" "Change the mount point ($mnt)")
+
+ if [ "$mnt" = "swap" ]; then
+ args=("${args[@]}" "SWAP" "* mkswap $dev (format as swap)")
+ args=("${args[@]}" "SWAPC" " mkswap -c $dev (format and check)")
+ def=${def:-SWAP}
+ else
+ strext2s="mke2fs -b 1024 -m 1 -s 1 $dev (format as small Ext2)"
+ strext2l="mke2fs -b 4096 -s 1 $dev (format as large Ext2)"
+ strext3="mke2fs -b 4096 -s 1 -j $dev (format as Ext3)"
+ strreiser="mkreiserfs -h r5 $dev (format as ReiserFS)"
+ if [ $size -lt 64 ]; then
+ strext2s="* $strext2s"
+ strext2l=" $strext2l"
+ strext3=" $strext3"
+ strreiser=" $strreiser"
+ def=${def:-EXT2S}
+ else
+ strext2s=" $strext2s"
+ strext2l=" $strext2l"
+ strext3="* $strext3"
+ strreiser=" $strreiser"
+ def=${def:-EXT3}
+ fi
+
+ args=("${args[@]}" "EXT2S" "$strext2s" "EXT2L" "$strext2l" "EXT3" "$strext3" "REISER" "$strreiser" )
+ fi
+ args=("${args[@]}" "SHELL" "Get Access to a Shell")
+
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow ${def:+--default-item $def} --menu "\nFormat and Mount Point\n\nChoose a mount point for this partition, then select a format command to format it and set its type. The '*' indicates the recommended format.\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 8 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
+ [ -n "$REPLY" ]
+}
+
+
+# lets the user change a mount point for a partition.
+# the partition is passed in $1
+# returns 0 if something changed, else 1.
+function menu_mount_point {
+ local mnt dev type id name
+ dev=$1
+ mnt=$(grep "^$dev " /tmp/fsmnt 2>/dev/null |cut -f2 -d' ')
+ id=$(grep "^$dev " /tmp/fsid 2>/dev/null |cut -f2 -d' ')
+ name=$(grep "^$dev " /tmp/fsid 2>/dev/null |cut -f3 -d' ')
+ type=$(grep "^$dev " /tmp/fstype 2>/dev/null |cut -f2 -d' ')
+
+ REPLY=$mnt
+ [ -z "$REPLY" -a "$id" = "82" ] && REPLY="swap"
+ [ -z "$REPLY" ] && ! grep -q " /boot$" /tmp/fsmnt && REPLY="/boot"
+ [ -z "$REPLY" ] && ! grep -q " /$" /tmp/fsmnt && REPLY="/"
+ [ -z "$REPLY" ] && ! grep -q " /var$" /tmp/fsmnt && REPLY="/var"
+ [ -z "$REPLY" ] && ! grep -q " /home$" /tmp/fsmnt && REPLY="/home"
+
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --inputbox "Enter the mount point for partition $dev\n${id:+Partition Id=$id($name)}${type:+${id:+, }Formated as $type}\nEnter 'swap' to force it to become swap\n\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 12 60 $REPLY 2>&1 || echo $mnt)
+ if [ "$REPLY" != "$mnt" ]; then
+ (grep -v "^$dev " /tmp/fsmnt 2>/dev/null; echo "$dev $REPLY") >/tmp/fsmnt-
+ mv /tmp/fsmnt- /tmp/fsmnt
+ return 0
+ else
+ return 1
+ fi
+}
+
+
+# lets the user change the package directory
+# the entry is checked to be a valid directory
+# returns 0 if something changed, else 1.
+function menu_pkg_dir {
+ local old
+
+ old=$(readlink /var/flx-pkg 2>/dev/null)
+ REPLY=$old
+ while : ; do
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --inputbox "Enter the new packages directory\nCurrently set to '$old'\n\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 12 60 $REPLY 2>&1 || echo $old)
+ if [ "$REPLY" != "$old" ]; then
+ if [ -d "$REPLY/." ]; then
+ PKGDIR=$REPLY
+ rm -f /var/flx-pkg
+ ln -sf $REPLY /var/flx-pkg
+ return 0
+ else
+ dialog --title " Formilux Installation Utility " --msgbox "'$REPLY' is not a valid directory. Please try again, or press [Cancel].\n" 8 60
+ fi
+ else
+ # cancel or no changes
+ return 1
+ fi
+ done
+}
+
+# ask the user about the desired source of packages for the installation
+function menu_select_source {
+ local -a args=( )
+ args=("CDROM" "CD-ROM" "DISK" "Hard disk or USB storage device" "NFS" "Remove file-system over NFS" "DIR" "Pre-mounted directory")
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --menu "\nSource Packages Selection\n\nChoose from which medium the source packages will be fetched.\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 8 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
+ [ -n "$REPLY" ]
+}
+
+
+# ask the user about the desired source cdrom
+# returns 0 if the CD could be mounted, 1 otherwise.
+function menu_select_cdrom {
+ local -a args=( )
+ local cdrom
+
+ umount -l /mnt/cdrom >/dev/null 2>&1
+ rm -f /dev/cdrom
+ rm -f /var/flx-pkg
+ PKGDIR=
+ case ${#cdlist[@]} in
+ 0)
+ dialog --title " Formilux Installation Utility " --msgbox "No CD-ROM device was detected on this system. Please load manually any appropriate module or choose another source medium." 12 60 ;
+ rm -f /var/flx-pkg
+ return 1
+ ;;
+ 1)
+ ln -sf ${cdlist[0]} /dev/cdrom
+ if mount /mnt/cdrom >/dev/null 2>&1 ; then
+ PKGDIR=/mnt/cdrom/pkg
+ ln -s $PKGDIR /var/flx-pkg
+ dialog --title " Formilux Installation Utility " --msgbox "/dev/${cdlist[0]} has been selected as the only CD-ROM device, and mounted successfully.\n" 8 60
+ return 0
+ else
+ dialog --title " Formilux Installation Utility " --msgbox "/dev/${cdlist[0]} has been selected as the only CD-ROM device, but could not be mounted. Please insert a valid CD-ROM and try again.\n" 8 60
+ return 1
+ fi
+ ;;
+ esac
+
+ args=("AUTO" "Automatically find which drive contains a CD")
+ for cdrom in "${cdlist[@]}"; do
+ if [ -e "/proc/ide/$cdrom/model" ]; then
+ args=("${args[@]}" "$cdrom" "$(cat /proc/ide/$cdrom/model)")
+ elif [ -z "${cdrom##sr*}" -o -z "${cdrom##scd*}" ]; then
+ args=("${args[@]}" "$cdrom" "SCSI CD-ROM")
+ else
+ args=("${args[@]}" "$cdrom" "Unknown CD-ROM model")
+ fi
+ done
+
+ cdrom="${args[0]}"
+ while [ -z "$PKGDIR" ]; do
+ rm -f /dev/cdrom
+ REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --default-item "$cdrom" --menu "\nCD-ROM\n\nSelect the CD-ROM drive which contains the Formilux CD-ROM you want to use for the installation.\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 8 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
+ cdrom=$REPLY
+ case "$REPLY" in
+ "")
+ return 1
+ ;;
+ AUTO)
+ findcdrom
+ if [ ! -e /dev/cdrom ]; then
+ dialog --title " Formilux Installation Utility " --msgbox "No drive containing a valid CD-ROM was found. Please insert a valid CD-ROM and try again.\n" 8 60
+ continue
+ fi
+ ;;
+ *)
+ ln -sf $REPLY /dev/cdrom
+ ;;
+ esac
+ if mount /mnt/cdrom >/dev/null 2>&1; then
+ PKGDIR=/mnt/cdrom/pkg
+ dialog --title " Formilux Installation Utility " --msgbox "/dev/$(readlink /dev/cdrom) has been selected as the new CD-ROM device, and mounted successfully.\n" 8 60
+ return 0
+ else
+ dialog --title " Formilux Installation Utility " --msgbox "/dev/$(readlink /dev/cdrom) has been selected as the new CD-ROM device, but could not be mounted. Please insert a valid CD-ROM and try again.\n" 8 60
+ fi
+ done
+ return 1
+}
+
+
+# ask the user a question to which he can reply by "yes" or "no".
+# A simple message is passed in $1
+# if $2 is NOT EMPTY, the default response will be NO.
+# returns 0 if No, 1 if Yes
+function menu_yesno {
+ dialog --title " Formilux Installation Utility " --no-shadow ${2:+--defaultno} --yesno "$1" 12 65
}
# user interface functions
@@ -32,74 +452,152 @@ function yesno {
#
function check_directories {
- if [ ! -d $ROOTDIR/etc/. ] ; then
- if [ -d $ROOTDIR/boot/etc/. ] ; then
- ln -s boot/etc $ROOTDIR/etc
- else
- echo "Can't find 'etc' directory neither in '/' nor in '/boot'"
- return 1
- fi
- fi
- if [ ! -d $ROOTDIR/var/. ] ; then
- mkdir $ROOTDIR/var ; fi
- if [ ! -d $ROOTDIR/var/tmp ] ; then
- mkdir $ROOTDIR/var/tmp ; chmod 1777 $ROOTDIR/var/tmp ; fi
- if [ ! -d $ROOTDIR/var/run ] ; then
- mkdir $ROOTDIR/var/run ; fi
- if [ ! -d $ROOTDIR/var/spool ] ; then
- mkdir $ROOTDIR/var/spool ; fi
- if [ ! -d $ROOTDIR/var/log ] ; then
- mkdir $ROOTDIR/var/log ; fi
- if [ ! -d $ROOTDIR/var/cache ] ; then
- mkdir $ROOTDIR/var/cache ; fi
- if [ ! -d $ROOTDIR/var/adm/. ] ; then
- ln -s log $ROOTDIR/var/adm ; fi
+ if [ ! -d $ROOTDIR/etc/. ] ; then
+ if [ -d $ROOTDIR/boot/etc/. ] ; then
+ ln -s boot/etc $ROOTDIR/etc
+ else
+ echo "Can't find 'etc' directory neither in '/' nor in '/boot'"
+ return 1
+ fi
+ fi
+ [ -d $ROOTDIR/var/. ] || mkdir $ROOTDIR/var
+ [ -d $ROOTDIR/var/run ] || mkdir $ROOTDIR/var/run
+ [ -d $ROOTDIR/var/spool ] || mkdir $ROOTDIR/var/spool
+ [ -d $ROOTDIR/var/cache ] || mkdir $ROOTDIR/var/cache
+ if [ ! -d $ROOTDIR/var/log ] ; then
+ mkdir $ROOTDIR/var/log
+ chown root:log $ROOTDIR/var/log
+ chmod 2750 $ROOTDIR/var/log
+ fi
+ [ -d $ROOTDIR/var/adm/. ] || ln -s log $ROOTDIR/var/adm
- return 0
+ if [ ! -d $ROOTDIR/var/tmp ] ; then mkdir $ROOTDIR/var/tmp ; chmod 1777 $ROOTDIR/var/tmp ; fi
+ # /tmp should exist, either as a dir or a link.
+ if [ ! -e $ROOTDIR/tmp ] ; then mkdir $ROOTDIR/tmp ; chmod 1777 $ROOTDIR/tmp ; fi
+
+ return 0
}
# this function lists all hard drives found, but hides CDROMs
function list_disks {
- for i in `tail +3 /proc/partitions | awk '{print $4}' | grep '\([a-zA-Z]$\)\|\(c[0-9]*d[0-9]*$\)'`; do
- if ! echo $CDROMS | grep -qw $i; then
- echo $i
- fi
- done
+ echo "${names[@]}"
+ #for i in `tail +3 /proc/partitions | awk '{print $4}' | grep '\([a-zA-Z]$\)\|\(c[0-9]*d[0-9]*$\)'`; do
+ # if ! echo $CDROMS | grep -qw $i; then
+ # echo $i
+ # fi
+ #done
}
+# mounts all the new file-systems, and creates the mount points when needed
+function mount_new_fs {
+ local -a mplist=($(sort -k2.1 /tmp/fsmnt 2>/dev/null|cut -f2 -d' ') )
+ local fs mp type
+
+ rm -f /tmp/fstab
+
+ echo "/proc /proc proc defaults 0 0" >> /tmp/fstab
+ echo "#/dev /dev tmpfs size=0,nr_inodes=4096,remount,nosuid 0 0" >> /tmp/fstab
+ echo "/dev/pts /dev/pts devpts defaults 0 0" >> /tmp/fstab
+ echo "/dev/cdrom /mnt/cdrom iso9660 defaults,noauto,ro,users,exec 0 0" >> /tmp/fstab
+
+ for mp in "${mplist[@]}"; do
+ fs=$(grep " $mp\$" /tmp/fsmnt 2>/dev/null|cut -f1 -d' ')
+ type=$(grep "^$fs " /tmp/fstype 2>/dev/null|cut -f2 -d' ')
+ if [ "$mp" != "swap" ]; then
+ mkdir -p -m 0755 $ROOTDIR$mp 2>/dev/null
+ mount -t $type $fs $ROOTDIR$mp
+ fi
+ if [ "$mp" = "/" ]; then
+ echo "#$fs $mp $type defaults,ro 1 1" >> /tmp/fstab
+ echo "/dev/root $mp $type defaults,ro 1 1" >> /tmp/fstab
+ mkdir -p -m 0755 $ROOTDIR/dev $ROOTDIR/proc $ROOTDIR/etc
+ mount -t proc proc $ROOTDIR/proc # may be needed for compressed files
+ elif [ "$mp" = "/boot" ]; then
+ echo "$fs $mp $type defaults,ro 1 2" >> /tmp/fstab
+ elif [ "$mp" = "swap" ]; then
+ echo "$fs $mp $type defaults 0 0" >> /tmp/fstab
+ else
+ echo "$fs $mp $type defaults 1 2" >> /tmp/fstab
+ fi
+ done
+ echo "/var/empty /var/empty tmpfs size=0,nr_inodes=1,ro,mode=0100,nosuid,nodev 0 0" >> /tmp/fstab
+}
+
+# unmounts all the new file-systems
+function unmount_new_fs {
+ local -a mplist=($(sort -rk 2.1 /proc/mounts 2>/dev/null | cut -f2 -d' ' | grep "^$ROOTDIR") )
+ local fs mp type
+
+ for mp in "${mplist[@]}"; do
+ if [ "$mp" != "swap" ]; then
+ umount $mp >/dev/null 2>&1
+ fi
+ done
+}
+
+
function setup_part {
- if [ -e /tmp/devmap -a -e /tmp/fstab ]; then
- echo "Filesystems are currently configured this way :"
- for i in `cut -f1 -d' ' /tmp/devmap`; do grep "^$i[ ]" /tmp/fstab | awk '{print $1 " => " $2 }'; done
- echo "-- end of list --"
- yesno "Do you want to change something (y/n) ?" "n"
- if [ "$REPLY" != "y" ]; then return 0; fi
- cp /tmp/fstab /tmp/fstab-
- cp /tmp/devmap /tmp/devmap-
- else
- touch /tmp/fstab- /tmp/devmap-
- fi
-
- # clean temporary files
- rm -rf /tmp/temp.$$ /tmp/fstab /tmp/devmap
-
- # unmount previously mounted file-systems
- for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do
- umount $part;
- done
+ if [ -e /tmp/devmap -a -e /tmp/fstab ]; then
+ echo "Filesystems are currently configured this way :"
+ for i in `cut -f1 -d' ' /tmp/devmap`; do grep "^$i[ ]" /tmp/fstab | awk '{print $1 " => " $2 }'; done
+ echo "-- end of list --"
+ yesno "Do you want to change something (y/n) ?" "n"
+ [ "$REPLY" = "y" ] || return 0
+ cp /tmp/fstab /tmp/fstab-
+ cp /tmp/devmap /tmp/devmap-
+ else
+ touch /tmp/fstab- /tmp/devmap-
+ fi
- echo "/proc /proc proc defaults 0 0" >> /tmp/fstab
- echo "/dev /dev tmpfs size=0,nr_inodes=4096,,remount 0 0" >> /tmp/fstab
- echo "/dev/pts /dev/pts devpts defaults 0 0" >> /tmp/fstab
- echo "/dev/cdrom /mnt/cdrom iso9660 defaults,noauto,ro,user 0 0" >> /tmp/fstab
+ # clean temporary files
+ rm -rf /tmp/temp.$$ /tmp/fstab /tmp/devmap
- echo "/dev/$(readlink /dev/cdrom) /dev/cdrom" >> /tmp/devmap
+ # unmount previously mounted file-systems
+ for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do
+ umount $part;
+ done
+
+ echo "/proc /proc proc defaults 0 0" >> /tmp/fstab
+ echo "#/dev /dev tmpfs size=0,nr_inodes=4096,remount 0 0" >> /tmp/fstab
+ echo "/dev/pts /dev/pts devpts defaults 0 0" >> /tmp/fstab
+ echo "/dev/cdrom /mnt/cdrom iso9660 defaults,noauto,ro,users 0 0" >> /tmp/fstab
+
+ echo "/dev/$(readlink /dev/cdrom) /dev/cdrom" >> /tmp/devmap
+ (grep -v ' CDROM$' /tmp/mounts 2>/dev/null; echo "/dev/$(readlink /dev/cdrom) CDROM") >/tmp/mounts- && mv /tmp/mounts- /tmp/mounts
+
+ # scan all disk
+ # for disk in $(list_disks); do
+ REPLY=${names[0]}
+ while menu_harddisk $REPLY; do
+ disk=${REPLY##/dev/}
- # scan all disk
- for disk in $(list_disks); do
# look for all detected partitions
- for spart in `sfdisk -l /dev/$disk 2>/dev/null | grep "^/" |tr '*' ' '| cut -f3- -d'/' | awk '{print $1 ":" $6 }'` ; do
+# for spart in `sfdisk -l /dev/$disk 2>/dev/null | grep "^/" |tr '*' ' '| cut -f3- -d'/' | awk '{print $1 ":" $6 }'` ; do
+
+
+ REPLY=
+ while { disk_read_part /dev/$disk ; menu_partition /dev/$disk $REPLY; } do
+ [ -z "$REPLY" ] && break
+ if [ "$REPLY" = "CLEAR" ] ; then
+ if menu_yesno "Warning !\n\nThis will erase the partition table for /dev/$disk.\nAll data will be lost.\n\nDo you still want to proceed ?" N; then
+ dd if=/dev/zero of=/dev/$disk bs=1024 count=1 > /dev/null 2>&1
+ (echo o ; echo w ) | fdisk /dev/$disk > /dev/null 2>&1
+ fi
+ REPLY=FDISK
+ continue
+ elif [ "$REPLY" = "FDISK" ]; then
+ fdisk /dev/$disk
+ REPLY=
+ continue
+ else
+ echo "menu format/mount pour $REPLY"
+ fi
+
+
+
+
+
# partition name
part=`echo $spart|cut -f1 -d:`
set -- `echo $spart | tr ':' ' '`
@@ -150,10 +648,20 @@ function setup_part {
case "$mountpoint" in
/) echo "$part /dev/root" >> /tmp/devmap ;;
/boot) echo "$part /dev/boot" >> /tmp/devmap ;;
- swap) echo "$part /dev/swap" >> /tmp/devmap ; echo "$part swap swap defaults 0 0" >> /tmp/fstab;;
+ swap) echo "$part /dev/swap" >> /tmp/devmap ;
+ echo "$part swap swap defaults 0 0" >> /tmp/fstab;;
*) echo "$part /dev/fs/$(echo ${mountpoint#/} |tr '/' '.')" >> /tmp/devmap ;;
esac
+
+ case "$mountpoint" in
+ swap)
+ (grep -v "^$part " /tmp/mounts 2>/dev/null; echo "$part SWAP") >/tmp/mounts- && mv /tmp/mounts- /tmp/mounts;;
+ *)
+ (grep -v "^$part " /tmp/mounts 2>/dev/null; echo "$part $mountpoint") >/tmp/mounts- && mv /tmp/mounts- /tmp/mounts;;
+ esac
+
+
formatcmd=''
# format linux partitions
if [ $type = 82 -o $type = 83 -o $type = 8e -o $type = fd ] ; then
@@ -294,8 +802,10 @@ function setup_config {
BOOTDEV=${BOOTDEV:-`echo $ROOTDEV | sed 's/[0-9]\+$//'`}
ask "Choose device on which LILO will be installed " $BOOTDEV
BOOTDEV=$REPLY
- grep -v '/dev/mbr$' /tmp/devmap > $TMP/devmap
+ grep -v '/dev/\(mbr\|cdrom\)$' /tmp/devmap > $TMP/devmap 2>/dev/null
echo "$BOOTDEV /dev/mbr" >> $TMP/devmap
+ echo "/dev/$(readlink /dev/cdrom) /dev/cdrom" >> $TMP/devmap
+
# build a new lilo.conf
cd $MNT
@@ -403,7 +913,7 @@ EOF
# if /var is on its own filesystem, /tmp must be a true filesystem too.
if grep -q ' \(/dev/fs/var\|/dev/fs/var\.tmp\)$' $TMP/devmap; then
if ! grep -q "^[^ ]\+[ ]\+/tmp[ ]" $TMP/fstab; then
- echo "/tmp /tmp tmpfs defaults 0 0" >> $TMP/fstab
+ echo "/tmp /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TMP/fstab
fi
fi
@@ -444,6 +954,10 @@ function do_lilo {
# main
+ROOTDIR=/var/mount
+PKGDIR=/home/pkg
+SHELLDIR=/
+
init
if [ $0 = "mkdisk" ] ; then setup_part && exit 0 ; exit 1 ;
@@ -464,132 +978,251 @@ while [ $# -ge 1 -a "$end" -ne 1 ] ; do
shift
done
-ROOTDIR=/mnt/disk
-PKGDIR=/home/pkg
-SHELLDIR=/
-
-action=1
-while [ "$action" != "q" -a "$action" != "Q" ] ; do
+action="PART"
+while [ -n "$action" ] ; do
- ROOTDEV=`mount | grep " on $ROOTDIR " | cut -f1 -d' '`
+ ROOTDEV=$(mount | grep " on $ROOTDIR " | cut -f1 -d' ')
- echo
- echo "Possible actions are :"
- echo "1: Run fdisk"
- echo "2: Setup filesystems"
- echo "3: Install packages"
- echo "4: Build running config"
- echo "5: Save built config for next reboot"
- echo "6: Run lilo"
- echo "7: Unmount all"
- echo "s: Shell"
- echo "q: Quit"
-
- ask "Select an action (1..7/s/q)" "$action"
-
- if [ "$REPLY" = "q" -o "$REPLY" = "Q" ] ; then break; fi
- if [ "$REPLY" = "s" -o "$REPLY" = "S" ] ; then (cd $SHELLDIR; pwd; sh -i); REPLY=$action; continue; fi
-
- action=`expr $REPLY + 1`
- if [ "$action" = 8 ] ; then action=q ; fi
- echo
- case $REPLY in
- 1)
+# echo
+# echo "Possible actions are :"
+# echo "1: Run fdisk"
+# echo "2: Setup filesystems"
+# echo "3: Install packages"
+# echo "4: Build running config"
+# echo "5: Save built config for next reboot"
+# echo "6: Run lilo"
+# echo "7: Unmount all"
+# echo "s: Shell"
+# echo "q: Quit"
+#
+# ask "Select an action (1..7/s/q)" "$action"
+
+ menu_main $action
+
+ [ -z "$REPLY" ] && break
+
+ if [ "$REPLY" = "SHELL" ] ; then (cd $SHELLDIR; echo -n "Current directory : "; pwd; bash -i); REPLY=$action; continue; fi
+
+ case $REPLY in
+ PART)
# unmount previously mounted file-systems
- for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do umount $part; done
-
- for disk in $(list_disks); do
- sfdisk -l /dev/$disk
- yesno "Clear partition table for '/dev/$disk' (y/n)?" "n"
- if [ "$REPLY" = "y" ] ; then
- dd if=/dev/zero of=/dev/$disk bs=1024 count=1 > /dev/null 2>&1
- (echo o ; echo w ) | fdisk /dev/$disk > /dev/null 2>&1
- fi
- yesno "Run 'fdisk' for '/dev/$disk' (y/n)" "y"
- if [ "$REPLY" = "y" ] ; then
- fdisk /dev/$disk
- fi
- done
- SHELLDIR=/
- ;;
- 2)
- setup_part
- SHELLDIR=/
- ;;
- 3)
- cd /
- if [ "$ROOTDEV" != "" ] ; then
- ask "Packages directory, or files pattern ($PKGDIR, $PKGDIR/*.lst, *.prf, *.tgz)"$'\n'" " $PKGDIR ; PKGDIR="$REPLY"
- if [ -d "$PKGDIR" ]; then
- list=`cd $PKGDIR && ls *.prf *.lst *.tgz 2>/dev/null`
- else
- list=`basename "$PKGDIR"`
- PKGDIR=`dirname "$PKGDIR"`
- list=$(cd $PKGDIR && echo $list)
- fi
- echo "Package list :"; (cd $PKGDIR && ls $list); echo
- for pack in $list ; do
- ask "Install package '$pack' (y/n/./<other dest>) ?" "y"
- INSTDIR=/
- if [ "`echo $REPLY | cut -c1`" = "/" ] ; then INSTDIR=$REPLY ; fi
- if [ "$REPLY" = "." ]; then break; fi
- if [ "$REPLY" != "n" -a "$REPLY" != "N" ] ; then
- case "$pack" in
- *lst) cat $PKGDIR/$pack | xargs cp --target-directory=$ROOTDIR$INSTDIR -p --parents -d -R -x ;;
- *tgz) mkdir -p -m 0755 $ROOTDIR$INSTDIR && tar zpxf $PKGDIR/$pack -C $ROOTDIR$INSTDIR ;;
- *prf) flxextract -R $ROOTDIR$INSTDIR -i $PKGDIR/$pack ;;
- esac
- fi
- done
- check_directories || exit 1
- fi
- SHELLDIR=/
- ;;
- 4)
- check_directories || exit 1
- if [ "$UPDATE_ONLY" != "n" -a "$UPDATE_ONLY" != "y" ]; then
- echo "Existing files can be REPLACED or UPDATED."
- yesno "Do you prefer to UPDATE existing files (y/n) ?" "y"
- UPDATE_ONLY="$REPLY"
- fi
- setup_config $ROOTDIR
- echo "done."
- echo "New files have been written to /tmp/newconf/"
- echo "You can check them now by starting a shell."
- SHELLDIR=/tmp/newconf
- (cd $SHELLDIR ; ls -lart)
- ;;
- 5)
- echo "Saving config (.preinit, startup.rc, config.rc, fstab, lilo.conf, passwd)"
- apply_config $ROOTDIR
- echo "Saving config ... done."
- echo "Updating dynamic files (/etc/formilux/sig.dat, /etc/ld.so.cache) ... "
- ldconfig -r $ROOTDIR > /dev/null 2>&1
-
- for SYSTEMMAP in `echo $ROOTDIR/boot/System.map-*`; do
- KERNVER=${SYSTEMMAP#$ROOTDIR/boot/System.map-}
- chroot $ROOTDIR depmod -a -F /boot/System.map-$KERNVER $KERNVER
- done
-
- echo "Signing the filesystem... (this may take a while)"
- cd $ROOTDIR ; signfs -x `mount|grep -v ' type \(tmpfs\|ramfs\)'|grep "^/.* $ROOTDIR "| \
- sed "s@^.*$ROOTDIR\([^ ]*\) .*@.\1@"` > /etc/formilux/sig.dat
- echo "Updating dynamic files ... done."
- SHELLDIR=/
- ;;
- 6)
- do_lilo
- SHELLDIR=/
- ;;
- 7)
- cd /
- for mp in `grep "$ROOTDIR" /proc/mounts | cut -f2 -d' ' | sort -r` ; do
- umount -n $mp
+ #for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do umount $part; done
+ unmount_new_fs
+ detect_disks
+ REPLY=${names[0]}
+ while menu_harddisk $REPLY; do
+ disk=${REPLY##/dev/}
+
+ #sfdisk -l /dev/$disk
+ #yesno "Clear partition table for '/dev/$disk' (y/n)?" "n"
+ REPLY=
+ while { disk_read_part /dev/$disk ; menu_partition /dev/$disk $REPLY; } do
+ part=$REPLY
+ [ -z "$REPLY" ] && break
+ if [ "$REPLY" = "CLEAR" ] ; then
+ if menu_yesno "Warning !\n\nThis will erase the partition table for /dev/$disk.\nAll data will be lost.\n\nDo you still want to proceed ?" N; then
+ dd if=/dev/zero of=/dev/$disk bs=1024 count=1 > /dev/null 2>&1
+ (echo o ; echo w ) | fdisk /dev/$disk > /dev/null 2>&1
+ fi
+ REPLY=FDISK
+ elif [ "$REPLY" = "FDISK" ]; then
+ fdisk /dev/$disk
+ REPLY=
+ else
+ part=$REPLY
+ REPLY=
+ while menu_setupfs /dev/$part $REPLY; do
+ case "$REPLY" in
+ SHELL)
+ (cd $SHELLDIR; echo -n "Current directory : "; pwd; bash -i)
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part auto") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ # goes automatically to default format
+ REPLY=
+ ;;
+ MNT)
+ menu_mount_point /dev/$part
+ # goes automatically to default format
+ REPLY=
+ ;;
+ SWAP)
+ mkswap /dev/$part
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part swap") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ REPLY=EXIT
+ ;;
+ SWAPC)
+ mkswap -c /dev/$part
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part swap") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ REPLY=EXIT
+ ;;
+ EXT2S)
+ mke2fs -b 1024 -m 1 -s 1 /dev/$part
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part ext2") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ REPLY=EXIT
+ ;;
+ EXT2L)
+ mke2fs -b 4096 -s 1 /dev/$part
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part ext2") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ REPLY=EXIT
+ ;;
+ EXT3)
+ mke2fs -b 4096 -s 1 -j /dev/$part
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part ext3") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ REPLY=EXIT
+ ;;
+ REISER)
+ mkreiserfs -h r5 /dev/$part
+ (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part reiserfs") >/tmp/fstype-
+ mv /tmp/fstype- /tmp/fstype
+ REPLY=EXIT
+ ;;
+ esac
+ # this is done to exit right after an mkfs
+ [ "$REPLY" = "EXIT" ] && break;
+ done
+ REPLY=
+ fi
+ done
+ # things might have changed !
+ detect_disks
+ REPLY=/dev/$disk
done
+ # we now have to mount all these file systems
+ mount_new_fs
SHELLDIR=/
+ action=SOURCE
;;
+ SOURCE)
+ action=SOURCE
+ while menu_select_source; do
+ case "$REPLY" in
+ CDROM)
+ menu_select_cdrom && break;
+ ;;
+ DISK)
+ menu_select_disk
+ ;;
+ NFS)
+ menu_select_nfs
+ ;;
+ DIR)
+ menu_select_dir
+ ;;
+ esac
+ done
+ PKGDIR=$(readlink /var/flx-pkg 2>/dev/null)
+ [ -d "/var/flx-pkg/." ] && action=PKG
+ ;;
+ PKG)
+ cd /
+ if [ "$ROOTDEV" != "" ] ; then
+ #ask "Packages directory, or files pattern ($PKGDIR, $PKGDIR/*.lst, *.prf, *.tgz)"$'\n'" " $PKGDIR ; PKGDIR="$REPLY"
+ #if [ -d "$PKGDIR" ]; then
+ # list=`cd $PKGDIR && ls *.prf *.lst *.tgz 2>/dev/null`
+ #else
+ # list=`basename "$PKGDIR"`
+ # PKGDIR=`dirname "$PKGDIR"`
+ # list=$(cd $PKGDIR && echo $list)
+ #fi
+ menu_pkg_dir
+ list=( ); idx=0
+ for pack in $(shopt -s nullglob ; cd $PKGDIR && echo *.{prf,tgz}); do
+ list[idx++]=$pack
+ list[idx++]=""
+ if [ -z "${pack##[0-9][0-9][0-9]_*}" ]; then
+ # pre-selects every numbered package
+ list[idx++]="on"
+ else
+ list[idx++]="off"
+ fi
+ done
+
+ list=( $(dialog --title " Formilux Installation Utility " --no-shadow \
+ --checklist "Packages Selection\n\n Press <Space> to select/deselect a package.\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to install your selection." 24 80 12 "${list[@]}" 2>&1) )
+
+ # dialog returns quoted words
+ eval list=( "${list[@]}" )
+ [ ${#list[@]} -gt 0 ] || break
+
+ for pack in "${list[@]}" ; do
+ case "$pack" in
+ *tgz)
+ [ -d "$ROOTDIR" ] || mkdir -p -m 0755 $ROOTDIR
+ [ -d "$ROOTDIR/etc/formilux" ] || { mkdir -p -m 0750 $ROOTDIR/etc/formilux; chgrp adm $ROOTDIR/etc/formilux; }
+ echo "### begin $pack ###" >> $ROOTDIR/etc/formilux/install.log
+ tar zpvxf $PKGDIR/$pack -C $ROOTDIR >> $ROOTDIR/etc/formilux/install.log
+ echo "### end $pack ###" >> $ROOTDIR/etc/formilux/install.log
+ ;;
+ *prf)
+ [ -d "$ROOTDIR/etc/formilux" ] || { mkdir -p -m 0750 $ROOTDIR/etc/formilux; chgrp adm $ROOTDIR/etc/formilux; }
+ echo "### begin $pack ###" >> $ROOTDIR/etc/formilux/install.log
+ rm -f /tmp/${pack##*/}.log
+ flxextract -R $ROOTDIR -p $PKGDIR -i $PKGDIR/$pack -l /tmp/${pack##*/}.log
+ cat /tmp/${pack##*/}.log >> $ROOTDIR/etc/formilux/install.log
+ echo "### end $pack ###" >> $ROOTDIR/etc/formilux/install.log
+ ;;
+ esac
+ done
+ check_directories || exit 1
+ SHELLDIR=/
+ action=CONFIG
+ else
+ action=PART
+ fi
+ ;;
+ CONFIG)
+ check_directories || exit 1
+ if [ "$UPDATE_ONLY" != "n" -a "$UPDATE_ONLY" != "y" ]; then
+ echo "Existing files can be REPLACED or UPDATED."
+ yesno "Do you prefer to UPDATE existing files (y/n) ?" "y"
+ UPDATE_ONLY="$REPLY"
+ fi
+ setup_config $ROOTDIR
+ echo "done."
+ echo "New files have been written to /tmp/newconf/"
+ echo "You can check them now by starting a shell."
+ SHELLDIR=/tmp/newconf
+ (cd $SHELLDIR ; ls -lart)
+ action=SAVE
+ ;;
+ SAVE)
+ echo "Saving config (.preinit, startup.rc, config.rc, fstab, lilo.conf, passwd)"
+ apply_config $ROOTDIR
+ echo "Saving config ... done."
+ echo "Updating dynamic files (/etc/formilux/sig.dat, /etc/ld.so.cache) ... "
+ ldconfig -r $ROOTDIR > /dev/null 2>&1
+
+ for SYSTEMMAP in `echo $ROOTDIR/boot/System.map-*`; do
+ KERNVER=${SYSTEMMAP#$ROOTDIR/boot/System.map-}
+ chroot $ROOTDIR depmod -a -F /boot/System.map-$KERNVER $KERNVER
+ done
+
+ echo "Signing the filesystem... (this may take a while)"
+ cd $ROOTDIR ; signfs -x `mount|grep -v ' type \(tmpfs\|ramfs\)'|grep "^/.* $ROOTDIR "| \
+ sed "s@^.*$ROOTDIR\([^ ]*\) .*@.\1@"` > /etc/formilux/sig.dat
+ echo "Updating dynamic files ... done."
+ SHELLDIR=/
+ action=LILO
+ ;;
+ LILO)
+ do_lilo
+ SHELLDIR=/
+ action=UNMOUNT
+ ;;
+ UNMOUNT)
+ cd /
+ unmount_new_fs
+ umount -l /mnt/cdrom >/dev/null 2>&1
+ SHELLDIR=/
+ action=EXIT
+ ;;
*)
- ;;
+ ;;
esac
done
diff --git a/scripts/mkinstall.old b/scripts/mkinstall.old
new file mode 100755
index 0000000..3ccd20e
--- /dev/null
+++ b/scripts/mkinstall.old
@@ -0,0 +1,595 @@
+#!/bin/sh
+#
+# /sbin/mkinstall - Formilux System Installer - version 1.0.0 - 2003-03-20
+# This file is part of the Formilux project : http://formilux.ant-computing.com/
+#
+# Copyright (C) 2001-2003 Benoit Dolez & Willy Tarreau
+# mailto: benoit@ant-computing.com,willy@ant-computing.com
+#
+# This program is licenced under GPLv2 ( http://www.gnu.org/licenses/gpl.txt )
+
+# This function collects some information in /proc and other places.
+# It should be called ASAP.
+
+function init {
+ #umount /mnt/cdrom >/dev/null 2>&1 # to avoid stupid recursive copying !
+ CDROMS=$(grep -i '^drive name:' /proc/sys/dev/cdrom/info |cut -f2- -d:)
+}
+
+# user interface functions
+function ask {
+ echo -n "$1 [$2] : "; read
+ if [ "$REPLY" = "" ]; then REPLY=$2; fi
+}
+
+function yesno {
+ echo -n "$1 [$2] : "; read ; REPLY=`echo $REPLY | cut -c1`
+ if [ "$REPLY" = "" ]; then REPLY=$2; fi
+ if [ "$REPLY" = o -o "$REPLY" = y -o "$REPLY" = Y ]; then
+ REPLY="y"
+ fi
+}
+
+#
+function check_directories {
+ if [ ! -d $ROOTDIR/etc/. ] ; then
+ if [ -d $ROOTDIR/boot/etc/. ] ; then
+ ln -s boot/etc $ROOTDIR/etc
+ else
+ echo "Can't find 'etc' directory neither in '/' nor in '/boot'"
+ return 1
+ fi
+ fi
+ if [ ! -d $ROOTDIR/var/. ] ; then
+ mkdir $ROOTDIR/var ; fi
+ if [ ! -d $ROOTDIR/var/tmp ] ; then
+ mkdir $ROOTDIR/var/tmp ; chmod 1777 $ROOTDIR/var/tmp ; fi
+ if [ ! -d $ROOTDIR/var/run ] ; then
+ mkdir $ROOTDIR/var/run ; fi
+ if [ ! -d $ROOTDIR/var/spool ] ; then
+ mkdir $ROOTDIR/var/spool ; fi
+ if [ ! -d $ROOTDIR/var/log ] ; then
+ mkdir $ROOTDIR/var/log ; fi
+ if [ ! -d $ROOTDIR/var/cache ] ; then
+ mkdir $ROOTDIR/var/cache ; fi
+ if [ ! -d $ROOTDIR/var/adm/. ] ; then
+ ln -s log $ROOTDIR/var/adm ; fi
+
+ return 0
+}
+
+# this function lists all hard drives found, but hides CDROMs
+function list_disks {
+ for i in `tail +3 /proc/partitions | awk '{print $4}' | grep '\([a-zA-Z]$\)\|\(c[0-9]*d[0-9]*$\)'`; do
+ if ! echo $CDROMS | grep -qw $i; then
+ echo $i
+ fi
+ done
+}
+
+function setup_part {
+
+ if [ -e /tmp/devmap -a -e /tmp/fstab ]; then
+ echo "Filesystems are currently configured this way :"
+ for i in `cut -f1 -d' ' /tmp/devmap`; do grep "^$i[ ]" /tmp/fstab | awk '{print $1 " => " $2 }'; done
+ echo "-- end of list --"
+ yesno "Do you want to change something (y/n) ?" "n"
+ if [ "$REPLY" != "y" ]; then return 0; fi
+ cp /tmp/fstab /tmp/fstab-
+ cp /tmp/devmap /tmp/devmap-
+ else
+ touch /tmp/fstab- /tmp/devmap-
+ fi
+
+ # clean temporary files
+ rm -rf /tmp/temp.$$ /tmp/fstab /tmp/devmap
+
+ # unmount previously mounted file-systems
+ for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do
+ umount $part;
+ done
+
+ echo "/proc /proc proc defaults 0 0" >> /tmp/fstab
+ echo "/dev /dev tmpfs size=0,nr_inodes=4096,,remount 0 0" >> /tmp/fstab
+ echo "/dev/pts /dev/pts devpts defaults 0 0" >> /tmp/fstab
+ echo "/dev/cdrom /mnt/cdrom iso9660 defaults,noauto,ro,user 0 0" >> /tmp/fstab
+
+ echo "/dev/$(readlink /dev/cdrom) /dev/cdrom" >> /tmp/devmap
+
+ # scan all disk
+ for disk in $(list_disks); do
+ # look for all detected partitions
+ for spart in `sfdisk -l /dev/$disk 2>/dev/null | grep "^/" |tr '*' ' '| cut -f3- -d'/' | awk '{print $1 ":" $6 }'` ; do
+ # partition name
+ part=`echo $spart|cut -f1 -d:`
+ set -- `echo $spart | tr ':' ' '`
+ set -- $* `fdisk -s /dev/$1` `sfdisk -l /dev/$disk 2>/dev/null | grep "/dev/$1 " | cut -c15-`
+
+ # hide mounted partitions
+ part=/dev/$part
+ if grep -q "$part " /proc/mounts > /dev/null ; then continue ; fi
+
+ # hide empty or extended partitions
+ if [ $2 = 0 -o $2 = 5 ] ; then continue ; fi
+
+ # partition size in Mega Bytes
+ size=$[ $3 / 1024]
+ # partition type in human readable form
+ type=$2
+ shift 8
+ htype=$*
+
+ # redo while not a good value
+ askagain=y
+ unset mountpoint
+ while [ "$askagain" = "y" ] ; do
+ askagain=n
+ echo
+ echo "Partition : $part ($htype, ${size} MB)"
+
+ # non linux partition
+ if [ $type != 82 -a $type != 83 -a $type != 8e -a $type != fd ] ; then
+ yesno "$part isn't a standard linux partition, would you like an entry in /etc/fstab (y/n)?" "n"
+ if [ "$REPLY" = "n" ] ; then continue ; fi
+ fstype=noauto
+ else
+ fstype=auto
+ fi
+
+ # getting mount point
+ if [ $type = 82 ] ; then
+ mountpoint=swap
+ else
+ mountpoint=$(grep "^$part[ ]" /tmp/fstab- | awk '{print $2 }')
+ fi
+ ask " Choose a mount point (swap,/,/boot,/var,...) or [Enter] for none" "$mountpoint"
+ # remove useless leading and trailing slashes
+ mountpoint=$(echo $REPLY|sed 's@^\([/]*\)\(/.*\)$@\2@'|sed 's@^\(.*[^/]\)\([/]*\)$@\1@')
+ if [ -z "$mountpoint" ] ; then break ; fi
+
+ case "$mountpoint" in
+ /) echo "$part /dev/root" >> /tmp/devmap ;;
+ /boot) echo "$part /dev/boot" >> /tmp/devmap ;;
+ swap) echo "$part /dev/swap" >> /tmp/devmap ; echo "$part swap swap defaults 0 0" >> /tmp/fstab;;
+ *) echo "$part /dev/fs/$(echo ${mountpoint#/} |tr '/' '.')" >> /tmp/devmap ;;
+ esac
+
+ formatcmd=''
+ # format linux partitions
+ if [ $type = 82 -o $type = 83 -o $type = 8e -o $type = fd ] ; then
+ # tell how to format
+ echo " 0: -- DO NOT format this partition (default) --" ; ch=0
+ if [ "$mountpoint" = "swap" ] ; then
+ ch1="mkswap $part" ; echo " >1: $ch1"
+ ch2="mkswap -c $part" ; echo " 2: $ch2 (with check)"
+ elif [ "`echo $mountpoint|cut -c1`" = "/" ] ; then
+ ch1="mke2fs -b 1024 -m 1 -s 1 $part"
+ if [ "$size" -lt 64 ]; then
+ echo " >1: $ch1 (small ext2)"
+ else
+ echo " 1: $ch1 (small ext2)"
+ fi
+ ch2="mke2fs -b 4096 -s 1 $part" ; echo " 2: $ch2 (large ext2)"
+ ch3="mke2fs -b 4096 -s 1 -j $part"
+ if [ "$size" -ge 64 ]; then
+ echo " >3: $ch3 (ext3)"
+ else
+ echo " 3: $ch3 (ext3)"
+ fi
+ ch4="mkreiserfs -h r5 $part" ; echo " 4: $ch4 (reiserfs)"
+ fi
+ ask " Select a format method or enter the complete command" "$ch"
+ case $REPLY in
+ 0) formatcmd='' ;;
+ [1-9]) formatcmd=`eval echo '\$ch'$REPLY` ;;
+ *) formatcmd=$REPLY ;;
+ esac
+ fi
+ done
+
+ # execute format
+ if [ "$formatcmd" ] ; then
+ echo -n "Doing: '$formatcmd': "
+ eval "echo y | $formatcmd" > /tmp/error.$$ 2>&1
+ if [ "$?" = "0" ] ; then
+ echo "done."
+ else
+ echo "failed."
+ echo "--------------------------------------------------------"
+ echo "$formatcmd said:"
+ sed -e "s/^/>> /" /tmp/error.$$
+ echo "----------- Filesystem will not be mounted -------------"
+ mountpoint=""
+ fi
+ fi
+ if [ "`echo $mountpoint|cut -c1`" = "/" ] ; then
+ echo "$mountpoint -t $fstype $part" >> /tmp/temp.$$
+ fi
+ done
+ done
+
+ # now we will mount all the filesystems we have just created, and add them to fstab
+ sort /tmp/temp.$$ | while read ; do
+ set -- $REPLY
+ mp=$1 ; shift
+ if [ ! -d $ROOTDIR$mp ] ; then mkdir -p $ROOTDIR$mp ; echo "Creating directory $mp" ; fi
+ if [ $2 != noauto ] ; then
+ echo -n "Mounting $mp ($3): "
+ mount -n $* $ROOTDIR$mp > /dev/null 2>&1
+ if [ "$?" = "0" ] ; then echo "done." ; else
+ echo "failed."
+ echo "##failed## $3 $mp $2 defaults 1 1" >> /tmp/fstab
+ fi
+ else
+ echo "#$3 $1 auto defaults 0 0" >> /tmp/fstab
+ fi
+ done
+ mount | grep '^[ ]*/' | grep "$ROOTDIR[/ ]" | sed "s@$ROOTDIR[/]*@/@" | \
+ awk '{ printf "%s\t%s\t%s\tdefaults%s\t1 %s\n",$1,$3,$5,($3=="/" || $3=="/boot")?",ro":"",($3=="/")?"1":"2" }' >> /tmp/fstab
+ #grep '^/' /proc/swaps | awk '{ print $1 "\tswap \tswap \tdefault 0 0"}' >> /tmp/fstab
+
+ mkdir -p -m 0755 $ROOTDIR/dev $ROOTDIR/proc $ROOTDIR/etc $ROOTDIR/mnt/cdrom
+ mount -t proc proc $ROOTDIR/proc # may be needed for compressed files
+
+### sed -e "s,^#L.*cdrom\$,ln ` readlink /dev/cdrom` /dev/cdrom," < /.preinit > $ROOTDIR/.preinit
+
+ rm -f /tmp/temp.$$
+ return 0
+}
+
+function setup_keyboard {
+ sed -n '/^service keyboard/,/^ *$/p' < /etc/config.rc
+}
+
+function setup_mouse {
+ sed -n '/^service mouse/,/^ *$/p' < /etc/config.rc
+}
+
+function setup_network {
+ echo "# hostname formilux"
+ echo "# interface eth0"
+ echo "# ip address 10.101.20.4/16"
+ echo "# ip dhcp"
+ echo "# service network"
+}
+
+# (re)build config.rc, startup.rc, fstab, devmap, lilo.conf
+function setup_config {
+ local MNT="$1"
+ local MPWD=$PWD
+ local TMP=/tmp/newconf
+
+ if [ ! -w /tmp ] ; then
+ echo "Directory /tmp not writable"; exit 1
+ fi
+
+ mkdir -p $TMP >/dev/null 2>&1
+
+ if [ "$MNT" = "" ] ; then MNT="$ROOTDIR"; fi
+
+# copy startup.rc and config.rc
+ rm -f $TMP/config.rc $TMP/startup.rc
+ if [ "$UPDATE_ONLY" != "y" -o ! -e $MNT/etc/config.rc ]; then
+ echo >> $TMP/config.rc
+ echo "# service syslogd" >> $TMP/config.rc
+ echo >> $TMP/config.rc
+ setup_network >> $TMP/config.rc
+ echo >> $TMP/config.rc
+ setup_keyboard >> $TMP/config.rc
+ setup_mouse >> $TMP/config.rc
+ chmod 644 $TMP/config.rc
+ fi
+
+ if [ "$UPDATE_ONLY" != "y" -o ! -e $MNT/etc/startup.rc ]; then
+ echo "#!/bin/sh" >> $TMP/startup.rc
+ echo "echo -n \"Default configuration ... \" " >> $TMP/startup.rc
+ echo "/sbin/init.d/sysprofiles /etc/config.rc" >> $TMP/startup.rc
+ chmod 755 $TMP/startup.rc
+ fi
+
+# copy fstab
+ cp /tmp/fstab $TMP/fstab
+
+# copy devmap
+ BOOTDEV=${BOOTDEV:-`echo $ROOTDEV | sed 's/[0-9]\+$//'`}
+ ask "Choose device on which LILO will be installed " $BOOTDEV
+ BOOTDEV=$REPLY
+ grep -v '/dev/mbr$' /tmp/devmap > $TMP/devmap
+ echo "$BOOTDEV /dev/mbr" >> $TMP/devmap
+
+# build a new lilo.conf
+ cd $MNT
+
+ KERNVER=`ls boot/*/bzImage | tail -1 | cut -f2 -d/`
+ KERNLBL=`echo $KERNVER | tr -d '.-'`
+ cat > $TMP/lilo.conf <<EOF
+serial = 0,9600n8
+boot = $BOOTDEV
+default = l$KERNLBL
+EOF
+
+ for bootimg in `ls boot/*/bzImage` ; do
+ echo "image = /$bootimg" >> $TMP/lilo.conf
+ echo " label = l`echo $bootimg | cut -f2 -d/ | tr -d '.-'`" >> $TMP/lilo.conf
+ echo " append = \"root=$ROOTDEV\"" >> $TMP/lilo.conf
+ echo " read-only" >> $TMP/lilo.conf
+ done
+
+ if [ `grep "label =" $TMP/lilo.conf | wc -l` = 0 ]; then
+ echo
+ echo "WARNING!!! no kernel was found in $MNT/boot !!!"
+ echo "You must install a kernel and edit $TMP/lilo.conf or your system will never boot."
+ echo
+ sleep 1
+ fi
+
+# copy /.preinit
+ if [ -e $MNT/.preinit -a "$UPDATE_ONLY" = "y" ]; then
+ cp $MNT/.preinit $TMP/.preinit
+ else
+ cp /.preinit $TMP/.preinit
+ fi
+
+ # 1st complicated part : merge old and new fstab.
+ # Method:
+ # - mount points only in old fstab are kept as-is
+ # - mount points in both with same types only have their dev updated
+ # - mount points in both with diff types are fully updated
+ # - mount points only in new fstab are merged
+ if [ "$UPDATE_ONLY" = "y" -a -e $MNT/etc/fstab ]; then
+ rm -f $TMP/fstab
+ while read; do
+ set -- $REPLY
+ if ! grep -q "^[^ ]\+[ ]\+${2}[ ]" /tmp/fstab; then
+ # not found
+ echo "$REPLY" >> $TMP/fstab
+ elif ! grep -q "^[^ ]\+[ ]\+${2}[ ]\+${3}[ ]" /tmp/fstab; then
+ # not found with the same type
+ echo "##old##$REPLY" >> $TMP/fstab
+ grep "^[^ ]\+[ ]\+${2}[ ]" /tmp/fstab >> $TMP/fstab
+ else
+ # found with the same type. We may have to update the device
+ dev=`grep "^[^# ]\+[ ]\+${2}[ ]" /tmp/fstab|head -1|awk '{print $1}'`
+ if [ "$dev" -a "$dev" != "$1" ]; then
+ echo "##old##$REPLY" >> $TMP/fstab
+ echo "$dev $2 $3 $4 $5 $6" >> $TMP/fstab # keep options
+ else
+ echo "$REPLY" >> $TMP/fstab # was commented or the same
+ fi
+ fi
+ done < $MNT/etc/fstab
+
+ # add new entries
+ while read; do
+ set -- $REPLY
+ if ! grep -q "^[^ ]\+[ ]\+${2}[ ]" $TMP/fstab; then
+ echo "$REPLY" >> $TMP/fstab
+ fi
+ done < /tmp/fstab
+ fi
+
+ # try to update lilo.conf
+
+ if [ -e $MNT/etc/lilo.conf -a "$UPDATE_ONLY" = "y" ]; then
+ rm -f $TMP/lilo.conf
+ if grep -q "^image.*$KERNVER" $MNT/etc/lilo.conf; then
+ # the latest kernel is referenced. We can use this conf.
+ (echo "boot = $BOOTDEV" ; grep -v "^boot[ ]*=[ ]*$BOOTDEV" $MNT/etc/lilo.conf | sed 's/^\(boot[ ]*=\)/##old##\1/') > $TMP/lilo.conf
+ else
+ # the latest kernel is missing from lilo.conf.
+ (echo "boot = $BOOTDEV" ; grep -v "^boot[ ]*=[ ]*$BOOTDEV" $MNT/etc/lilo.conf | sed 's/^\(boot[ ]*=\)/##old##\1/') | sed -e 's:^\(image.*=[^/]*/boot/\)\([^/]*\)\(/.*\)$:\1'$KERNVER'\3:' > $TMP/lilo.conf
+ fi
+ fi
+
+ # now, we may have to update .preinit to create aliased entries.
+ # we remove all references to devices that have been updated
+
+ grep -v "^[#]*\(ln\|L\).*[ ]\+\($(echo `cut -f2 -d' ' $TMP/devmap`|sed 's@ @\\|@g')\)" $TMP/.preinit > $TMP/.preinit-
+ grep -v ' /dev/fs/' $TMP/devmap | sed 's@^/dev/@ln @' >> $TMP/.preinit-
+ if grep -q ' /dev/fs' $TMP/devmap; then
+ if ! grep -q "^\(md\|M\)[ ]\+/dev/fs" $TMP/.preinit-; then
+ echo "md /dev/fs 755" >> $TMP/.preinit-
+ fi
+ grep ' /dev/fs/' $TMP/devmap | sed 's@^/dev@ln ..@' >> $TMP/.preinit-
+ fi
+ mv $TMP/.preinit- $TMP/.preinit ; chmod 711 $TMP/.preinit
+
+ rm -f $TMP/passwd
+ if [ "$UPDATE_ONLY" != "y" -o ! -e $MNT/etc/passwd ]; then
+ sed -e 's@/home/admin@/root@' < /etc/passwd |grep -v '^\(squid:\|pdnsd:\|flx:\|install:\)' > $TMP/passwd
+ chmod 644 $TMP/passwd
+ fi
+
+ # if /var is on its own filesystem, /tmp must be a true filesystem too.
+ if grep -q ' \(/dev/fs/var\|/dev/fs/var\.tmp\)$' $TMP/devmap; then
+ if ! grep -q "^[^ ]\+[ ]\+/tmp[ ]" $TMP/fstab; then
+ echo "/tmp /tmp tmpfs defaults 0 0" >> $TMP/fstab
+ fi
+ fi
+
+ cd $MPWD
+ return 0
+}
+
+function apply_config {
+ local MNT=$1
+ local TMP=/tmp/newconf
+
+ [ -e $TMP/.preinit ] && (rm -f $MNT/.preinit ; cp -p $TMP/.preinit $MNT)
+ [ -e $TMP/passwd ] && (rm -f $MNT/etc/passwd ; cp -p $TMP/passwd $MNT/etc)
+ [ -e $TMP/lilo.conf ] && (rm -f $MNT/etc/lilo.conf ; cp -p $TMP/lilo.conf $MNT/etc)
+ [ -e $TMP/fstab ] && (rm -f $MNT/etc/fstab ; cp -p $TMP/fstab $MNT/etc)
+ [ -e $TMP/config.rc ] && (rm -f $MNT/etc/config.rc ; cp -p $TMP/config.rc $MNT/etc)
+ [ -e $TMP/startup.rc ] && (rm -f $MNT/etc/startup.rc ; cp -p $TMP/startup.rc $MNT/etc)
+
+ # replace /tmp with a directory if needed
+ if grep -q "^[^ ]\+[ ]\+/tmp[ ]" $TMP/fstab; then
+ if [ -L $MNT/tmp ]; then rm -f $MNT/tmp && mkdir -m 1777 $MNT/tmp >/dev/null 2>&1; fi
+ fi
+ return 0
+}
+
+function do_lilo {
+ if [ -e $ROOTDIR/dev -a -e $ROOTDIR/.preinit -a -e $ROOTDIR/etc/lilo.conf ]; then
+ chroot $ROOTDIR /.preinit rebuild
+ chroot $ROOTDIR /sbin/lilo || lilo -r $ROOTDIR
+ umount $ROOTDIR/dev # remove what .preinit has installed
+ else
+ echo "LILO has NOT been run because it needs /dev, /.preinit, and /etc/lilo.conf"
+ fi
+ return 0
+}
+
+
+
+# main
+
+init
+
+if [ $0 = "mkdisk" ] ; then setup_part && exit 0 ; exit 1 ;
+elif [ $0 = "mkconfig" ] ; then setup_config $1 && exit 0 ; exit 1 ;
+elif [ $0 = "doconfig" ] ; then apply_config $1 && exit 0 ; exit 1 ;
+fi
+
+end=0
+while [ $# -ge 1 -a "$end" -ne 1 ] ; do
+ case $1 in
+ --disk) setup_part;;
+ --config) setup_config $2; shift;;
+ --apply) apply_config $2; shift;;
+ --) end=1;;
+ *) end=1;;
+ esac
+ if [ "$end" -eq 1 ] ; then break ; fi
+ shift
+done
+
+ROOTDIR=/mnt/disk
+PKGDIR=/home/pkg
+SHELLDIR=/
+
+action=1
+while [ "$action" != "q" -a "$action" != "Q" ] ; do
+
+ ROOTDEV=`mount | grep " on $ROOTDIR " | cut -f1 -d' '`
+
+ echo
+ echo "Possible actions are :"
+ echo "1: Run fdisk"
+ echo "2: Setup filesystems"
+ echo "3: Install packages"
+ echo "4: Build running config"
+ echo "5: Save built config for next reboot"
+ echo "6: Run lilo"
+ echo "7: Unmount all"
+ echo "s: Shell"
+ echo "q: Quit"
+
+ ask "Select an action (1..7/s/q)" "$action"
+
+ if [ "$REPLY" = "q" -o "$REPLY" = "Q" ] ; then break; fi
+ if [ "$REPLY" = "s" -o "$REPLY" = "S" ] ; then (cd $SHELLDIR; pwd; sh -i); REPLY=$action; continue; fi
+
+ action=`expr $REPLY + 1`
+ if [ "$action" = 8 ] ; then action=q ; fi
+ echo
+ case $REPLY in
+ 1)
+ # unmount previously mounted file-systems
+ for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do umount $part; done
+
+ for disk in $(list_disks); do
+ sfdisk -l /dev/$disk
+ yesno "Clear partition table for '/dev/$disk' (y/n)?" "n"
+ if [ "$REPLY" = "y" ] ; then
+ dd if=/dev/zero of=/dev/$disk bs=1024 count=1 > /dev/null 2>&1
+ (echo o ; echo w ) | fdisk /dev/$disk > /dev/null 2>&1
+ fi
+ yesno "Run 'fdisk' for '/dev/$disk' (y/n)" "y"
+ if [ "$REPLY" = "y" ] ; then
+ fdisk /dev/$disk
+ fi
+ done
+ SHELLDIR=/
+ ;;
+ 2)
+ setup_part
+ SHELLDIR=/
+ ;;
+ 3)
+ cd /
+ if [ "$ROOTDEV" != "" ] ; then
+ ask "Packages directory, or files pattern ($PKGDIR, $PKGDIR/*.lst, *.prf, *.tgz)"$'\n'" " $PKGDIR ; PKGDIR="$REPLY"
+ if [ -d "$PKGDIR" ]; then
+ list=`cd $PKGDIR && ls *.prf *.lst *.tgz 2>/dev/null`
+ else
+ list=`basename "$PKGDIR"`
+ PKGDIR=`dirname "$PKGDIR"`
+ list=$(cd $PKGDIR && echo $list)
+ fi
+ echo "Package list :"; (cd $PKGDIR && ls $list); echo
+ for pack in $list ; do
+ ask "Install package '$pack' (y/n/./<other dest>) ?" "y"
+ INSTDIR=/
+ if [ "`echo $REPLY | cut -c1`" = "/" ] ; then INSTDIR=$REPLY ; fi
+ if [ "$REPLY" = "." ]; then break; fi
+ if [ "$REPLY" != "n" -a "$REPLY" != "N" ] ; then
+ case "$pack" in
+ *lst) cat $PKGDIR/$pack | xargs cp --target-directory=$ROOTDIR$INSTDIR -p --parents -d -R -x ;;
+ *tgz) mkdir -p -m 0755 $ROOTDIR$INSTDIR && tar zpxf $PKGDIR/$pack -C $ROOTDIR$INSTDIR ;;
+ *prf) flxextract -R $ROOTDIR$INSTDIR -i $PKGDIR/$pack ;;
+ esac
+ fi
+ done
+ check_directories || exit 1
+ fi
+ SHELLDIR=/
+ ;;
+ 4)
+ check_directories || exit 1
+ if [ "$UPDATE_ONLY" != "n" -a "$UPDATE_ONLY" != "y" ]; then
+ echo "Existing files can be REPLACED or UPDATED."
+ yesno "Do you prefer to UPDATE existing files (y/n) ?" "y"
+ UPDATE_ONLY="$REPLY"
+ fi
+ setup_config $ROOTDIR
+ echo "done."
+ echo "New files have been written to /tmp/newconf/"
+ echo "You can check them now by starting a shell."
+ SHELLDIR=/tmp/newconf
+ (cd $SHELLDIR ; ls -lart)
+ ;;
+ 5)
+ echo "Saving config (.preinit, startup.rc, config.rc, fstab, lilo.conf, passwd)"
+ apply_config $ROOTDIR
+ echo "Saving config ... done."
+ echo "Updating dynamic files (/etc/formilux/sig.dat, /etc/ld.so.cache) ... "
+ ldconfig -r $ROOTDIR > /dev/null 2>&1
+
+ for SYSTEMMAP in `echo $ROOTDIR/boot/System.map-*`; do
+ KERNVER=${SYSTEMMAP#$ROOTDIR/boot/System.map-}
+ chroot $ROOTDIR depmod -a -F /boot/System.map-$KERNVER $KERNVER
+ done
+
+ echo "Signing the filesystem... (this may take a while)"
+ cd $ROOTDIR ; signfs -x `mount|grep -v ' type \(tmpfs\|ramfs\)'|grep "^/.* $ROOTDIR "| \
+ sed "s@^.*$ROOTDIR\([^ ]*\) .*@.\1@"` > /etc/formilux/sig.dat
+ echo "Updating dynamic files ... done."
+ SHELLDIR=/
+ ;;
+ 6)
+ do_lilo
+ SHELLDIR=/
+ ;;
+ 7)
+ cd /
+ for mp in `grep "$ROOTDIR" /proc/mounts | cut -f2 -d' ' | sort -r` ; do
+ umount -n $mp
+ done
+ SHELLDIR=/
+ ;;
+ *)
+ ;;
+ esac
+done
+
diff --git a/scripts/mkinstall2 b/scripts/mkinstall2
deleted file mode 100755
index 62aa458..0000000
--- a/scripts/mkinstall2
+++ /dev/null
@@ -1,1218 +0,0 @@
-#!/bin/bash
-#
-# /sbin/mkinstall - System Installer - version 1.9.0 - 2003-06-16
-# This file is part of the Formilux project : http://formilux.ant-computing.com/
-#
-# Copyright (C) 2001-2003 Benoit Dolez & Willy Tarreau
-# mailto: benoit@ant-computing.com,willy@ant-computing.com
-#
-# This program is licenced under GPLv2 ( http://www.gnu.org/licenses/gpl.txt )
-
-cdlist=( )
-names=( )
-sizes=( )
-parts=( )
-
-# this utility uses a few temporary files :
-#
-# /tmp/fsmnt : <device><space><mount_point>
-# device=/dev/hda, /dev/sda1...
-# space=exactly one space
-# mount_mount=/home, /var, /, ..., mbr, cdrom, swap, <empty string when not affected>
-# /tmp/fsid : <device><space><hex_id><space><os_name>
-# /tmp/fstype : <device><space><fstype>
-# /tmp/fslist : <device>
-# /tmp/fssize : <device><space><size_in_kB>
-# /tmp/sourcepkg : symlink to the source packages directory
-
-# give it a number suffixed with a k,M,G,T, and it will return it reduced to
-# the nearest power of 1024 suffixed with k,M,G or T
-humansize() {
- local pow val
- local -a suff=( "" k M G T P )
- case "${1##[0-9]*}" in
- k) pow=1;;
- M) pow=2;;
- G) pow=3;;
- T) pow=4;;
- P) pow=5;;
- *) pow=0;;
- esac
- val=${1%%[a-zA-Z]*}
- # we don't return values lower than 10 when possible
- while [ $val -ge 10240 ]; do
- ((pow++))
- ((val/=1024))
- done
- REPLY=$val${suff[$pow]}
- echo -n $REPLY
-}
-
-detect_cdrom() {
- cdlist=($(grep -i '^drive name:' /proc/sys/dev/cdrom/info |cut -f2 -d:))
- CDROMS="${cdlist[*]}"
-}
-
-detect_disks() {
- local i j major minor size name rest
-
- names=( )
- sizes=( )
- parts=( )
-
- rm -f /tmp/partitions
- tail +3 /proc/partitions | sort -k4.1 >/tmp/partitions
- while read major minor size name rest; do
- if ((i >= 0)); then
- names[i]=$name
- sizes[i]=$size
- parts[i]=1
- fi
- ((i++))
- done < /tmp/partitions
-
- i=0
- while ((i < ${#names[@]})); do
- if [ -n "${names[i]}" ]; then
- j=0
- while ((j < ${#names[@]})); do
- if [ $i -ne $j -a -n "${names[j]}" -a -z "${names[j]##${names[i]}*}" ]; then
- names[j]=""
- ((parts[i]+=${parts[j]}))
- fi
- ((j++))
- done
- fi
- ((i++))
- done
-
- i=0 j=0
- while ((i < ${#names[@]})); do
- if [ -n "${names[i]}" -a "${cdlist[*]##${names[i]}}" = "${cdlist[*]}" ]; then
- names[j]=${names[i]}
- sizes[j]=${sizes[i]}
- ((parts[j]=${parts[i]}-1))
- ((j++))
- fi
-
- if ((i >= j)); then
- unset names[i] parts[i] sizes[i]
- names=("${names[@]}") parts=("${parts[@]}") sizes=("${sizes[@]}")
- else
- ((i++))
- fi
- done
- # now we have the list of the hard disks :
- # names[] contains their name in /dev
- # sizes[] contains their size in blocks (1 kB)
- # parts[] contains their number of partitions
-}
-
-# This function collects some information in /proc and other places.
-# It should be called ASAP.
-
-function init {
- #umount /mnt/cdrom >/dev/null 2>&1 # to avoid stupid recursive copying !
- detect_cdrom
- detect_disks
- mkdir -p $ROOTDIR >/dev/null 2>&1
-}
-
-# displays the main menu
-# if an arg is passed, it will be used as the name entry of the default action.
-# it returns the name of the entry in REPLY
-# returns 0 if OK, 1 if Cancel/Exit.
-function menu_main {
- REPLY=$(dialog --title " Formilux Installation Utility " --no-cancel --no-shadow ${1:+--default-item $1 }\
- --menu "Installation Menu\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 14 \
- "PART" "Configure Partitions and File Systems" \
- "SOURCE" "Select Packages Source" \
- "PKG" "Select which Packages to Install" \
- "CONFIG" "Build Configuration" \
- "SAVE" "Save Current Configuration" \
- "LILO" "Run LILO" \
- "UNMOUNT" "Unmount all File Systems" \
- "SHELL" "Get Access to a Shell" \
- "EXIT" "Exit this Utility" 2>&1 | grep -v EXIT)
- [ -n "$REPLY" ]
-}
-
-
-# presents a list of hard disks and lets the user choose one.
-# the default one can be passed in $1
-# returns 0 if OK, 1 if Cancel/Exit.
-function menu_harddisk {
- local -a args=( )
- local i=0
- local model
- while ((i < ${#names[@]})); do
- model='unknown model'
- [ -e "/proc/ide/${names[i]}/model" ] && model=$(</proc/ide/${names[i]}/model)
- args=("${args[@]}" "${names[i]}" "$model, $(humansize ${sizes[i]}k)B, ${parts[i]} part.")
- ((i++))
- done
-
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow ${1:+--default-item $1 } --menu "\nSelect a Hard Disk to Configure\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 12 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
- [ -n "$REPLY" ]
-}
-
-# presents a list of hard disks partitions and lets the user choose one.
-# the disk is passed in $1
-# the default one can be passed in $2
-# returns 0 if OK, 1 if Cancel/Exit.
-function menu_partition {
- local -a args=( )
- local dev=$1
- local disk=${1##/dev/}
- local def=$2
- local mnt
- local device size id syst rest
-
- for device in $(grep "^$dev" /tmp/fslist 2>/dev/null); do
- size=$(grep "^$device " /tmp/fssize 2>/dev/null |cut -f2 -d' ')
- mnt=$(grep "^$device " /tmp/fsmnt 2>/dev/null |cut -f2 -d' ')
- id=$(grep "^$device " /tmp/fsid 2>/dev/null |cut -f2 -d' ')
- syst=$(grep "^$device " /tmp/fsid 2>/dev/null |cut -f3 -d' ')
- type=$(grep "^$device " /tmp/fstype 2>/dev/null |cut -f2 -d' ')
- if [ -z "$mnt" ]; then
- def=${def:-${device##/dev/}}
- mnt="not assigned"
- else
- mnt="assigned to $mnt"
- fi
- if [ -z "$type" ]; then
- def=${def:-${device##/dev/}}
- type="not formated"
- else
- type="type $type"
- fi
- args=("${args[@]}" "${device##/dev/}" "$(humansize ${size}k)B, Id 0x$id($syst), $type, $mnt")
- done
-
- def=${def:-EXIT}
- args=("${args[@]}" "CLEAR" "Clear ALL partitions on this disk" "FDISK" "Run fdisk on this disk")
-
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow ${def:+--default-item $def} --menu "\nSelect a Partition\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 12 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
- [ -n "$REPLY" ]
-}
-
-# reads the partition table on a disk and updates the associated files :
-# /tmp/fslist, /tmp/fssize, /tmp/fsid, /tmp/fsmnt, /tmp/fstype
-# the disk device is passed in $1 (/dev/xxx). There's no return code.
-function disk_read_part {
- local dev=$1
- local disk=${1##/dev/}
- local device begin end cyl size id syst rest file
-
- rm -f /tmp/sfdisk.$disk
- for file in fslist fssize fsid; do
- grep -v "^$dev" /tmp/$file 2>/dev/null >/tmp/${file}-; mv /tmp/${file}- /tmp/$file
- done
-
- for file in fsmnt fstype; do
- grep "^$dev" /tmp/$file 2>/dev/null >/tmp/$file.$disk
- grep -v "^$dev" /tmp/$file 2>/dev/null >/tmp/${file}-; mv /tmp/${file}- /tmp/$file
- done
-
- sfdisk -l $dev | tr '*' ' ' | grep '^/dev/' >/tmp/sfdisk.$disk
- while read device begin end cyl size id syst rest; do
- # let's ignore empty and extended partitions
- [ "$id" = "0" -o "$id" = "5" ] && continue
- size=${size%+}
- echo "$device" >> /tmp/fslist
- echo "$device $size" >> /tmp/fssize
- echo "$device $id $syst" >> /tmp/fsid
- if [ "$id" != "82" ] || grep -q "^$device " /tmp/fsmnt.$disk && ! grep -q "^$device swap" /tmp/fsmnt.$disk; then
- grep "^$device " /tmp/fsmnt.$disk >> /tmp/fsmnt
- grep "^$device " /tmp/fstype.$disk >> /tmp/fstype
- else
- echo "$device swap" >> /tmp/fsmnt
- # we want to keep a trace of the format status of the swap partition
- # instead of assuming it has already been formated
- grep "^$device " /tmp/fstype.$disk >> /tmp/fstype
- #echo "$device swap" >> /tmp/fstype
- fi
- done < /tmp/sfdisk.$disk
- rm -f /tmp/sfdisk.$disk
-}
-
-# presents a list of possible actions for a partition :
-# - change its mount point
-# - format it
-# the partition is passed in $1
-# if a default choice should be proposed, its name must be in $2
-# returns 0 if OK, 1 if Cancel/Exit.
-function menu_setupfs {
- local -a args=( )
- local dev=$1
- local def size type strext2s strext2l strext3 strreiser
- local mnt
-
- def=$2
- mnt=$(grep "^$dev " /tmp/fsmnt 2>/dev/null |cut -f2 -d' ')
- [ -z "$mnt" ] && { mnt="not assigned" ; def=${def:-"MNT"}; }
-
- type=$(grep "^$dev " /tmp/fstype 2>/dev/null |cut -f2 -d' ')
- [ -z "$type" ] && type="not formated"
-
- size=$[ ($(grep "^$dev " /tmp/fssize 2>/dev/null | cut -f2 -d' ')+0) / 1024 ]
-
- args=("MNT" "Change the mount point ($mnt)")
-
- if [ "$mnt" = "swap" ]; then
- args=("${args[@]}" "SWAP" "* mkswap $dev (format as swap)")
- args=("${args[@]}" "SWAPC" " mkswap -c $dev (format and check)")
- def=${def:-SWAP}
- else
- strext2s="mke2fs -b 1024 -m 1 -s 1 $dev (format as small Ext2)"
- strext2l="mke2fs -b 4096 -s 1 $dev (format as large Ext2)"
- strext3="mke2fs -b 4096 -s 1 -j $dev (format as Ext3)"
- strreiser="mkreiserfs -h r5 $dev (format as ReiserFS)"
- if [ $size -lt 64 ]; then
- strext2s="* $strext2s"
- strext2l=" $strext2l"
- strext3=" $strext3"
- strreiser=" $strreiser"
- def=${def:-EXT2S}
- else
- strext2s=" $strext2s"
- strext2l=" $strext2l"
- strext3="* $strext3"
- strreiser=" $strreiser"
- def=${def:-EXT3}
- fi
-
- args=("${args[@]}" "EXT2S" "$strext2s" "EXT2L" "$strext2l" "EXT3" "$strext3" "REISER" "$strreiser" )
- fi
- args=("${args[@]}" "SHELL" "Get Access to a Shell")
-
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow ${def:+--default-item $def} --menu "\nFormat and Mount Point\n\nChoose a mount point for this partition, then select a format command to format it and set its type. The '*' indicates the recommended format.\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 8 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
- [ -n "$REPLY" ]
-}
-
-
-# lets the user change a mount point for a partition.
-# the partition is passed in $1
-# returns 0 if something changed, else 1.
-function menu_mount_point {
- local mnt dev type id name
- dev=$1
- mnt=$(grep "^$dev " /tmp/fsmnt 2>/dev/null |cut -f2 -d' ')
- id=$(grep "^$dev " /tmp/fsid 2>/dev/null |cut -f2 -d' ')
- name=$(grep "^$dev " /tmp/fsid 2>/dev/null |cut -f3 -d' ')
- type=$(grep "^$dev " /tmp/fstype 2>/dev/null |cut -f2 -d' ')
-
- REPLY=$mnt
- [ -z "$REPLY" -a "$id" = "82" ] && REPLY="swap"
- [ -z "$REPLY" ] && ! grep -q " /boot$" /tmp/fsmnt && REPLY="/boot"
- [ -z "$REPLY" ] && ! grep -q " /$" /tmp/fsmnt && REPLY="/"
- [ -z "$REPLY" ] && ! grep -q " /var$" /tmp/fsmnt && REPLY="/var"
- [ -z "$REPLY" ] && ! grep -q " /home$" /tmp/fsmnt && REPLY="/home"
-
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --inputbox "Enter the mount point for partition $dev\n${id:+Partition Id=$id($name)}${type:+${id:+, }Formated as $type}\nEnter 'swap' to force it to become swap\n\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 12 60 $REPLY 2>&1 || echo $mnt)
- if [ "$REPLY" != "$mnt" ]; then
- (grep -v "^$dev " /tmp/fsmnt 2>/dev/null; echo "$dev $REPLY") >/tmp/fsmnt-
- mv /tmp/fsmnt- /tmp/fsmnt
- return 0
- else
- return 1
- fi
-}
-
-
-# lets the user change the package directory
-# the entry is checked to be a valid directory
-# returns 0 if something changed, else 1.
-function menu_pkg_dir {
- local old
-
- old=$(readlink /var/flx-pkg 2>/dev/null)
- REPLY=$old
- while : ; do
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --inputbox "Enter the new packages directory\nCurrently set to '$old'\n\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 12 60 $REPLY 2>&1 || echo $old)
- if [ "$REPLY" != "$old" ]; then
- if [ -d "$REPLY/." ]; then
- PKGDIR=$REPLY
- rm -f /var/flx-pkg
- ln -sf $REPLY /var/flx-pkg
- return 0
- else
- dialog --title " Formilux Installation Utility " --msgbox "'$REPLY' is not a valid directory. Please try again, or press [Cancel].\n" 8 60
- fi
- else
- # cancel or no changes
- return 1
- fi
- done
-}
-
-# ask the user about the desired source of packages for the installation
-function menu_select_source {
- local -a args=( )
- args=("CDROM" "CD-ROM" "DISK" "Hard disk or USB storage device" "NFS" "Remove file-system over NFS" "DIR" "Pre-mounted directory")
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --menu "\nSource Packages Selection\n\nChoose from which medium the source packages will be fetched.\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 8 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
- [ -n "$REPLY" ]
-}
-
-
-# ask the user about the desired source cdrom
-# returns 0 if the CD could be mounted, 1 otherwise.
-function menu_select_cdrom {
- local -a args=( )
- local cdrom
-
- umount -l /mnt/cdrom >/dev/null 2>&1
- rm -f /dev/cdrom
- rm -f /var/flx-pkg
- PKGDIR=
- case ${#cdlist[@]} in
- 0)
- dialog --title " Formilux Installation Utility " --msgbox "No CD-ROM device was detected on this system. Please load manually any appropriate module or choose another source medium." 12 60 ;
- rm -f /var/flx-pkg
- return 1
- ;;
- 1)
- ln -sf ${cdlist[0]} /dev/cdrom
- if mount /mnt/cdrom >/dev/null 2>&1 ; then
- PKGDIR=/mnt/cdrom/pkg
- ln -s $PKGDIR /var/flx-pkg
- dialog --title " Formilux Installation Utility " --msgbox "/dev/${cdlist[0]} has been selected as the only CD-ROM device, and mounted successfully.\n" 8 60
- return 0
- else
- dialog --title " Formilux Installation Utility " --msgbox "/dev/${cdlist[0]} has been selected as the only CD-ROM device, but could not be mounted. Please insert a valid CD-ROM and try again.\n" 8 60
- return 1
- fi
- ;;
- esac
-
- args=("AUTO" "Automatically find which drive contains a CD")
- for cdrom in "${cdlist[@]}"; do
- if [ -e "/proc/ide/$cdrom/model" ]; then
- args=("${args[@]}" "$cdrom" "$(cat /proc/ide/$cdrom/model)")
- elif [ -z "${cdrom##sr*}" -o -z "${cdrom##scd*}" ]; then
- args=("${args[@]}" "$cdrom" "SCSI CD-ROM")
- else
- args=("${args[@]}" "$cdrom" "Unknown CD-ROM model")
- fi
- done
-
- cdrom="${args[0]}"
- while [ -z "$PKGDIR" ]; do
- rm -f /dev/cdrom
- REPLY=$(dialog --title " Formilux Installation Utility " --no-shadow --default-item "$cdrom" --menu "\nCD-ROM\n\nSelect the CD-ROM drive which contains the Formilux CD-ROM you want to use for the installation.\n\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to confirm your choice." 24 80 8 "${args[@]}" "EXIT" "Exit this menu" 2>&1 |grep -v EXIT)
- cdrom=$REPLY
- case "$REPLY" in
- "")
- return 1
- ;;
- AUTO)
- findcdrom
- if [ ! -e /dev/cdrom ]; then
- dialog --title " Formilux Installation Utility " --msgbox "No drive containing a valid CD-ROM was found. Please insert a valid CD-ROM and try again.\n" 8 60
- continue
- fi
- ;;
- *)
- ln -sf $REPLY /dev/cdrom
- ;;
- esac
- if mount /mnt/cdrom >/dev/null 2>&1; then
- PKGDIR=/mnt/cdrom/pkg
- dialog --title " Formilux Installation Utility " --msgbox "/dev/$(readlink /dev/cdrom) has been selected as the new CD-ROM device, and mounted successfully.\n" 8 60
- return 0
- else
- dialog --title " Formilux Installation Utility " --msgbox "/dev/$(readlink /dev/cdrom) has been selected as the new CD-ROM device, but could not be mounted. Please insert a valid CD-ROM and try again.\n" 8 60
- fi
- done
- return 1
-}
-
-
-# ask the user a question to which he can reply by "yes" or "no".
-# A simple message is passed in $1
-# if $2 is NOT EMPTY, the default response will be NO.
-# returns 0 if No, 1 if Yes
-function menu_yesno {
- dialog --title " Formilux Installation Utility " --no-shadow ${2:+--defaultno} --yesno "$1" 12 65
-}
-
-# user interface functions
-function ask {
- echo -n "$1 [$2] : "; read
- if [ "$REPLY" = "" ]; then REPLY=$2; fi
-}
-
-function yesno {
- echo -n "$1 [$2] : "; read ; REPLY=`echo $REPLY | cut -c1`
- if [ "$REPLY" = "" ]; then REPLY=$2; fi
- if [ "$REPLY" = o -o "$REPLY" = y -o "$REPLY" = Y ]; then
- REPLY="y"
- fi
-}
-
-#
-function check_directories {
- if [ ! -d $ROOTDIR/etc/. ] ; then
- if [ -d $ROOTDIR/boot/etc/. ] ; then
- ln -s boot/etc $ROOTDIR/etc
- else
- echo "Can't find 'etc' directory neither in '/' nor in '/boot'"
- return 1
- fi
- fi
- [ -d $ROOTDIR/var/. ] || mkdir $ROOTDIR/var
- [ -d $ROOTDIR/var/run ] || mkdir $ROOTDIR/var/run
- [ -d $ROOTDIR/var/spool ] || mkdir $ROOTDIR/var/spool
- [ -d $ROOTDIR/var/cache ] || mkdir $ROOTDIR/var/cache
- if [ ! -d $ROOTDIR/var/log ] ; then
- mkdir $ROOTDIR/var/log
- chown root:log $ROOTDIR/var/log
- chmod 2750 $ROOTDIR/var/log
- fi
- [ -d $ROOTDIR/var/adm/. ] || ln -s log $ROOTDIR/var/adm
-
- if [ ! -d $ROOTDIR/var/tmp ] ; then mkdir $ROOTDIR/var/tmp ; chmod 1777 $ROOTDIR/var/tmp ; fi
- # /tmp should exist, either as a dir or a link.
- if [ ! -e $ROOTDIR/tmp ] ; then mkdir $ROOTDIR/tmp ; chmod 1777 $ROOTDIR/tmp ; fi
-
- return 0
-}
-
-# this function lists all hard drives found, but hides CDROMs
-function list_disks {
- echo "${names[@]}"
- #for i in `tail +3 /proc/partitions | awk '{print $4}' | grep '\([a-zA-Z]$\)\|\(c[0-9]*d[0-9]*$\)'`; do
- # if ! echo $CDROMS | grep -qw $i; then
- # echo $i
- # fi
- #done
-}
-
-# mounts all the new file-systems, and creates the mount points when needed
-function mount_new_fs {
- local -a mplist=($(sort -k2.1 /tmp/fsmnt 2>/dev/null|cut -f2 -d' ') )
- local fs mp type
-
- rm -f /tmp/fstab
-
- echo "/proc /proc proc defaults 0 0" >> /tmp/fstab
- echo "#/dev /dev tmpfs size=0,nr_inodes=4096,remount,nosuid 0 0" >> /tmp/fstab
- echo "/dev/pts /dev/pts devpts defaults 0 0" >> /tmp/fstab
- echo "/dev/cdrom /mnt/cdrom iso9660 defaults,noauto,ro,users,exec 0 0" >> /tmp/fstab
-
- for mp in "${mplist[@]}"; do
- fs=$(grep " $mp\$" /tmp/fsmnt 2>/dev/null|cut -f1 -d' ')
- type=$(grep "^$fs " /tmp/fstype 2>/dev/null|cut -f2 -d' ')
- if [ "$mp" != "swap" ]; then
- mkdir -p -m 0755 $ROOTDIR$mp 2>/dev/null
- mount -t $type $fs $ROOTDIR$mp
- fi
- if [ "$mp" = "/" ]; then
- echo "#$fs $mp $type defaults,ro 1 1" >> /tmp/fstab
- echo "/dev/root $mp $type defaults,ro 1 1" >> /tmp/fstab
- mkdir -p -m 0755 $ROOTDIR/dev $ROOTDIR/proc $ROOTDIR/etc
- mount -t proc proc $ROOTDIR/proc # may be needed for compressed files
- elif [ "$mp" = "/boot" ]; then
- echo "$fs $mp $type defaults,ro 1 2" >> /tmp/fstab
- elif [ "$mp" = "swap" ]; then
- echo "$fs $mp $type defaults 0 0" >> /tmp/fstab
- else
- echo "$fs $mp $type defaults 1 2" >> /tmp/fstab
- fi
- done
- echo "/var/empty /var/empty tmpfs size=0,nr_inodes=1,ro,mode=0100,nosuid,nodev 0 0" >> /tmp/fstab
-}
-
-# unmounts all the new file-systems
-function unmount_new_fs {
- local -a mplist=($(sort -rk 2.1 /proc/mounts 2>/dev/null | cut -f2 -d' ' | grep "^$ROOTDIR") )
- local fs mp type
-
- for mp in "${mplist[@]}"; do
- if [ "$mp" != "swap" ]; then
- umount $mp >/dev/null 2>&1
- fi
- done
-}
-
-
-function setup_part {
-
- if [ -e /tmp/devmap -a -e /tmp/fstab ]; then
- echo "Filesystems are currently configured this way :"
- for i in `cut -f1 -d' ' /tmp/devmap`; do grep "^$i[ ]" /tmp/fstab | awk '{print $1 " => " $2 }'; done
- echo "-- end of list --"
- yesno "Do you want to change something (y/n) ?" "n"
- [ "$REPLY" = "y" ] || return 0
- cp /tmp/fstab /tmp/fstab-
- cp /tmp/devmap /tmp/devmap-
- else
- touch /tmp/fstab- /tmp/devmap-
- fi
-
- # clean temporary files
- rm -rf /tmp/temp.$$ /tmp/fstab /tmp/devmap
-
- # unmount previously mounted file-systems
- for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do
- umount $part;
- done
-
- echo "/proc /proc proc defaults 0 0" >> /tmp/fstab
- echo "#/dev /dev tmpfs size=0,nr_inodes=4096,remount 0 0" >> /tmp/fstab
- echo "/dev/pts /dev/pts devpts defaults 0 0" >> /tmp/fstab
- echo "/dev/cdrom /mnt/cdrom iso9660 defaults,noauto,ro,users 0 0" >> /tmp/fstab
-
- echo "/dev/$(readlink /dev/cdrom) /dev/cdrom" >> /tmp/devmap
- (grep -v ' CDROM$' /tmp/mounts 2>/dev/null; echo "/dev/$(readlink /dev/cdrom) CDROM") >/tmp/mounts- && mv /tmp/mounts- /tmp/mounts
-
- # scan all disk
- # for disk in $(list_disks); do
- REPLY=${names[0]}
- while menu_harddisk $REPLY; do
- disk=${REPLY##/dev/}
-
- # look for all detected partitions
-# for spart in `sfdisk -l /dev/$disk 2>/dev/null | grep "^/" |tr '*' ' '| cut -f3- -d'/' | awk '{print $1 ":" $6 }'` ; do
-
-
- REPLY=
- while { disk_read_part /dev/$disk ; menu_partition /dev/$disk $REPLY; } do
- [ -z "$REPLY" ] && break
- if [ "$REPLY" = "CLEAR" ] ; then
- if menu_yesno "Warning !\n\nThis will erase the partition table for /dev/$disk.\nAll data will be lost.\n\nDo you still want to proceed ?" N; then
- dd if=/dev/zero of=/dev/$disk bs=1024 count=1 > /dev/null 2>&1
- (echo o ; echo w ) | fdisk /dev/$disk > /dev/null 2>&1
- fi
- REPLY=FDISK
- continue
- elif [ "$REPLY" = "FDISK" ]; then
- fdisk /dev/$disk
- REPLY=
- continue
- else
- echo "menu format/mount pour $REPLY"
- fi
-
-
-
-
-
- # partition name
- part=`echo $spart|cut -f1 -d:`
- set -- `echo $spart | tr ':' ' '`
- set -- $* `fdisk -s /dev/$1` `sfdisk -l /dev/$disk 2>/dev/null | grep "/dev/$1 " | cut -c15-`
-
- # hide mounted partitions
- part=/dev/$part
- if grep -q "$part " /proc/mounts > /dev/null ; then continue ; fi
-
- # hide empty or extended partitions
- if [ $2 = 0 -o $2 = 5 ] ; then continue ; fi
-
- # partition size in Mega Bytes
- size=$[ $3 / 1024]
- # partition type in human readable form
- type=$2
- shift 8
- htype=$*
-
- # redo while not a good value
- askagain=y
- unset mountpoint
- while [ "$askagain" = "y" ] ; do
- askagain=n
- echo
- echo "Partition : $part ($htype, ${size} MB)"
-
- # non linux partition
- if [ $type != 82 -a $type != 83 -a $type != 8e -a $type != fd ] ; then
- yesno "$part isn't a standard linux partition, would you like an entry in /etc/fstab (y/n)?" "n"
- if [ "$REPLY" = "n" ] ; then continue ; fi
- fstype=noauto
- else
- fstype=auto
- fi
-
- # getting mount point
- if [ $type = 82 ] ; then
- mountpoint=swap
- else
- mountpoint=$(grep "^$part[ ]" /tmp/fstab- | awk '{print $2 }')
- fi
- ask " Choose a mount point (swap,/,/boot,/var,...) or [Enter] for none" "$mountpoint"
- # remove useless leading and trailing slashes
- mountpoint=$(echo $REPLY|sed 's@^\([/]*\)\(/.*\)$@\2@'|sed 's@^\(.*[^/]\)\([/]*\)$@\1@')
- if [ -z "$mountpoint" ] ; then break ; fi
-
- case "$mountpoint" in
- /) echo "$part /dev/root" >> /tmp/devmap ;;
- /boot) echo "$part /dev/boot" >> /tmp/devmap ;;
- swap) echo "$part /dev/swap" >> /tmp/devmap ;
- echo "$part swap swap defaults 0 0" >> /tmp/fstab;;
- *) echo "$part /dev/fs/$(echo ${mountpoint#/} |tr '/' '.')" >> /tmp/devmap ;;
- esac
-
-
- case "$mountpoint" in
- swap)
- (grep -v "^$part " /tmp/mounts 2>/dev/null; echo "$part SWAP") >/tmp/mounts- && mv /tmp/mounts- /tmp/mounts;;
- *)
- (grep -v "^$part " /tmp/mounts 2>/dev/null; echo "$part $mountpoint") >/tmp/mounts- && mv /tmp/mounts- /tmp/mounts;;
- esac
-
-
- formatcmd=''
- # format linux partitions
- if [ $type = 82 -o $type = 83 -o $type = 8e -o $type = fd ] ; then
- # tell how to format
- echo " 0: -- DO NOT format this partition (default) --" ; ch=0
- if [ "$mountpoint" = "swap" ] ; then
- ch1="mkswap $part" ; echo " >1: $ch1"
- ch2="mkswap -c $part" ; echo " 2: $ch2 (with check)"
- elif [ "`echo $mountpoint|cut -c1`" = "/" ] ; then
- ch1="mke2fs -b 1024 -m 1 -s 1 $part"
- if [ "$size" -lt 64 ]; then
- echo " >1: $ch1 (small ext2)"
- else
- echo " 1: $ch1 (small ext2)"
- fi
- ch2="mke2fs -b 4096 -s 1 $part" ; echo " 2: $ch2 (large ext2)"
- ch3="mke2fs -b 4096 -s 1 -j $part"
- if [ "$size" -ge 64 ]; then
- echo " >3: $ch3 (ext3)"
- else
- echo " 3: $ch3 (ext3)"
- fi
- ch4="mkreiserfs -h r5 $part" ; echo " 4: $ch4 (reiserfs)"
- fi
- ask " Select a format method or enter the complete command" "$ch"
- case $REPLY in
- 0) formatcmd='' ;;
- [1-9]) formatcmd=`eval echo '\$ch'$REPLY` ;;
- *) formatcmd=$REPLY ;;
- esac
- fi
- done
-
- # execute format
- if [ "$formatcmd" ] ; then
- echo -n "Doing: '$formatcmd': "
- eval "echo y | $formatcmd" > /tmp/error.$$ 2>&1
- if [ "$?" = "0" ] ; then
- echo "done."
- else
- echo "failed."
- echo "--------------------------------------------------------"
- echo "$formatcmd said:"
- sed -e "s/^/>> /" /tmp/error.$$
- echo "----------- Filesystem will not be mounted -------------"
- mountpoint=""
- fi
- fi
- if [ "`echo $mountpoint|cut -c1`" = "/" ] ; then
- echo "$mountpoint -t $fstype $part" >> /tmp/temp.$$
- fi
- done
- done
-
- # now we will mount all the filesystems we have just created, and add them to fstab
- sort /tmp/temp.$$ | while read ; do
- set -- $REPLY
- mp=$1 ; shift
- if [ ! -d $ROOTDIR$mp ] ; then mkdir -p $ROOTDIR$mp ; echo "Creating directory $mp" ; fi
- if [ $2 != noauto ] ; then
- echo -n "Mounting $mp ($3): "
- mount -n $* $ROOTDIR$mp > /dev/null 2>&1
- if [ "$?" = "0" ] ; then echo "done." ; else
- echo "failed."
- echo "##failed## $3 $mp $2 defaults 1 1" >> /tmp/fstab
- fi
- else
- echo "#$3 $1 auto defaults 0 0" >> /tmp/fstab
- fi
- done
- mount | grep '^[ ]*/' | grep "$ROOTDIR[/ ]" | sed "s@$ROOTDIR[/]*@/@" | \
- awk '{ printf "%s\t%s\t%s\tdefaults%s\t1 %s\n",$1,$3,$5,($3=="/" || $3=="/boot")?",ro":"",($3=="/")?"1":"2" }' >> /tmp/fstab
- #grep '^/' /proc/swaps | awk '{ print $1 "\tswap \tswap \tdefault 0 0"}' >> /tmp/fstab
-
- mkdir -p -m 0755 $ROOTDIR/dev $ROOTDIR/proc $ROOTDIR/etc $ROOTDIR/mnt/cdrom
- mount -t proc proc $ROOTDIR/proc # may be needed for compressed files
-
-### sed -e "s,^#L.*cdrom\$,ln ` readlink /dev/cdrom` /dev/cdrom," < /.preinit > $ROOTDIR/.preinit
-
- rm -f /tmp/temp.$$
- return 0
-}
-
-function setup_keyboard {
- sed -n '/^service keyboard/,/^ *$/p' < /etc/config.rc
-}
-
-function setup_mouse {
- sed -n '/^service mouse/,/^ *$/p' < /etc/config.rc
-}
-
-function setup_network {
- echo "# hostname formilux"
- echo "# interface eth0"
- echo "# ip address 10.101.20.4/16"
- echo "# ip dhcp"
- echo "# service network"
-}
-
-# (re)build config.rc, startup.rc, fstab, devmap, lilo.conf
-function setup_config {
- local MNT="$1"
- local MPWD=$PWD
- local TMP=/tmp/newconf
-
- if [ ! -w /tmp ] ; then
- echo "Directory /tmp not writable"; exit 1
- fi
-
- mkdir -p $TMP >/dev/null 2>&1
-
- if [ "$MNT" = "" ] ; then MNT="$ROOTDIR"; fi
-
-# copy startup.rc and config.rc
- rm -f $TMP/config.rc $TMP/startup.rc
- if [ "$UPDATE_ONLY" != "y" -o ! -e $MNT/etc/config.rc ]; then
- echo >> $TMP/config.rc
- echo "# service syslogd" >> $TMP/config.rc
- echo >> $TMP/config.rc
- setup_network >> $TMP/config.rc
- echo >> $TMP/config.rc
- setup_keyboard >> $TMP/config.rc
- setup_mouse >> $TMP/config.rc
- chmod 644 $TMP/config.rc
- fi
-
- if [ "$UPDATE_ONLY" != "y" -o ! -e $MNT/etc/startup.rc ]; then
- echo "#!/bin/sh" >> $TMP/startup.rc
- echo "echo -n \"Default configuration ... \" " >> $TMP/startup.rc
- echo "/sbin/init.d/sysprofiles /etc/config.rc" >> $TMP/startup.rc
- chmod 755 $TMP/startup.rc
- fi
-
-# copy fstab
- cp /tmp/fstab $TMP/fstab
-
-# copy devmap
- BOOTDEV=${BOOTDEV:-`echo $ROOTDEV | sed 's/[0-9]\+$//'`}
- ask "Choose device on which LILO will be installed " $BOOTDEV
- BOOTDEV=$REPLY
- grep -v '/dev/\(mbr\|cdrom\)$' /tmp/devmap > $TMP/devmap 2>/dev/null
- echo "$BOOTDEV /dev/mbr" >> $TMP/devmap
- echo "/dev/$(readlink /dev/cdrom) /dev/cdrom" >> $TMP/devmap
-
-
-# build a new lilo.conf
- cd $MNT
-
- KERNVER=`ls boot/*/bzImage | tail -1 | cut -f2 -d/`
- KERNLBL=`echo $KERNVER | tr -d '.-'`
- cat > $TMP/lilo.conf <<EOF
-serial = 0,9600n8
-boot = $BOOTDEV
-default = l$KERNLBL
-EOF
-
- for bootimg in `ls boot/*/bzImage` ; do
- echo "image = /$bootimg" >> $TMP/lilo.conf
- echo " label = l`echo $bootimg | cut -f2 -d/ | tr -d '.-'`" >> $TMP/lilo.conf
- echo " append = \"root=$ROOTDEV\"" >> $TMP/lilo.conf
- echo " read-only" >> $TMP/lilo.conf
- done
-
- if [ `grep "label =" $TMP/lilo.conf | wc -l` = 0 ]; then
- echo
- echo "WARNING!!! no kernel was found in $MNT/boot !!!"
- echo "You must install a kernel and edit $TMP/lilo.conf or your system will never boot."
- echo
- sleep 1
- fi
-
-# copy /.preinit
- if [ -e $MNT/.preinit -a "$UPDATE_ONLY" = "y" ]; then
- cp $MNT/.preinit $TMP/.preinit
- else
- cp /.preinit $TMP/.preinit
- fi
-
- # 1st complicated part : merge old and new fstab.
- # Method:
- # - mount points only in old fstab are kept as-is
- # - mount points in both with same types only have their dev updated
- # - mount points in both with diff types are fully updated
- # - mount points only in new fstab are merged
- if [ "$UPDATE_ONLY" = "y" -a -e $MNT/etc/fstab ]; then
- rm -f $TMP/fstab
- while read; do
- set -- $REPLY
- if ! grep -q "^[^ ]\+[ ]\+${2}[ ]" /tmp/fstab; then
- # not found
- echo "$REPLY" >> $TMP/fstab
- elif ! grep -q "^[^ ]\+[ ]\+${2}[ ]\+${3}[ ]" /tmp/fstab; then
- # not found with the same type
- echo "##old##$REPLY" >> $TMP/fstab
- grep "^[^ ]\+[ ]\+${2}[ ]" /tmp/fstab >> $TMP/fstab
- else
- # found with the same type. We may have to update the device
- dev=`grep "^[^# ]\+[ ]\+${2}[ ]" /tmp/fstab|head -1|awk '{print $1}'`
- if [ "$dev" -a "$dev" != "$1" ]; then
- echo "##old##$REPLY" >> $TMP/fstab
- echo "$dev $2 $3 $4 $5 $6" >> $TMP/fstab # keep options
- else
- echo "$REPLY" >> $TMP/fstab # was commented or the same
- fi
- fi
- done < $MNT/etc/fstab
-
- # add new entries
- while read; do
- set -- $REPLY
- if ! grep -q "^[^ ]\+[ ]\+${2}[ ]" $TMP/fstab; then
- echo "$REPLY" >> $TMP/fstab
- fi
- done < /tmp/fstab
- fi
-
- # try to update lilo.conf
-
- if [ -e $MNT/etc/lilo.conf -a "$UPDATE_ONLY" = "y" ]; then
- rm -f $TMP/lilo.conf
- if grep -q "^image.*$KERNVER" $MNT/etc/lilo.conf; then
- # the latest kernel is referenced. We can use this conf.
- (echo "boot = $BOOTDEV" ; grep -v "^boot[ ]*=[ ]*$BOOTDEV" $MNT/etc/lilo.conf | sed 's/^\(boot[ ]*=\)/##old##\1/') > $TMP/lilo.conf
- else
- # the latest kernel is missing from lilo.conf.
- (echo "boot = $BOOTDEV" ; grep -v "^boot[ ]*=[ ]*$BOOTDEV" $MNT/etc/lilo.conf | sed 's/^\(boot[ ]*=\)/##old##\1/') | sed -e 's:^\(image.*=[^/]*/boot/\)\([^/]*\)\(/.*\)$:\1'$KERNVER'\3:' > $TMP/lilo.conf
- fi
- fi
-
- # now, we may have to update .preinit to create aliased entries.
- # we remove all references to devices that have been updated
-
- grep -v "^[#]*\(ln\|L\).*[ ]\+\($(echo `cut -f2 -d' ' $TMP/devmap`|sed 's@ @\\|@g')\)" $TMP/.preinit > $TMP/.preinit-
- grep -v ' /dev/fs/' $TMP/devmap | sed 's@^/dev/@ln @' >> $TMP/.preinit-
- if grep -q ' /dev/fs' $TMP/devmap; then
- if ! grep -q "^\(md\|M\)[ ]\+/dev/fs" $TMP/.preinit-; then
- echo "md /dev/fs 755" >> $TMP/.preinit-
- fi
- grep ' /dev/fs/' $TMP/devmap | sed 's@^/dev@ln ..@' >> $TMP/.preinit-
- fi
- mv $TMP/.preinit- $TMP/.preinit ; chmod 711 $TMP/.preinit
-
- rm -f $TMP/passwd
- if [ "$UPDATE_ONLY" != "y" -o ! -e $MNT/etc/passwd ]; then
- sed -e 's@/home/admin@/root@' < /etc/passwd |grep -v '^\(squid:\|pdnsd:\|flx:\|install:\)' > $TMP/passwd
- chmod 644 $TMP/passwd
- fi
-
- # if /var is on its own filesystem, /tmp must be a true filesystem too.
- if grep -q ' \(/dev/fs/var\|/dev/fs/var\.tmp\)$' $TMP/devmap; then
- if ! grep -q "^[^ ]\+[ ]\+/tmp[ ]" $TMP/fstab; then
- echo "/tmp /tmp tmpfs defaults,nosuid,nodev 0 0" >> $TMP/fstab
- fi
- fi
-
- cd $MPWD
- return 0
-}
-
-function apply_config {
- local MNT=$1
- local TMP=/tmp/newconf
-
- [ -e $TMP/.preinit ] && (rm -f $MNT/.preinit ; cp -p $TMP/.preinit $MNT)
- [ -e $TMP/passwd ] && (rm -f $MNT/etc/passwd ; cp -p $TMP/passwd $MNT/etc)
- [ -e $TMP/lilo.conf ] && (rm -f $MNT/etc/lilo.conf ; cp -p $TMP/lilo.conf $MNT/etc)
- [ -e $TMP/fstab ] && (rm -f $MNT/etc/fstab ; cp -p $TMP/fstab $MNT/etc)
- [ -e $TMP/config.rc ] && (rm -f $MNT/etc/config.rc ; cp -p $TMP/config.rc $MNT/etc)
- [ -e $TMP/startup.rc ] && (rm -f $MNT/etc/startup.rc ; cp -p $TMP/startup.rc $MNT/etc)
-
- # replace /tmp with a directory if needed
- if grep -q "^[^ ]\+[ ]\+/tmp[ ]" $TMP/fstab; then
- if [ -L $MNT/tmp ]; then rm -f $MNT/tmp && mkdir -m 1777 $MNT/tmp >/dev/null 2>&1; fi
- fi
- return 0
-}
-
-function do_lilo {
- if [ -e $ROOTDIR/dev -a -e $ROOTDIR/.preinit -a -e $ROOTDIR/etc/lilo.conf ]; then
- chroot $ROOTDIR /.preinit rebuild
- chroot $ROOTDIR /sbin/lilo || lilo -r $ROOTDIR
- umount $ROOTDIR/dev # remove what .preinit has installed
- else
- echo "LILO has NOT been run because it needs /dev, /.preinit, and /etc/lilo.conf"
- fi
- return 0
-}
-
-
-
-# main
-
-ROOTDIR=/var/mount
-PKGDIR=/home/pkg
-SHELLDIR=/
-
-init
-
-if [ $0 = "mkdisk" ] ; then setup_part && exit 0 ; exit 1 ;
-elif [ $0 = "mkconfig" ] ; then setup_config $1 && exit 0 ; exit 1 ;
-elif [ $0 = "doconfig" ] ; then apply_config $1 && exit 0 ; exit 1 ;
-fi
-
-end=0
-while [ $# -ge 1 -a "$end" -ne 1 ] ; do
- case $1 in
- --disk) setup_part;;
- --config) setup_config $2; shift;;
- --apply) apply_config $2; shift;;
- --) end=1;;
- *) end=1;;
- esac
- if [ "$end" -eq 1 ] ; then break ; fi
- shift
-done
-
-action="PART"
-while [ -n "$action" ] ; do
-
- ROOTDEV=$(mount | grep " on $ROOTDIR " | cut -f1 -d' ')
-
-# echo
-# echo "Possible actions are :"
-# echo "1: Run fdisk"
-# echo "2: Setup filesystems"
-# echo "3: Install packages"
-# echo "4: Build running config"
-# echo "5: Save built config for next reboot"
-# echo "6: Run lilo"
-# echo "7: Unmount all"
-# echo "s: Shell"
-# echo "q: Quit"
-#
-# ask "Select an action (1..7/s/q)" "$action"
-
- menu_main $action
-
- [ -z "$REPLY" ] && break
-
- if [ "$REPLY" = "SHELL" ] ; then (cd $SHELLDIR; echo -n "Current directory : "; pwd; bash -i); REPLY=$action; continue; fi
-
- case $REPLY in
- PART)
- # unmount previously mounted file-systems
- #for part in $(grep " $ROOTDIR" /proc/mounts|awk '{print $2}'|sort -r); do umount $part; done
- unmount_new_fs
- detect_disks
- REPLY=${names[0]}
- while menu_harddisk $REPLY; do
- disk=${REPLY##/dev/}
-
- #sfdisk -l /dev/$disk
- #yesno "Clear partition table for '/dev/$disk' (y/n)?" "n"
- REPLY=
- while { disk_read_part /dev/$disk ; menu_partition /dev/$disk $REPLY; } do
- part=$REPLY
- [ -z "$REPLY" ] && break
- if [ "$REPLY" = "CLEAR" ] ; then
- if menu_yesno "Warning !\n\nThis will erase the partition table for /dev/$disk.\nAll data will be lost.\n\nDo you still want to proceed ?" N; then
- dd if=/dev/zero of=/dev/$disk bs=1024 count=1 > /dev/null 2>&1
- (echo o ; echo w ) | fdisk /dev/$disk > /dev/null 2>&1
- fi
- REPLY=FDISK
- elif [ "$REPLY" = "FDISK" ]; then
- fdisk /dev/$disk
- REPLY=
- else
- part=$REPLY
- REPLY=
- while menu_setupfs /dev/$part $REPLY; do
- case "$REPLY" in
- SHELL)
- (cd $SHELLDIR; echo -n "Current directory : "; pwd; bash -i)
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part auto") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- # goes automatically to default format
- REPLY=
- ;;
- MNT)
- menu_mount_point /dev/$part
- # goes automatically to default format
- REPLY=
- ;;
- SWAP)
- mkswap /dev/$part
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part swap") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- REPLY=EXIT
- ;;
- SWAPC)
- mkswap -c /dev/$part
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part swap") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- REPLY=EXIT
- ;;
- EXT2S)
- mke2fs -b 1024 -m 1 -s 1 /dev/$part
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part ext2") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- REPLY=EXIT
- ;;
- EXT2L)
- mke2fs -b 4096 -s 1 /dev/$part
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part ext2") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- REPLY=EXIT
- ;;
- EXT3)
- mke2fs -b 4096 -s 1 -j /dev/$part
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part ext3") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- REPLY=EXIT
- ;;
- REISER)
- mkreiserfs -h r5 /dev/$part
- (grep -v "^/dev/$part " /tmp/fstype 2>/dev/null; echo "/dev/$part reiserfs") >/tmp/fstype-
- mv /tmp/fstype- /tmp/fstype
- REPLY=EXIT
- ;;
- esac
- # this is done to exit right after an mkfs
- [ "$REPLY" = "EXIT" ] && break;
- done
- REPLY=
- fi
- done
- # things might have changed !
- detect_disks
- REPLY=/dev/$disk
- done
- # we now have to mount all these file systems
- mount_new_fs
- SHELLDIR=/
- action=SOURCE
- ;;
- SOURCE)
- action=SOURCE
- while menu_select_source; do
- case "$REPLY" in
- CDROM)
- menu_select_cdrom && break;
- ;;
- DISK)
- menu_select_disk
- ;;
- NFS)
- menu_select_nfs
- ;;
- DIR)
- menu_select_dir
- ;;
- esac
- done
- PKGDIR=$(readlink /var/flx-pkg 2>/dev/null)
- [ -d "/var/flx-pkg/." ] && action=PKG
- ;;
- PKG)
- cd /
- if [ "$ROOTDEV" != "" ] ; then
- #ask "Packages directory, or files pattern ($PKGDIR, $PKGDIR/*.lst, *.prf, *.tgz)"$'\n'" " $PKGDIR ; PKGDIR="$REPLY"
- #if [ -d "$PKGDIR" ]; then
- # list=`cd $PKGDIR && ls *.prf *.lst *.tgz 2>/dev/null`
- #else
- # list=`basename "$PKGDIR"`
- # PKGDIR=`dirname "$PKGDIR"`
- # list=$(cd $PKGDIR && echo $list)
- #fi
- menu_pkg_dir
- list=( ); idx=0
- for pack in $(shopt -s nullglob ; cd $PKGDIR && echo *.{prf,tgz}); do
- list[idx++]=$pack
- list[idx++]=""
- if [ -z "${pack##[0-9][0-9][0-9]_*}" ]; then
- # pre-selects every numbered package
- list[idx++]="on"
- else
- list[idx++]="off"
- fi
- done
-
- list=( $(dialog --title " Formilux Installation Utility " --no-shadow \
- --checklist "Packages Selection\n\n Press <Space> to select/deselect a package.\n Press <Up>/<Down> to select an item.\n Press <Tab> to move between [OK] and [Cancel].\n Press <Enter> to install your selection." 24 80 12 "${list[@]}" 2>&1) )
-
- # dialog returns quoted words
- eval list=( "${list[@]}" )
- [ ${#list[@]} -gt 0 ] || break
-
- for pack in "${list[@]}" ; do
- case "$pack" in
- *tgz)
- [ -d "$ROOTDIR" ] || mkdir -p -m 0755 $ROOTDIR
- tar zpxf $PKGDIR/$pack -C $ROOTDIR ;;
- *prf)
- flxextract -R $ROOTDIR -p $PKGDIR -i $PKGDIR/$pack ;;
- esac
- done
- check_directories || exit 1
- SHELLDIR=/
- action=CONFIG
- else
- action=PART
- fi
- ;;
- CONFIG)
- check_directories || exit 1
- if [ "$UPDATE_ONLY" != "n" -a "$UPDATE_ONLY" != "y" ]; then
- echo "Existing files can be REPLACED or UPDATED."
- yesno "Do you prefer to UPDATE existing files (y/n) ?" "y"
- UPDATE_ONLY="$REPLY"
- fi
- setup_config $ROOTDIR
- echo "done."
- echo "New files have been written to /tmp/newconf/"
- echo "You can check them now by starting a shell."
- SHELLDIR=/tmp/newconf
- (cd $SHELLDIR ; ls -lart)
- action=SAVE
- ;;
- SAVE)
- echo "Saving config (.preinit, startup.rc, config.rc, fstab, lilo.conf, passwd)"
- apply_config $ROOTDIR
- echo "Saving config ... done."
- echo "Updating dynamic files (/etc/formilux/sig.dat, /etc/ld.so.cache) ... "
- ldconfig -r $ROOTDIR > /dev/null 2>&1
-
- for SYSTEMMAP in `echo $ROOTDIR/boot/System.map-*`; do
- KERNVER=${SYSTEMMAP#$ROOTDIR/boot/System.map-}
- chroot $ROOTDIR depmod -a -F /boot/System.map-$KERNVER $KERNVER
- done
-
- echo "Signing the filesystem... (this may take a while)"
- cd $ROOTDIR ; signfs -x `mount|grep -v ' type \(tmpfs\|ramfs\)'|grep "^/.* $ROOTDIR "| \
- sed "s@^.*$ROOTDIR\([^ ]*\) .*@.\1@"` > /etc/formilux/sig.dat
- echo "Updating dynamic files ... done."
- SHELLDIR=/
- action=LILO
- ;;
- LILO)
- do_lilo
- SHELLDIR=/
- action=UNMOUNT
- ;;
- UNMOUNT)
- cd /
- unmount_new_fs
- umount -l /mnt/cdrom >/dev/null 2>&1
- SHELLDIR=/
- action=EXIT
- ;;
- *)
- ;;
- esac
-done
-
diff --git a/scripts/pkg b/scripts/pkg
index ab88db7..5168074 100755
--- a/scripts/pkg
+++ b/scripts/pkg
@@ -1,6 +1,6 @@
#!/bin/bash
-# pkg - Formilux package builder - version 0.3.2 - 2003-06-09
+# pkg - Formilux package builder - version 0.3.11 - 2003-09-14
#
# Copyright (C) 2001-2003 Benoit Dolez & Willy Tarreau
# mailto: benoit@ant-computing.com,willy@ant-computing.com
@@ -23,13 +23,13 @@
# pkg setpkg [ new_pkg ]
# ex: pkg setpkg openssl-0.9.6g-flx0.1
#
-# pkg { info | cat | edit } [ pkg ]
+# pkg { info | cat | edit | unpack } [ pkg ]
# ex: pkg info
# pkg info bash
# pkg edit modutils-2.4
# pkg cat gzip-1.3
#
-# pkg { compile,build,prepack,strip,pack,unpack,delpack,release,clean }*
+# pkg { compile,build,prepack,strip,pack,delpack,release,clean }*
#
# pkg { patch | unpatch } [ patch_name ]
#
@@ -64,8 +64,33 @@ CFGSUFF="cfg"
INSTNAME=".flxdisk"
LINKNAME=".flxpkg"
+FIND_CMD=pkgfilefind
+
FILE_LIST=
+# all the directories that should be ignored by do_pack
+EXCLUDE_LIST=( bin boot dev etc etc/opt home lib lib/modules mnt mnt/disk mnt/cdrom mnt/usb mnt/nfs mnt/floppy opt opt/bin opt/lib opt/sbin proc root root/bin sbin sbin/init.d usr usr/bin usr/lib usr/sbin usr/share usr/share/examples var var/tmp var/run var/cache var/empty var/lib var/log var/spool var/adm )
+
+######
+###### here are some undertermined type functions
+######
+
+# find packageable files (that can't be automaticaly created) and return only
+# their relative path to the argument.
+
+function pkgfilefind {
+ local start=${1%%/}
+ local dir
+ local -a exclude_args=( )
+
+ for dir in "${EXCLUDE_LIST[@]}"; do
+ exclude_args=( "${exclude_args[@]}" -and -not -path "${start}/${dir}" )
+ done
+
+ find ${start} -not -path ${start} \( -empty -o \! -type d -o \! -uid 0 -o \! -gid 0 -o \! -perm 0755 \) "${exclude_args[@]}" -printf "%P\n"
+}
+
+
######
###### here are some functions for manipulating package names
######
@@ -168,6 +193,139 @@ function sortnames {
echo "${list[*]}" | sort -t , $flist | cut -f2 -d~
}
+
+######
+###### here are some "exported" functions used to ease file manipulation
+######
+
+#
+# usage: set_perm uid:gid mode file...
+function set_perm {
+ local own mode
+ [ $# -gt 2 ] || return 1
+ own=$1 ; shift
+ mode=$1 ; shift
+ chown $own "$@"
+ chmod $mode "$@"
+ return 0
+}
+
+#
+# usage: set_default_perm $ROOTDIR/start_dir
+function set_default_perm {
+ local start_dir=$1
+ local strip_dir=${ROOTDIR%%/}
+ local type executable script
+
+ if [ -z "$1" ]; then
+ echo; echo "### ERROR! set_default_perm called without arguments !!!"
+ echo "### You must specify the root directory to fix."
+ return 1
+ fi
+
+ echo
+ echo "PKG : Fixing permissions in $1 ... "
+ echo " Please wait..."
+ echo " Fixing directories..."
+
+ # first pass : check directories
+ find $start_dir -type d | while read; do
+ case "${REPLY##$strip_dir}" in
+ /|/.)
+ set_perm root:root 755 "$REPLY"
+ ;;
+ /sbin|/sbin/init.d|/usr/sbin)
+ set_perm root:adm 751 "$REPLY"
+ ;;
+ /root)
+ set_perm root:root 700 "$REPLY"
+ ;;
+ /etc/formilux|/var/core)
+ set_perm root:adm 750 "$REPLY"
+ ;;
+ *)
+ if [ ! -u "$REPLY" -a ! -g "$REPLY" -a ! -k "$REPLY" ]; then
+ set_perm root:root 755 "$REPLY"
+ fi
+ ;;
+ esac
+ done
+
+ echo " Fixing special files..."
+ # second pass : check special files (block, char, fifo)
+ find $start_dir -not -type d -a -not -type f | while read; do
+ if [ -b "$REPLY" -o -c "$REPLY" -o -p "$REPLY" ]; then
+ set_perm root:root 600 "$REPLY"
+ fi
+ done
+
+ echo " Fixing regular files..."
+ # third pass : check regular files
+ find $start_dir -type f | while read; do
+ if [ -u "$REPLY" -o -g "$REPLY" ]; then
+ chmod o-rw "$REPLY"
+ else
+ type=$(file -z "$REPLY")
+ executable=0
+ script=0
+
+ if [ -z "${type//*ELF [0-9][0-9]-bit */}" -o \
+ -z "${type//*ERROR: Corrupt*/}" ]; then
+ executable=1
+ elif [ -z "${type//*script*/}" ]; then
+ script=1
+ fi
+
+ #echo "processing ${REPLY##$strip_dir}"
+ case "${REPLY##$strip_dir}" in
+ /bin/*|/usr/bin/*|/opt/bin/*|/opt/*/bin/*|/sbin/init.d/*)
+ if [ $executable -gt 0 ]; then
+ set_perm root:adm ug-w,o-rw "$REPLY"
+ elif [ $script -gt 0 ]; then
+ set_perm root:adm ugo-w "$REPLY"
+ else
+ set_perm root:adm ugo-w "$REPLY"
+ fi
+ ;;
+ /sbin/*|/usr/sbin/*)
+ if [ $executable -gt 0 ]; then
+ set_perm root:adm u-sw,g-wx,o-rwx "$REPLY"
+ elif [ $script -gt 0 ]; then
+ set_perm root:adm u-sw,g-swx,o-rwx "$REPLY"
+ else
+ # neither an exec nor a script, no need to execute it !
+ set_perm root:adm ug-swx,o-wx "$REPLY"
+ fi
+ ;;
+ /lib/*.so|/lib/*.so.*|/usr/lib/*.so|/usr/lib/*.so.*|\
+ /opt/lib/*.so|/opt/lib/*.so.*|/opt/*/lib/*.so|/opt/*/lib/*.so.*)
+ set_perm root:adm ug-sw,o-w "$REPLY"
+ ;;
+ /lib/*.[ao]|/usr/lib/*.[ao]|/opt/lib/*.[ao]|/opt/*/lib/*.[ao])
+ set_perm root:adm ugo-swx "$REPLY"
+ ;;
+ /usr/man/man*/*)
+ set_perm root:man ugo-swx "$REPLY"
+ ;;
+ /usr/doc/*|/usr/info/*)
+ set_perm root:man ugo-swx "$REPLY"
+ ;;
+ /boot/*/*|/boot/*|/etc/*/*)
+ set_perm root:man ug-swx,o-rwx "$REPLY"
+ ;;
+ /etc/*|/usr/share/examples/*|/usr/share/examples/*/*)
+ set_perm root:man ugo-swx "$REPLY"
+ ;;
+ *)
+ # chgrp adm if not setgid and group==root
+ # chmod ugo-w if user==root
+ ;;
+ esac
+ fi
+ done
+ echo "PKG : done fixing permissions."
+}
+
######
###### here are "exported" functions, which can be used and redefined by build.cfg
######
@@ -181,6 +339,7 @@ function do_build {
declare -f do_$ACTION > /dev/null && { ( do_$ACTION $* ) || return $?; }
declare -f post_$ACTION > /dev/null && { ( post_$ACTION $* ) || return $?; }
done
+ return 0
}
# this function returns one exact package name from a list of potentially
@@ -467,7 +626,7 @@ function do_newpkg {
fi
rm -f ${LINKNAME} && mkdir -p $new_name && ln -s $new_name ${LINKNAME} && \
- tar -C $pkg_name --exclude='compiled/*' --exclude='released.*' -cplf - . | tar -C $new_name -xf - || \
+ tar -C $pkg_name --exclude='compiled/*' --exclude='released.*' --exclude='./pkg.*' -cplf - . | tar -C $new_name -xf - || \
(rmdir $new_name ; rm -f ${LINKNAME})
echo "A new package '$(basename $new_name)' has been created as '$new_name', based on '$(basename $pkg_name)'."
echo "The link '${LINKNAME}' now points to it."
@@ -490,6 +649,13 @@ function do_cat {
cat $CFGFILE
}
+function do_lst {
+ local FPNAME
+
+ FPNAME=$PKGDIR/compiled/$EXACTPKG-$FLXARCH
+ cat $FPNAME.lst
+}
+
function pre_info {
echo "Information for package '$EXACTPKG' :"
@@ -508,7 +674,7 @@ function pre_info {
else
echo "does not exist yet."
fi
- [ "$PATCH_LIST" ] && echo " Patches list : $PATCH_LIST"
+ [ -n "${PATCH_LIST}" ] && echo " Patches list : ${PATCH_LIST}"
return 0
}
@@ -542,17 +708,27 @@ function pre_prepack {
# WARNING! here, we don't use $ROOTDIR because we don't want to risk
# erasing a wrong directory as root !
[ -d $(pwd)/${INSTNAME} ] && rm -rf $(pwd)/${INSTNAME}
+ # permissions are important here because we don't want to get an
+ # inherited setgid or something alike on the root dir
+ [ ! -d "$ROOTDIR" ] && { mkdir -p $ROOTDIR; chmod 0755 $ROOTDIR; }
+ #mkdir -p "$EXAMPLEDIR"
return 0
}
-# some cleanup of an eventual opt directory after prepack()
-function post_prepack {
+# build link in /opt directory
+# INPUT: selected path to creation in /opt
+function build_opt {
local dir
+
if [ -d $ROOTDIR/opt ] ; then (
+ [ $# = 0 ] && set -- bin sbin lib
+ set +o noglob
+ shopt -s nullglob
cd $ROOTDIR/opt
- for dir in bin sbin lib ; do
+ for dir in $* ; do
mkdir $dir
- find */$dir -type f -perm +111 -exec ln -s ../{} $dir \; -printf "ln -s ../%p $ROOTDIR/opt/$dir\n"
+ dirs=( */$dir )
+ [ -n "${dirs[*]}" ] && find ${dirs[@]} -type f -perm +111 -exec ln -s ../{} $dir \; -printf "ln -s ../%p $ROOTDIR/opt/$dir\n"
done
) fi
return 0
@@ -579,8 +755,13 @@ function do_patch {
local i
find . -name '*.rej' -o -name '*~' | xargs rm -f
- for i in $PATCH_LIST; do
- patch -Np$PATCH_LEVEL < $PKGDIR/patches/$i
+ for i in ${PATCH_LIST}; do
+ [ ! -e "$PKGDIR/patches/$i" -a -e "$PKGDIR/patches/$i.gz" ] && i="$i.gz"
+ if [ -z "${i##*.gz}" ]; then
+ gzip -cd < $PKGDIR/patches/$i | patch -Np$PATCH_LEVEL
+ else
+ patch -Np$PATCH_LEVEL < $PKGDIR/patches/$i
+ fi
done
if [ -z "$(find . -name '*.rej')" ]; then
@@ -597,12 +778,17 @@ function do_unpatch {
find . -name '*.rej' -o -name '*~' | xargs rm -f
- for i in $PATCH_LIST; do
- UNPATCH_LIST="$i $UNPATCH_LIST"
+ for i in ${PATCH_LIST}; do
+ UNPATCH_LIST=( $i ${UNPATCH_LIST[@]} )
done
- for i in $UNPATCH_LIST; do
- patch -RNp$PATCH_LEVEL < $PKGDIR/patches/$i
+ for i in ${UNPATCH_LIST[@]}; do
+ [ ! -e "$PKGDIR/patches/$i" -a -e "$PKGDIR/patches/$i.gz" ] && i="$i.gz"
+ if [ -z "${i##*.gz}" ]; then
+ gzip -cd < $PKGDIR/patches/$i | patch -RNp$PATCH_LEVEL
+ else
+ patch -RNp$PATCH_LEVEL < $PKGDIR/patches/$i
+ fi
done
if [ -z "$(find . -name '*.rej')" ]; then
@@ -627,7 +813,7 @@ function do_unpack {
# Abort if ROOTDIR doesn't exist (thus needing prepack() first).
function do_strip {
if [ ! -d $ROOTDIR ] ; then
- echo "Error: directory $ROOTDIR doesn't exist. Make sure you dir 'prepack'."
+ echo "Error: directory $ROOTDIR doesn't exist. Make sure you did 'prepack'."
exit 1
fi
#find $ROOTDIR/. -type f | xargs file | grep ":.*executable.*not stripped" | cut -f1 -d: | xargs strip -x --strip-unneeded -R .note -R .comment > /dev/null 2>&1
@@ -638,12 +824,15 @@ function do_strip {
# forces pack() to strip before starting, even if do_pack() is redefined by the user.
function pre_pack {
+ # in the mean time, we avoid removing this directory since it could have
+ # been brought legally by an authorized package.
+ #[ $(find $EXAMPLEDIR | wc -l) = 1 ] && rmdir -p $EXAMPLEDIR 2>/dev/null
( do_strip )
return 0
}
# this function finds perl dependencies for a given file.
-# It's only called from do_pack_files() and do_pack()
+# It's only called from _do_pack_files() and do_pack()
function get_perl_depend {
local filename=$1
local dep DEP
@@ -668,25 +857,26 @@ function get_perl_depend {
# same as pack, except that it uses files in the current directory as the root
# entries, and that no strip, link nor compression is performed.
-# Only entries listed in the file pointed to by variable FILE_LIST find their
-# way to the archive.
+# Only entries listed in the files pointed to by $* find their way to the archive.
# This function relies on get_perl_depend().
-function do_pack_files {
- local DEP_FILE FPNAME
+function _do_pack_files {
+ local DEP_FILE FPNAME ext
+ local FILE_LIST=$*
+ echo -n "Updating timestamps ... "
find . -not -type l | xargs touch -m
+ echo "done."
# full path name of different files
FPNAME=$PKGDIR/compiled/$EXACTPKG-$FLXARCH
DEP_FILE=$FPNAME.dep
- # FIXME: absurde ? : rm puis cat !
rm -rf $DEP_FILE
- if [ -e $DEP_FILE.diff ] ; then cat $DEP_FILE.diff $DEP_FILE ; fi
+ if [ -e $DEP_FILE.diff ] ; then cat $DEP_FILE.diff > $DEP_FILE ; fi
echo -n "Creating $DEP_FILE ... "
touch $DEP_FILE
- find . -type f -o -type l | while read ; do
+ ( set +f; shopt -s nullglob ; shopt -s dotglob ; find * -type f -o -type l ) | while read ; do
case $REPLY in
*.pm|*.pl|*.ph)
get_perl_depend $REPLY
@@ -710,10 +900,10 @@ function do_pack_files {
*:\ symbolic\ link*)
echo "$REPLY $(echo $flr | cut -f5 -d' ')" >> $DEP_FILE
;;
- *\ ELF\ 32-bit\ LSB*dynamically\ linked*)
+ *\ ELF\ [0-9][0-9]-bit\ *dynamically\ linked*)
echo "$REPLY $(ldd $REPLY 2>/dev/null | grep -v 'statically linked' | awk '{print $1}' | tr '\012' ' ')" >> $DEP_FILE
;;
- *\ ELF\ 32-bit\ LSB*shared\ object*)
+ *\ ELF\ [0-9][0-9]-bit\ *shared\ object*)
echo "$REPLY $(ldd $REPLY 2>/dev/null | grep -v 'statically linked' | awk '{print $1}' | tr '\012' ' ')" >> $DEP_FILE
;;
esac
@@ -738,6 +928,12 @@ function do_pack_files {
# we want everything, including directories.
cut -f1 -d' ' $FILE_LIST|sed -e 's,/$,,' | tar -T - --no-recursion -cf - | gzip -9 >$FPNAME.$PKGSUFF 2>/dev/null
+
+ # create shortcuts ".*" for tgz, dep and lst files
+ for ext in dep lst tgz; do
+ rm -f $PKGDIR/.$ext
+ ln -sf compiled/$EXACTPKG-$FLXARCH.$ext $PKGDIR/.$ext
+ done
echo "done."
return 0
}
@@ -745,37 +941,76 @@ function do_pack_files {
# packs the prepacked files into a new file located in $DEVROOT.
# any eventual old package is removed.
-# this function relies on do_pack_files(), get_perl_depend(),
+# this function relies on _do_pack_files(), get_perl_depend(),
function do_pack {
local DEP_FILE FPNAME
+ local FILE_LISTS ext
- # use the file list when available
- if [ "$FILE_LIST" ]; then
- do_pack_files
- return $?
- fi
-
+ # normalize the list with an absolute path for each entry
+ for file in $FILE_LIST ; do
+ if [ -z "${file##/*}" ]; then
+ FILE_LISTS="$FILE_LISTS $file"
+ else
+ FILE_LISTS="$FILE_LISTS $(pwd)/$file"
+ fi
+ done
# FIXME: is this normal ???
- if [ ! -d $ROOTDIR ] ; then export ROOTDIR=$(pwd) ; fi
+ if [ ! -d "$ROOTDIR" ] ; then
+ echo "Error: \$ROOTDIR doesn't point to a valid directory : $ROOTDIR"
+ exit 1
+ fi
cd $ROOTDIR
+ # use the file list when available
+ if [ "$FILE_LISTS" ]; then
+ _do_pack_files $FILE_LISTS
+ return $?
+ fi
+
## ( find lib -type l -name "lib*.so*" | xargs rm -f ; \
## find usr/lib -type l -name "lib*.so*" | xargs rm -f ; \
## ldconfig -nr . ) > /dev/null 2>&1
+
+ echo -n "Updating libraries ... "
ldconfig -nr . lib usr/lib > /dev/null 2>&1
+ echo "done."
+
+ echo -n "Updating timestamps ... "
find . ! -type l | xargs touch -m
+ echo "done."
# full path name of different files
FPNAME=$PKGDIR/compiled/$EXACTPKG-$FLXARCH
DEP_FILE=$FPNAME.dep
- # FIXME: absurde ? : rm puis cat !
+ # rebuild dependencies file, first is a diff file
+ echo -n "Creating $DEP_FILE ... "
rm -rf $DEP_FILE
- if [ -e $DEP_FILE.diff ] ; then cat $DEP_FILE.diff $DEP_FILE ; fi
+ if [ -e $DEP_FILE.diff ] ; then cat $DEP_FILE.diff > $DEP_FILE ; fi
+
+ # build a one shot function 'add' to add dependences
+ oldadd="$(declare -f add)"
+ # usage: add file [...] need file [...]
+ function add {
+ local file files
+ # remove file
+ while [ $# -gt 0 -a "x$1" != xneed ] ; do
+ files=( "$1" "${files[@]}" )
+ shift
+ done
+ [ $# -le 1 ] && return
+ shift
+ for file in "${files}" ; do echo "$file $*" >> $DEP_FILE ; done
+ }
+ # load dependences function
+ declare -f load_deps > /dev/null && ( load_deps )
+ # reset 'add' function
+ unset add
+ # reload old one
+ [ -n "$oldadd" ] && eval "$oldadd"
- echo -n "Creating $DEP_FILE ... "
touch $DEP_FILE
- find . -type f -o -type l | while read ; do
+ find . \( -type f -o -type l \) -printf "%P\n" | while read ; do
case $REPLY in
*.pm|*.pl|*.ph)
get_perl_depend $REPLY
@@ -813,10 +1048,10 @@ function do_pack {
*:\ symbolic\ link*)
echo "$REPLY $(echo $flr | cut -f5 -d' ')" >> $DEP_FILE
;;
- *\ ELF\ 32-bit\ LSB*dynamically\ linked*)
+ *\ ELF\ [0-9][0-9]-bit\ *dynamically\ linked*)
echo "$REPLY $(ldd $REPLY 2>/dev/null | grep -v 'statically linked' | awk '{print $1}' | tr '\012' ' ')" >> $DEP_FILE
;;
- *\ ELF\ 32-bit\ LSB*shared\ object*)
+ *\ ELF\ [0-9][0-9]-bit\ *shared\ object*)
echo "$REPLY $(ldd $REPLY 2>/dev/null | grep -v 'statically linked' | awk '{print $1}' | tr '\012' ' ')" >> $DEP_FILE
;;
esac
@@ -826,13 +1061,20 @@ function do_pack {
echo "done."
echo -n "Creating $FPNAME.lst ... "
- (find . ! -type d -o -empty | cut -c3-| xargs flx sign --ignore-dot --no-depth > $FPNAME.lst) > /dev/null 2>&1
+ ($FIND_CMD . | xargs flx sign --ignore-dot --no-depth > $FPNAME.lst) > /dev/null 2>&1
echo "done."
echo -n "Creating $FPNAME.$PKGSUFF ... "
- # we want everything, and directories only if they're empty. All this without './'
- # we shouldn't get an empty line since . should contain at least what we want to tar !
- find . ! -type d -o -empty | cut -c3- | tar -T - -cf - | gzip -9 >$FPNAME.$PKGSUFF 2>/dev/null
+ # we want everything, and directories only if they're empty.
+ # All this without './' we shouldn't get an empty line since .
+ # should contain at least what we want to tar !
+ $FIND_CMD . | tar --no-recursion -T - -cf - | gzip -9 >$FPNAME.$PKGSUFF 2>/dev/null
+
+ # create shortcuts ".*" for tgz, dep and lst files
+ for ext in dep lst tgz; do
+ rm -f $PKGDIR/.$ext
+ ln -sf compiled/$EXACTPKG-$FLXARCH.$ext $PKGDIR/.$ext
+ done
echo "done."
return 0
}
@@ -850,14 +1092,14 @@ function usage {
echo " pkg setpkg [ new_pkg ]"
echo " ex: pkg setpkg openssl-0.9.6g-${BUILDSFX}${BUILDVER}.1"
echo
- echo " pkg { info | cat | edit } [ pkg ]"
+ echo " pkg { info | cat | edit | unpack } [ pkg ]"
echo " ex: pkg info"
echo " pkg info bash"
echo " pkg edit modutils-2.4"
echo " pkg cat gzip-1.3"
echo
- echo " pkg { compile | config | compile_only | build | prepack }*"
- echo " pkg { strip | pack | unpack | delpack | release | clean }*"
+ echo " pkg { clean | compile | config | compile_only | build }*"
+ echo " pkg { prepack | strip | pack | delpack | release }*"
echo
echo " pkg { patch | unpatch } [ patch_name ]"
echo
@@ -897,6 +1139,7 @@ function known_cmd {
declare -f pre_$ACTION > /dev/null && { ( pre_$ACTION $* ) || return $?; }
declare -f do_$ACTION > /dev/null && { ( do_$ACTION $* ) || return $?; }
declare -f post_$ACTION > /dev/null && { ( post_$ACTION $* ) || return $?; }
+ return 0
}
@@ -950,7 +1193,7 @@ done
# Some actions can be chained, others not. we'll get the longest
# possible chain, and stop once we encounter a non-chainable action
-while [ $CHAINCMD -gt 0 ]; do
+while [ $CHAINCMD -gt 0 -a ${#ARGLIST[@]} -gt 0 ]; do
set -o noglob
ACTION=${ARGLIST[0]}
@@ -968,7 +1211,7 @@ while [ $CHAINCMD -gt 0 ]; do
KNOWNCMD=1
get_name $1 %P default
;;
- info|edit|cat)
+ info|edit|cat|unpack)
CHAINCMD=0
KNOWNCMD=1
get_name ${ARGLIST[0]} %L %P %D
@@ -979,7 +1222,7 @@ while [ $CHAINCMD -gt 0 ]; do
REPLY=$(basename $(readlink ${LINKNAME}) 2>/dev/null)
# get_name %L
;;
- compile_only|config|config_only|compile|build|prepack|strip|pack|unpack|delpack|release|clean)
+ compile_only|config|config_only|compile|build|prepack|strip|pack|delpack|release|clean)
KNOWNCMD=1
REPLY=$(basename $(readlink ${LINKNAME}) 2>/dev/null)
# get_name %L
@@ -992,6 +1235,8 @@ while [ $CHAINCMD -gt 0 ]; do
;;
esac
+ [ $CHAINCMD -gt 0 ] && (echo;echo "===> PKG: starting [$ACTION] <===") >&2
+
set +o noglob
if [ "$ACTION" != "newpkg" ]; then
if [ -z "$REPLY" ]; then
@@ -1010,6 +1255,7 @@ while [ $CHAINCMD -gt 0 ]; do
PKGVER=$(get_pkg_ver $EXACTPKG)
DISTVER=$(get_build_num $EXACTPKG)
ROOTDIR=${ROOTDIR:-$(pwd)/${INSTNAME}}
+ EXAMPLEDIR=${ROOTDIR}/usr/share/examples
# for compatibility with old functions. Not used anywhere outside this script.
packver=$EXACTPKG
@@ -1022,6 +1268,7 @@ while [ $CHAINCMD -gt 0 ]; do
i686) arch=i686 cpu=i686 basearch=i386 ;;
i486) arch=i486 cpu=i486 basearch=i386 ;;
i386) arch=i386 cpu=i386 basearch=i386 ;;
+ ev6) arch=ev6 cpu=ev6 basearch=ev6 ;;
*) arch=i586 cpu=i686 basearch=i386 ;;
esac
@@ -1041,11 +1288,13 @@ while [ $CHAINCMD -gt 0 ]; do
( do_$ACTION ${ARGLIST[*]} ) || exit 1
fi
fi
+ [ $CHAINCMD -gt 0 ] && (echo "===> PKG: end of [$ACTION] <===";echo) >&2
# now, we'll loop only if we were in a chainable action
done
-
+[ $CHAINCMD -gt 0 ] && (echo "===> PKG: [END] <===";echo) >&2
+exit 0
@@ -1146,13 +1395,14 @@ function usage {
echo " build : execute clean compile prepack pack."
echo " unpack : extract package into temporary directory"
echo "Variables are :"
- echo "CFGROOT : directory for .pkg and patches, <$CFGROOT>"
- echo "CFGFILE : force to use of a .pkg, <$CFGFILE>"
- echo "PKGROOT : directory for .lst, .tgz and .dep, <$PKGROOT>"
- echo "ROOTDIR : base directory for package (not source), <$ROOTDIR>"
- echo "FLXARCH : architecture for package name, <$FLXARCH>"
- echo "KERNDIR : base directory for package (not source), <$KERNDIR>"
- echo "DISTVER : build version (flx.1)"
+ echo "CFGROOT : directory for .pkg and patches, <$CFGROOT>"
+ echo "CFGFILE : force to use of a .pkg, <$CFGFILE>"
+ echo "PKGROOT : directory for .lst, .tgz and .dep, <$PKGROOT>"
+ echo "ROOTDIR : base directory for package (not source), <$ROOTDIR>"
+ echo "EXAMPLEDIR : base directory for sample config , <$EXAMPLEDIR>"
+ echo "FLXARCH : architecture for package name, <$FLXARCH>"
+ echo "KERNDIR : base directory for package (not source), <$KERNDIR>"
+ echo "DISTVER : build version (flx.1)"
exit 1
}
@@ -1440,9 +1690,9 @@ else
fi
- if [ -z "$PATCH_LIST" ]; then
+ if [ -z "${PATCH_LIST}" ]; then
PATCH_LIST=${CFGFILE%%.$CFGSUFF}.diff
- if [ ! -e "$PATCH_LIST" ]; then
+ if [ ! -e ${PATCH_LIST} ]; then
unset PATCH_LIST
fi
fi