aboutsummaryrefslogtreecommitdiffstats
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
parent[RELEASE] flxutils-0.1.17 (diff)
downloadflxutils-a9ca11bf64f18a1671f0b0810cfcc5fa7d0acf6d.tar.gz
[RELEASE] flxutils-0.1.18v0.1.18
-rw-r--r--ChangeLog17
-rw-r--r--ifenslave/Makefile8
-rw-r--r--ifenslave/ifenslave-1.0.11.c (renamed from ifenslave/ifenslave.c)0
-rw-r--r--ifenslave/ifenslave-1.0.12.c769
-rwxr-xr-xscripts/mkinstall995
-rwxr-xr-xscripts/mkinstall.old595
-rwxr-xr-xscripts/mkinstall21218
-rwxr-xr-xscripts/pkg370
8 files changed, 2511 insertions, 1461 deletions
diff --git a/ChangeLog b/ChangeLog
index 3881c60..74d27be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,3 +7,20 @@
- reverted to ifenslave 1.0.11 because 1.0.12 breaks compatibility with
older versions while it claims to fix it !
- release 0.1.17
+
+2003/08/02
+ - fixed a bug in mkinstall2 which would prevent it from installing on
+ partition devices which contains '/' in their names (eg: /dev/ida/...)
+
+2003/08/17
+ - updated pkg to 0.3.5 :
+ - unpack accepts a package name
+ - chaining of actions has been fixed
+ - set_default_perm
+ - increased verbosity
+
+2003/09/14
+ - changed mkinstall2 to mkinstall and renamed old mkinstall to mkinstall.old
+ - updated pkg to 0.3.11. Now works on alpha.
+ - included ifenslave 1.0.11 and 1.0.12 with a symlink to let the user choose.
+ - release 0.1.18
diff --git a/ifenslave/Makefile b/ifenslave/Makefile
index e90f13f..116268d 100644
--- a/ifenslave/Makefile
+++ b/ifenslave/Makefile
@@ -1,4 +1,4 @@
-OBJS=ifenslave
+OBJS=ifenslave-1.0.11 ifenslave-1.0.12 ifenslave
# include ../../include/rules.make
CC=gcc
CFLAGS+=-Wstrict-prototypes -I/usr/src/linux/include -momit-leaf-frame-pointer
@@ -8,7 +8,11 @@ all: $(OBJS)
clean:
rm -vf $(OBJS) core *.[oa] *~
-ifenslave: ifenslave.o
+ifenslave:
+ rm -f ifenslave
+ ln -s ifenslave-1.0.12 ifenslave
+
+%: %.o
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
strip -R .comment -R .note $@
objdump -h $@ | grep -q '\.data[ ]*00000000' && strip -R .data $@ || true
diff --git a/ifenslave/ifenslave.c b/ifenslave/ifenslave-1.0.11.c
index 62cd9ad..62cd9ad 100644
--- a/ifenslave/ifenslave.c
+++ b/ifenslave/ifenslave-1.0.11.c
diff --git a/ifenslave/ifenslave-1.0.12.c b/ifenslave/ifenslave-1.0.12.c
new file mode 100644
index 0000000..07c8df0
--- /dev/null
+++ b/ifenslave/ifenslave-1.0.12.c
@@ -0,0 +1,769 @@
+/* Mode: C;
+ * ifenslave.c: Configure network interfaces for parallel routing.
+ *
+ * This program controls the Linux implementation of running multiple
+ * network interfaces in parallel.
+ *
+ * Usage: ifenslave [-v] master-interface < slave-interface [metric <N>] > ...
+ *
+ * Author: Donald Becker <becker@cesdis.gsfc.nasa.gov>
+ * Copyright 1994-1996 Donald Becker
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
+ * Center of Excellence in Space Data and Information Sciences
+ * Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
+ *
+ * Changes :
+ * - 2000/10/02 Willy Tarreau <willy at meta-x.org> :
+ * - few fixes. Master's MAC address is now correctly taken from
+ * the first device when not previously set ;
+ * - detach support : call BOND_RELEASE to detach an enslaved interface.
+ * - give a mini-howto from command-line help : # ifenslave -h
+ *
+ * - 2001/02/16 Chad N. Tindel <ctindel at ieee dot org> :
+ * - Master is now brought down before setting the MAC address. In
+ * the 2.4 kernel you can't change the MAC address while the device is
+ * up because you get EBUSY.
+ *
+ * - 2001/09/13 Takao Indoh <indou dot takao at jp dot fujitsu dot com>
+ * - Added the ability to change the active interface on a mode 1 bond
+ * at runtime.
+ *
+ * - 2001/10/23 Chad N. Tindel <ctindel at ieee dot org> :
+ * - No longer set the MAC address of the master. The bond device will
+ * take care of this itself
+ * - Try the SIOC*** versions of the bonding ioctls before using the
+ * old versions
+ * - 2002/02/18 Erik Habbinga <erik_habbinga @ hp dot com> :
+ * - ifr2.ifr_flags was not initialized in the hwaddr_notset case,
+ * SIOCGIFFLAGS now called before hwaddr_notset test
+ *
+ * - 2002/10/31 Tony Cureington <tony.cureington * hp_com> :
+ * - If the master does not have a hardware address when the first slave
+ * is enslaved, the master is assigned the hardware address of that
+ * slave - there is a comment in bonding.c stating "ifenslave takes
+ * care of this now." This corrects the problem of slaves having
+ * different hardware addresses in active-backup mode when
+ * multiple interfaces are specified on a single ifenslave command
+ * (ifenslave bond0 eth0 eth1).
+ *
+ * - 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
+ * Shmulik Hen <shmulik.hen at intel dot com>
+ * - Moved setting the slave's mac address and openning it, from
+ * the application to the driver. This enables support of modes
+ * that need to use the unique mac address of each slave.
+ * The driver also takes care of closing the slave and restoring its
+ * original mac address upon release.
+ * In addition, block possibility of enslaving before the master is up.
+ * This prevents putting the system in an undefined state.
+ *
+ * - 2003/05/01 - Amir Noam <amir.noam at intel dot com>
+ * - Added ABI version control to restore compatibility between
+ * new/old ifenslave and new/old bonding.
+ * - Prevent adding an adapter that is already a slave.
+ * Fixes the problem of stalling the transmission and leaving
+ * the slave in a down state.
+ *
+ * - 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
+ * - Prevent enslaving if the bond device is down.
+ * Fixes the problem of leaving the system in unstable state and
+ * halting when trying to remove the module.
+ * - Close socket on all abnormal exists.
+ * - Add versioning scheme that follows that of the bonding driver.
+ * current version is 1.0.0 as a base line.
+ *
+ * - 2003/05/22 - Jay Vosburgh <fubar at us dot ibm dot com>
+ * - ifenslave -c was broken; it's now fixed
+ * - Fixed problem with routes vanishing from master during enslave
+ * processing.
+ *
+ * - 2003/05/27 - Amir Noam <amir.noam at intel dot com>
+ * - Fix backward compatibility issues:
+ * For drivers not using ABI versions, slave was set down while
+ * it should be left up before enslaving.
+ * Also, master was not set down and the default set_mac_address()
+ * would fail and generate an error message in the system log.
+ * - For opt_c: slave should not be set to the master's setting
+ * while it is running. It was already set during enslave. To
+ * simplify things, it is now handeled separately.
+ */
+
+#define APP_VERSION "1.0.12"
+#define APP_RELDATE "June 30, 2003"
+#define APP_NAME "ifenslave"
+
+static char *version =
+APP_NAME ".c:v" APP_VERSION " (" APP_RELDATE ") " "\nDonald Becker (becker@cesdis.gsfc.nasa.gov).\n"
+"detach support added on 2000/10/02 by Willy Tarreau (willy at meta-x.org).\n"
+"2.4 kernel support added on 2001/02/16 by Chad N. Tindel (ctindel at ieee dot org.\n";
+
+static const char *usage_msg =
+"Usage: ifenslave [-adfrvVh] <master-interface> < <slave-if> [metric <N>] > ...\n"
+" ifenslave -c master-interface slave-if\n";
+
+static const char *howto_msg =
+"Usage: ifenslave [-adfrvVh] <master-interface> < <slave-if> [metric <N>] > ...\n"
+" ifenslave -c master-interface slave-if\n"
+"\n"
+" To create a bond device, simply follow these three steps :\n"
+" - ensure that the required drivers are properly loaded :\n"
+" # modprobe bonding ; modprobe <3c59x|eepro100|pcnet32|tulip|...>\n"
+" - assign an IP address to the bond device :\n"
+" # ifconfig bond0 <addr> netmask <mask> broadcast <bcast>\n"
+" - attach all the interfaces you need to the bond device :\n"
+" # ifenslave bond0 eth0 eth1 eth2\n"
+" If bond0 didn't have a MAC address, it will take eth0's. Then, all\n"
+" interfaces attached AFTER this assignment will get the same MAC addr.\n"
+"\n"
+" To detach a dead interface without setting the bond device down :\n"
+" # ifenslave -d bond0 eth1\n"
+"\n"
+" To set the bond device down and automatically release all the slaves :\n"
+" # ifconfig bond0 down\n"
+"\n"
+" To change active slave :\n"
+" # ifenslave -c bond0 eth0\n"
+"\n";
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/if_bonding.h>
+#include <linux/sockios.h>
+
+typedef unsigned long long u64; /* hack, so we may include kernel's ethtool.h */
+typedef __uint32_t u32; /* ditto */
+typedef __uint16_t u16; /* ditto */
+typedef __uint8_t u8; /* ditto */
+#include <linux/ethtool.h>
+
+struct option longopts[] = {
+ /* { name has_arg *flag val } */
+ {"all-interfaces", 0, 0, 'a'}, /* Show all interfaces. */
+ {"force", 0, 0, 'f'}, /* Force the operation. */
+ {"help", 0, 0, '?'}, /* Give help */
+ {"howto", 0, 0, 'h'}, /* Give some more help */
+ {"receive-slave", 0, 0, 'r'}, /* Make a receive-only slave. */
+ {"verbose", 0, 0, 'v'}, /* Report each action taken. */
+ {"version", 0, 0, 'V'}, /* Emit version information. */
+ {"detach", 0, 0, 'd'}, /* Detach a slave interface. */
+ {"change-active", 0, 0, 'c'}, /* Change the active slave. */
+ { 0, 0, 0, 0 }
+};
+
+/* Command-line flags. */
+unsigned int
+opt_a = 0, /* Show-all-interfaces flag. */
+opt_f = 0, /* Force the operation. */
+opt_r = 0, /* Set up a Rx-only slave. */
+opt_d = 0, /* detach a slave interface. */
+opt_c = 0, /* change-active-slave flag. */
+verbose = 0, /* Verbose flag. */
+opt_version = 0,
+opt_howto = 0;
+int skfd = -1; /* AF_INET socket for ioctl() calls. */
+
+static void if_print(char *ifname);
+static int get_abi_ver(char *master_ifname);
+
+int
+main(int argc, char **argv)
+{
+ struct ifreq ifr2, if_hwaddr, if_ipaddr, if_metric, if_mtu, if_dstaddr;
+ struct ifreq if_netmask, if_brdaddr, if_flags;
+ int rv, goterr = 0;
+ int c, errflag = 0;
+ sa_family_t master_family;
+ char **spp, *master_ifname, *slave_ifname;
+ int hwaddr_notset;
+ int abi_ver = 0;
+
+ while ((c = getopt_long(argc, argv, "acdfrvV?h", longopts, 0)) != EOF)
+ switch (c) {
+ case 'a': opt_a++; break;
+ case 'f': opt_f++; break;
+ case 'r': opt_r++; break;
+ case 'd': opt_d++; break;
+ case 'c': opt_c++; break;
+ case 'v': verbose++; break;
+ case 'V': opt_version++; break;
+ case 'h': opt_howto++; break;
+ case '?': errflag++;
+ }
+
+ /* option check */
+ if (opt_c)
+ if(opt_a || opt_f || opt_r || opt_d || verbose || opt_version ||
+ opt_howto || errflag ) {
+ fprintf(stderr, usage_msg);
+ return 2;
+ }
+
+ if (errflag) {
+ fprintf(stderr, usage_msg);
+ return 2;
+ }
+
+ if (opt_howto) {
+ fprintf(stderr, howto_msg);
+ return 0;
+ }
+
+ if (verbose || opt_version) {
+ printf(version);
+ if (opt_version)
+ exit(0);
+ }
+
+ /* Open a basic socket. */
+ if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
+ perror("socket");
+ exit(-1);
+ }
+
+ if (verbose)
+ fprintf(stderr, "DEBUG: argc=%d, optind=%d and argv[optind] is %s.\n",
+ argc, optind, argv[optind]);
+
+ /* No remaining args means show all interfaces. */
+ if (optind == argc) {
+ if_print((char *)NULL);
+ (void) close(skfd);
+ exit(0);
+ }
+
+ /* Copy the interface name. */
+ spp = argv + optind;
+ master_ifname = *spp++;
+ slave_ifname = *spp++;
+
+ /* Check command line. */
+ if (opt_c) {
+ char **tempp = spp;
+ if ((master_ifname == NULL)||(slave_ifname == NULL)||(*tempp++ != NULL)) {
+ fprintf(stderr, usage_msg);
+ (void) close(skfd);
+ return 2;
+ }
+ }
+
+ /* A single args means show the configuration for this interface. */
+ if (slave_ifname == NULL) {
+ if_print(master_ifname);
+ (void) close(skfd);
+ exit(0);
+ }
+
+ /* exchange abi version with bonding driver */
+ abi_ver = get_abi_ver(master_ifname);
+ if (abi_ver < 0) {
+ (void) close(skfd);
+ exit(1);
+ }
+
+ /* Get the vitals from the master interface. */
+ {
+ struct ifreq *ifra[7] = { &if_ipaddr, &if_mtu, &if_dstaddr,
+ &if_brdaddr, &if_netmask, &if_flags,
+ &if_hwaddr };
+ const char *req_name[7] = {
+ "IP address", "MTU", "destination address",
+ "broadcast address", "netmask", "status flags",
+ "hardware address" };
+ const int ioctl_req_type[7] = {
+ SIOCGIFADDR, SIOCGIFMTU, SIOCGIFDSTADDR,
+ SIOCGIFBRDADDR, SIOCGIFNETMASK, SIOCGIFFLAGS,
+ SIOCGIFHWADDR };
+ int i;
+
+ for (i = 0; i < 7; i++) {
+ strncpy(ifra[i]->ifr_name, master_ifname, IFNAMSIZ);
+ if (ioctl(skfd, ioctl_req_type[i], ifra[i]) < 0) {
+ fprintf(stderr,
+ "Something broke getting the master's %s: %s.\n",
+ req_name[i], strerror(errno));
+ }
+ }
+
+ /* check if master is up; if not then fail any operation */
+ if (!(if_flags.ifr_flags & IFF_UP)) {
+ fprintf(stderr, "Illegal operation; the specified master interface '%s' is not up.\n", master_ifname);
+ (void) close(skfd);
+ exit (1);
+ }
+
+ hwaddr_notset = 1; /* assume master's address not set yet */
+ for (i = 0; hwaddr_notset && (i < 6); i++) {
+ hwaddr_notset &= ((unsigned char *)if_hwaddr.ifr_hwaddr.sa_data)[i] == 0;
+ }
+
+ /* The family '1' is ARPHRD_ETHER for ethernet. */
+ if (if_hwaddr.ifr_hwaddr.sa_family != 1 && !opt_f) {
+ fprintf(stderr, "The specified master interface '%s' is not"
+ " ethernet-like.\n This program is designed to work"
+ " with ethernet-like network interfaces.\n"
+ " Use the '-f' option to force the operation.\n",
+ master_ifname);
+ (void) close(skfd);
+ exit (1);
+ }
+ master_family = if_hwaddr.ifr_hwaddr.sa_family;
+ if (verbose) {
+ unsigned char *hwaddr = (unsigned char *)if_hwaddr.ifr_hwaddr.sa_data;
+ printf("The current hardware address (SIOCGIFHWADDR) of %s is type %d "
+ "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", master_ifname,
+ if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1],
+ hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
+ }
+ }
+
+
+ /* do this when enslaving interfaces */
+ do {
+ if (opt_d) { /* detach a slave interface from the master */
+ strncpy(if_flags.ifr_name, master_ifname, IFNAMSIZ);
+ strncpy(if_flags.ifr_slave, slave_ifname, IFNAMSIZ);
+ if ((ioctl(skfd, SIOCBONDRELEASE, &if_flags) < 0) &&
+ (ioctl(skfd, BOND_RELEASE_OLD, &if_flags) < 0)) {
+ fprintf(stderr, "SIOCBONDRELEASE: cannot detach %s from %s. errno=%s.\n",
+ slave_ifname, master_ifname, strerror(errno));
+ }
+ else if (abi_ver < 1) {
+ /* The driver is using an old ABI, so we'll set the interface
+ * down to avoid any conflicts due to same IP/MAC
+ */
+ strncpy(ifr2.ifr_name, slave_ifname, IFNAMSIZ);
+ if (ioctl(skfd, SIOCGIFFLAGS, &ifr2) < 0) {
+ int saved_errno = errno;
+ fprintf(stderr, "SIOCGIFFLAGS on %s failed: %s\n", slave_ifname,
+ strerror(saved_errno));
+ }
+ else {
+ ifr2.ifr_flags &= ~(IFF_UP | IFF_RUNNING);
+ if (ioctl(skfd, SIOCSIFFLAGS, &ifr2) < 0) {
+ int saved_errno = errno;
+ fprintf(stderr, "Shutting down interface %s failed: %s\n",
+ slave_ifname, strerror(saved_errno));
+ }
+ }
+ }
+ } else if (opt_c) { /* change primary slave */
+ strncpy(if_flags.ifr_name, master_ifname, IFNAMSIZ);
+ strncpy(if_flags.ifr_slave, slave_ifname, IFNAMSIZ);
+ if ((ioctl(skfd, SIOCBONDCHANGEACTIVE, &if_flags) < 0) &&
+ (ioctl(skfd, BOND_CHANGE_ACTIVE_OLD, &if_flags) < 0)) {
+ fprintf(stderr, "SIOCBONDCHANGEACTIVE: %s.\n", strerror(errno));
+ }
+ } else { /* attach a slave interface to the master */
+
+ strncpy(ifr2.ifr_name, slave_ifname, IFNAMSIZ);
+ if (ioctl(skfd, SIOCGIFFLAGS, &ifr2) < 0) {
+ int saved_errno = errno;
+ fprintf(stderr, "SIOCGIFFLAGS on %s failed: %s\n", slave_ifname,
+ strerror(saved_errno));
+ (void) close(skfd);
+ return 1;
+ }
+
+ if ((ifr2.ifr_flags & IFF_SLAVE) && !opt_r) {
+ fprintf(stderr, "%s is already a slave\n", slave_ifname);
+ (void) close(skfd);
+ return 1;
+ }
+
+ /* if hwaddr_notset, assign the slave hw address to the master */
+ if (hwaddr_notset) {
+ /* assign the slave hw address to the
+ * master since it currently does not
+ * have one; otherwise, slaves may
+ * have different hw addresses in
+ * active-backup mode as seen when enslaving
+ * using "ifenslave bond0 eth0 eth1" because
+ * hwaddr_notset is set outside this loop.
+ * TODO: put this and the "else" portion in
+ * a function.
+ */
+ /* get the slaves MAC address */
+ strncpy(if_hwaddr.ifr_name, slave_ifname,
+ IFNAMSIZ);
+ rv = ioctl(skfd, SIOCGIFHWADDR, &if_hwaddr);
+ if (-1 == rv) {
+ fprintf(stderr, "Could not get MAC "
+ "address of %s: %s\n",
+ slave_ifname,
+ strerror(errno));
+ strncpy(if_hwaddr.ifr_name,
+ master_ifname, IFNAMSIZ);
+ goterr = 1;
+ }
+
+ if (!goterr) {
+ if (abi_ver < 1) {
+ /* In ABI versions older than 1, the
+ * master's set_mac routine couldn't
+ * work if it was up, because it
+ * used the default ethernet set_mac
+ * function.
+ */
+ /* bring master down */
+ if_flags.ifr_flags &= ~IFF_UP;
+ if (ioctl(skfd, SIOCSIFFLAGS,
+ &if_flags) < 0) {
+ goterr = 1;
+ fprintf(stderr,
+ "Shutting down "
+ "interface %s failed: "
+ "%s\n",
+ master_ifname,
+ strerror(errno));
+ }
+ }
+
+ strncpy(if_hwaddr.ifr_name,
+ master_ifname, IFNAMSIZ);
+ if (ioctl(skfd, SIOCSIFHWADDR,
+ &if_hwaddr) < 0) {
+ fprintf(stderr,
+ "Could not set MAC "
+ "address of %s: %s\n",
+ master_ifname,
+ strerror(errno));
+ goterr=1;
+ } else {
+ hwaddr_notset = 0;
+ }
+
+ if (abi_ver < 1) {
+ /* bring master back up */
+ if_flags.ifr_flags |= IFF_UP;
+ if (ioctl(skfd, SIOCSIFFLAGS,
+ &if_flags) < 0) {
+ fprintf(stderr,
+ "Bringing up interface "
+ "%s failed: %s\n",
+ master_ifname,
+ strerror(errno));
+ }
+ }
+ }
+ } else if (abi_ver < 1) { /* if (hwaddr_notset) */
+
+ /* The driver is using an old ABI, so we'll set the interface
+ * down and assign the master's hwaddr to it
+ */
+ if (ifr2.ifr_flags & IFF_UP) {
+ ifr2.ifr_flags &= ~IFF_UP;
+ if (ioctl(skfd, SIOCSIFFLAGS, &ifr2) < 0) {
+ int saved_errno = errno;
+ fprintf(stderr, "Shutting down interface %s failed: %s\n",
+ slave_ifname, strerror(saved_errno));
+ }
+ }
+
+ strncpy(if_hwaddr.ifr_name, slave_ifname, IFNAMSIZ);
+ if (ioctl(skfd, SIOCSIFHWADDR, &if_hwaddr) < 0) {
+ int saved_errno = errno;
+ fprintf(stderr, "SIOCSIFHWADDR on %s failed: %s\n", if_hwaddr.ifr_name,
+ strerror(saved_errno));
+ if (saved_errno == EBUSY)
+ fprintf(stderr, " The slave device %s is busy: it must be"
+ " idle before running this command.\n", slave_ifname);
+ else if (saved_errno == EOPNOTSUPP)
+ fprintf(stderr, " The slave device you specified does not support"
+ " setting the MAC address.\n Your kernel likely does not"
+ " support slave devices.\n");
+ else if (saved_errno == EINVAL)
+ fprintf(stderr, " The slave device's address type does not match"
+ " the master's address type.\n");
+ } else {
+ if (verbose) {
+ unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data;
+ printf("Slave's (%s) hardware address set to "
+ "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n", slave_ifname,
+ hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
+ }
+ }
+ }
+
+ if (*spp && !strcmp(*spp, "metric")) {
+ if (*++spp == NULL) {
+ fprintf(stderr, usage_msg);
+ (void) close(skfd);
+ exit(2);
+ }
+ if_metric.ifr_metric = atoi(*spp);
+ strncpy(if_metric.ifr_name, slave_ifname, IFNAMSIZ);
+ if (ioctl(skfd, SIOCSIFMETRIC, &if_metric) < 0) {
+ fprintf(stderr, "SIOCSIFMETRIC on %s: %s\n", slave_ifname,
+ strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ }
+
+ if (strncpy(if_ipaddr.ifr_name, slave_ifname, IFNAMSIZ) <= 0
+ || ioctl(skfd, SIOCSIFADDR, &if_ipaddr) < 0) {
+ fprintf(stderr,
+ "Something broke setting the slave's address: %s.\n",
+ strerror(errno));
+ } else {
+ if (verbose) {
+ unsigned char *ipaddr = if_ipaddr.ifr_addr.sa_data;
+ printf("Set the slave's (%s) IP address to %d.%d.%d.%d.\n",
+ slave_ifname, ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+ }
+ }
+
+ if (strncpy(if_mtu.ifr_name, slave_ifname, IFNAMSIZ) <= 0
+ || ioctl(skfd, SIOCSIFMTU, &if_mtu) < 0) {
+ fprintf(stderr, "Something broke setting the slave MTU: %s.\n",
+ strerror(errno));
+ } else {
+ if (verbose)
+ printf("Set the slave's (%s) MTU to %d.\n", slave_ifname, if_mtu.ifr_mtu);
+ }
+
+ if (strncpy(if_dstaddr.ifr_name, slave_ifname, IFNAMSIZ) <= 0
+ || ioctl(skfd, SIOCSIFDSTADDR, &if_dstaddr) < 0) {
+ fprintf(stderr, "Error setting the slave (%s) with SIOCSIFDSTADDR: %s.\n",
+ slave_ifname, strerror(errno));
+ } else {
+ if (verbose) {
+ unsigned char *ipaddr = if_dstaddr.ifr_dstaddr.sa_data;
+ printf("Set the slave's (%s) destination address to %d.%d.%d.%d.\n",
+ slave_ifname, ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+ }
+ }
+
+ if (strncpy(if_brdaddr.ifr_name, slave_ifname, IFNAMSIZ) <= 0
+ || ioctl(skfd, SIOCSIFBRDADDR, &if_brdaddr) < 0) {
+ fprintf(stderr,
+ "Something broke setting the slave (%s) broadcast address: %s.\n",
+ slave_ifname, strerror(errno));
+ } else {
+ if (verbose) {
+ unsigned char *ipaddr = if_brdaddr.ifr_broadaddr.sa_data;
+ printf("Set the slave's (%s) broadcast address to %d.%d.%d.%d.\n",
+ slave_ifname, ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+ }
+ }
+
+ if (strncpy(if_netmask.ifr_name, slave_ifname, IFNAMSIZ) <= 0
+ || ioctl(skfd, SIOCSIFNETMASK, &if_netmask) < 0) {
+ fprintf(stderr,
+ "Something broke setting the slave (%s) netmask: %s.\n",
+ slave_ifname, strerror(errno));
+ } else {
+ if (verbose) {
+ unsigned char *ipaddr = if_netmask.ifr_netmask.sa_data;
+ printf("Set the slave's (%s) netmask to %d.%d.%d.%d.\n",
+ slave_ifname, ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+ }
+ }
+
+ if (abi_ver < 1) {
+
+ /* The driver is using an old ABI, so we'll set the interface
+ * up before enslaving it
+ */
+ ifr2.ifr_flags |= IFF_UP;
+ if ((ifr2.ifr_flags &= ~(IFF_SLAVE | IFF_MASTER)) == 0
+ || strncpy(ifr2.ifr_name, slave_ifname, IFNAMSIZ) <= 0
+ || ioctl(skfd, SIOCSIFFLAGS, &ifr2) < 0) {
+ fprintf(stderr,
+ "Something broke setting the slave (%s) flags: %s.\n",
+ slave_ifname, strerror(errno));
+ } else {
+ if (verbose)
+ printf("Set the slave's (%s) flags %4.4x.\n",
+ slave_ifname, if_flags.ifr_flags);
+ }
+ } else {
+ /* the bonding module takes care of setting the slave's mac address
+ * and opening its interface
+ */
+ if (ifr2.ifr_flags & IFF_UP) { /* the interface will need to be down */
+ ifr2.ifr_flags &= ~IFF_UP;
+ if (ioctl(skfd, SIOCSIFFLAGS, &ifr2) < 0) {
+ int saved_errno = errno;
+ fprintf(stderr, "Shutting down interface %s failed: %s\n",
+ slave_ifname, strerror(saved_errno));
+ }
+ }
+ }
+
+ /* Do the real thing */
+ if (!opt_r) {
+ strncpy(if_flags.ifr_name, master_ifname, IFNAMSIZ);
+ strncpy(if_flags.ifr_slave, slave_ifname, IFNAMSIZ);
+ if ((ioctl(skfd, SIOCBONDENSLAVE, &if_flags) < 0) &&
+ (ioctl(skfd, BOND_ENSLAVE_OLD, &if_flags) < 0)) {
+ fprintf(stderr, "SIOCBONDENSLAVE: %s.\n", strerror(errno));
+ }
+ }
+ }
+ } while ( (slave_ifname = *spp++) != NULL);
+
+ /* Close the socket. */
+ (void) close(skfd);
+
+ return(goterr);
+}
+
+static short mif_flags;
+
+/* Get the inteface configuration from the kernel. */
+static int if_getconfig(char *ifname)
+{
+ struct ifreq ifr;
+ int metric, mtu; /* Parameters of the master interface. */
+ struct sockaddr dstaddr, broadaddr, netmask;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
+ return -1;
+ mif_flags = ifr.ifr_flags;
+ printf("The result of SIOCGIFFLAGS on %s is %x.\n",
+ ifname, ifr.ifr_flags);
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFADDR, &ifr) < 0)
+ return -1;
+ printf("The result of SIOCGIFADDR is %2.2x.%2.2x.%2.2x.%2.2x.\n",
+ ifr.ifr_addr.sa_data[0], ifr.ifr_addr.sa_data[1],
+ ifr.ifr_addr.sa_data[2], ifr.ifr_addr.sa_data[3]);
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
+ return -1;
+
+ {
+ /* Gotta convert from 'char' to unsigned for printf(). */
+ unsigned char *hwaddr = (unsigned char *)ifr.ifr_hwaddr.sa_data;
+ printf("The result of SIOCGIFHWADDR is type %d "
+ "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x.\n",
+ ifr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1],
+ hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
+ }
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) {
+ metric = 0;
+ } else
+ metric = ifr.ifr_metric;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
+ mtu = 0;
+ else
+ mtu = ifr.ifr_mtu;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFDSTADDR, &ifr) < 0) {
+ memset(&dstaddr, 0, sizeof(struct sockaddr));
+ } else
+ dstaddr = ifr.ifr_dstaddr;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFBRDADDR, &ifr) < 0) {
+ memset(&broadaddr, 0, sizeof(struct sockaddr));
+ } else
+ broadaddr = ifr.ifr_broadaddr;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFNETMASK, &ifr) < 0) {
+ memset(&netmask, 0, sizeof(struct sockaddr));
+ } else
+ netmask = ifr.ifr_netmask;
+
+ return(0);
+}
+
+static void if_print(char *ifname)
+{
+ char buff[1024];
+ struct ifconf ifc;
+ struct ifreq *ifr;
+ int i;
+
+ if (ifname == (char *)NULL) {
+ ifc.ifc_len = sizeof(buff);
+ ifc.ifc_buf = buff;
+ if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
+ fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
+ return;
+ }
+
+ ifr = ifc.ifc_req;
+ for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) {
+ if (if_getconfig(ifr->ifr_name) < 0) {
+ fprintf(stderr, "%s: unknown interface.\n",
+ ifr->ifr_name);
+ continue;
+ }
+
+ if (((mif_flags & IFF_UP) == 0) && !opt_a) continue;
+ /*ife_print(&ife);*/
+ }
+ } else {
+ if (if_getconfig(ifname) < 0)
+ fprintf(stderr, "%s: unknown interface.\n", ifname);
+ }
+}
+
+static int get_abi_ver(char *master_ifname)
+{
+ struct ifreq ifr;
+ struct ethtool_drvinfo info;
+ int abi_ver = 0;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+ ifr.ifr_data = (caddr_t)&info;
+
+ info.cmd = ETHTOOL_GDRVINFO;
+ strncpy(info.driver, "ifenslave", 32);
+ snprintf(info.fw_version, 32, "%d", BOND_ABI_VERSION);
+ if (ioctl(skfd, SIOCETHTOOL, &ifr) >= 0) {
+ char *endptr;
+
+ abi_ver = strtoul(info.fw_version, &endptr, 0);
+ if (*endptr) {
+ fprintf(stderr, "Error: got invalid string as an ABI "
+ "version from the bonding module\n");
+ return -1;
+ }
+ }
+
+ if (verbose) {
+ printf("ABI ver is %d\n", abi_ver);
+ }
+ return abi_ver;
+}
+
+
+
+/*
+ * Local variables:
+ * version-control: t
+ * kept-new-versions: 5
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * compile-command: "gcc -Wall -Wstrict-prototypes -O -I/usr/src/linux/include ifenslave.c -o ifenslave"
+ * End:
+ */
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