Commit 637ebe18 authored by Mike Hibler's avatar Mike Hibler

Get the assorted versions of slicefix in sync.

All now include the localization code that Leigh added.
parent aec49251
......@@ -13,6 +13,16 @@ else
ETCDIR=/etc/emulab
fi
# XXX should fix paths.sh but I am afraid of the consequences
if [ -d "/etc/emulab" -a "$ETCDIR" = "/etc/testbed" ]; then
ETCDIR=/etc/emulab
for f in isvgaonly isflash bossnode emulab.pem client.pem; do
if [ -e "/etc/testbed/$f" -a ! -e "/etc/emulab/$f" ]; then
mv /etc/testbed/$f /etc/emulab/$f
fi
done
fi
disk="ad0"
case $# in
......@@ -162,6 +172,7 @@ dofreebsd() {
echo "fixing FreeBSD root partition ${disk}s${part}a"
fsck -p $rootdev || {
# 8.x fsck fails to determine the FS type, try again with ufs
echo "retrying fsck with '-t ufs'"
fsck -t ufs -p $rootdev || {
echo "Fsck of $rootdev failed"
return 1
......@@ -306,11 +317,14 @@ dofreebsd() {
fi
fi
#
# Localize the image. We only do this if the MFS we are running in
# has the necessary files.
#
if islocalized; then
# Check the certs.
if [ -e $ETCDIR/emulab.pem ]; then
cmp -s $ETCDIR/emulab.pem /mnt/etc/emulab/emulab.pem
if [ $? -ne 0 ]; then
changecerts=1
fixit=1
......@@ -318,14 +332,13 @@ dofreebsd() {
fi
if [ -e $ETCDIR/client.pem ]; then
cmp -s $ETCDIR/client.pem /mnt/etc/emulab/client.pem
if [ $? -ne 0 ]; then
changecerts=1
fixit=1
fi
fi
# Check the root keys
# Check the root keys.
if [ -e /root/.ssh/authorized_keys2 ]; then
cmp -s /root/.ssh/authorized_keys2 /mnt/root/.ssh/authorized_keys
if [ $? -ne 0 ]; then
......@@ -335,21 +348,21 @@ dofreebsd() {
fi
# Check the host keys.
if [ -e /etc/ssh/ssh_host_key -a -d /mnt/etc/ssh ]; then
if [ -e /etc/ssh/ssh_host_key ]; then
cmp -s /etc/ssh/ssh_host_key /mnt/etc/ssh/ssh_host_key
if [ $? -ne 0 ]; then
changehostkeys=1
fixit=1
fi
fi
if [ -e /etc/ssh/ssh_host_rsa_key -a -d /mnt/etc/ssh ]; then
if [ -e /etc/ssh/ssh_host_rsa_key ]; then
cmp -s /etc/ssh/ssh_host_rsa_key /mnt/etc/ssh/ssh_host_rsa_key
if [ $? -ne 0 ]; then
changehostkeys=1
fixit=1
fi
fi
if [ -e /etc/ssh/ssh_host_dsa_key -a -d /mnt/etc/ssh ]; then
if [ -e /etc/ssh/ssh_host_dsa_key ]; then
cmp -s /etc/ssh/ssh_host_dsa_key /mnt/etc/ssh/ssh_host_dsa_key
if [ $? -ne 0 ]; then
changehostkeys=1
......@@ -513,7 +526,7 @@ EOF1
return 1
}
fi
cp -p $ETCDIR/emulab.pem $ETCDIR/client.pem /mnt/etc/emulab || {
cp -p $ETCDIR/emulab.pem $ETCDIR/client.pem /mnt/etc/emulab/ || {
echo "Failed to create $ETCDIR/emulab.pem or $ETCDIR/client.pem"
umount $rootdev
return 1
......@@ -522,7 +535,7 @@ EOF1
# Copy in new root keys
if [ $changerootkeys -eq 1 ]; then
echo " updating /root/.ssh/authorized_keys2"
echo " updating /root/.ssh/authorized_keys"
if [ ! -d /mnt/root/.ssh ]; then
mkdir -m 700 /mnt/root/.ssh || {
......@@ -531,7 +544,13 @@ EOF1
return 1
}
fi
cp -p /root/.ssh/authorized_keys2 /mnt/root/.ssh || {
# copy to both authorized_keys and _keys2
cp -p /root/.ssh/authorized_keys2 /mnt/root/.ssh/authorized_keys || {
echo "Failed to create /root/.ssh/authorized_keys"
umount $rootdev
return 1
}
cp -p /root/.ssh/authorized_keys2 /mnt/root/.ssh/ || {
echo "Failed to create /root/.ssh/authorized_keys2"
umount $rootdev
return 1
......@@ -549,7 +568,7 @@ EOF1
return 1
}
fi
cp -p /etc/ssh/ssh_host_* /mnt/etc/ssh || {
cp -p /etc/ssh/ssh_host_* /mnt/etc/ssh/ || {
echo "Failed to create /etc/ssh/hostkeys"
umount $rootdev
return 1
......@@ -810,8 +829,12 @@ dolinux() {
dd if=/dev/urandom of=/mnt/var/lib/random-seed bs=512 count=1 >/dev/null 2>&1
fi
# Check the certs.
#
# Localize the image. We only do this if the MFS we are running in
# has the necessary files.
#
if islocalized; then
# Check the certs.
if [ ! -d /mnt/etc/emulab ]; then
mkdir -m 755 /mnt/etc/emulab || {
echo "Failed to mkdir /mnt/etc/emulab"
......@@ -821,10 +844,9 @@ dolinux() {
fi
if [ -e $ETCDIR/emulab.pem ]; then
cmp -s $ETCDIR/emulab.pem /mnt/etc/emulab/emulab.pem
if [ $? -ne 0 ]; then
echo " updating /mnt/etc/emulab/emulab.pem"
cp -p $ETCDIR/emulab.pem /mnt/etc/emulab || {
cp -p $ETCDIR/emulab.pem /mnt/etc/emulab/ || {
echo "Failed to create $ETCDIR/emulab.pem"
umount $rootdev
return 1
......@@ -833,10 +855,9 @@ dolinux() {
fi
if [ -e $ETCDIR/client.pem ]; then
cmp -s $ETCDIR/client.pem /mnt/etc/emulab/client.pem
if [ $? -ne 0 ]; then
echo " updating /mnt/etc/emulab/client.pem"
cp -p $ETCDIR/client.pem /mnt/etc/emulab || {
cp -p $ETCDIR/client.pem /mnt/etc/emulab/ || {
echo "Failed to create $ETCDIR/client.pem"
umount $rootdev
return 1
......@@ -844,11 +865,11 @@ dolinux() {
fi
fi
# Check the root keys
# Check the root keys.
if [ -e /root/.ssh/authorized_keys2 ]; then
cmp -s /root/.ssh/authorized_keys2 /mnt/root/.ssh/authorized_keys
if [ $? -ne 0 ]; then
echo " updating /root/.ssh/authorized_keys2"
echo " updating /root/.ssh/authorized_keys"
if [ ! -d /mnt/root/.ssh ]; then
mkdir -m 700 /mnt/root/.ssh || {
......@@ -857,7 +878,13 @@ dolinux() {
return 1
}
fi
cp -p /root/.ssh/authorized_keys2 /mnt/root/.ssh || {
# copy to both authorized_keys and _keys2
cp -p /root/.ssh/authorized_keys2 /mnt/root/.ssh/authorized_keys || {
echo "Failed to create /root/.ssh/authorized_keys"
umount $rootdev
return 1
}
cp -p /root/.ssh/authorized_keys2 /mnt/root/.ssh/ || {
echo "Failed to create /root/.ssh/authorized_keys2"
umount $rootdev
return 1
......@@ -865,21 +892,21 @@ dolinux() {
fi
fi
changehostkeys=0
# Check the host keys.
if [ -e /etc/ssh/ssh_host_key -a -d /mnt/etc/ssh ]; then
changehostkeys=0
if [ -e /etc/ssh/ssh_host_key ]; then
cmp -s /etc/ssh/ssh_host_key /mnt/etc/ssh/ssh_host_key
if [ $? -ne 0 ]; then
changehostkeys=1
fi
fi
if [ -e /etc/ssh/ssh_host_rsa_key -a -d /mnt/etc/ssh ]; then
if [ -e /etc/ssh/ssh_host_rsa_key ]; then
cmp -s /etc/ssh/ssh_host_rsa_key /mnt/etc/ssh/ssh_host_rsa_key
if [ $? -ne 0 ]; then
changehostkeys=1
fi
fi
if [ -e /etc/ssh/ssh_host_dsa_key -a -d /mnt/etc/ssh ]; then
if [ -e /etc/ssh/ssh_host_dsa_key ]; then
cmp -s /etc/ssh/ssh_host_dsa_key /mnt/etc/ssh/ssh_host_dsa_key
if [ $? -ne 0 ]; then
changehostkeys=1
......@@ -895,7 +922,7 @@ dolinux() {
return 1
}
fi
cp -p /etc/ssh/ssh_host_* /mnt/etc/ssh || {
cp -p /etc/ssh/ssh_host_* /mnt/etc/ssh/ || {
echo "Failed to create /etc/ssh/hostkeys"
umount $rootdev
return 1
......
......@@ -363,6 +363,133 @@ if [ -f $imageroot/var/lib/random-seed -a -c /dev/urandom ]; then
dd if=/dev/urandom of=$imageroot/var/lib/random-seed bs=512 count=1 >/dev/null 2>&1
fi
# Indicates the MFS has been properly localized and we can copy stuff
# into the image.
LOCALIZED="/.localized"
islocalized()
{
if [ -e $LOCALIZED ]; then
return 0;
fi
return 1;
}
#
# Localize the image. We only do this if the MFS we are running in
# has the necessary files.
#
if islocalized; then
# Check the certs.
if [ ! -d $imageroot/etc/emulab ]; then
mkdir -m 755 $imageroot/etc/emulab || {
echo "Failed to mkdir $imageroot/etc/emulab"
umount $rootdev
return 1
}
fi
if [ -e $ETCDIR/emulab.pem ]; then
cmp -s $ETCDIR/emulab.pem $imageroot/etc/emulab/emulab.pem
if [ $? -ne 0 ]; then
echo " updating $imageroot/etc/emulab/emulab.pem"
cp -p $ETCDIR/emulab.pem $imageroot/etc/emulab/ || {
echo "Failed to create $ETCDIR/emulab.pem"
umount $rootdev
return 1
}
fi
fi
if [ -e $ETCDIR/client.pem ]; then
cmp -s $ETCDIR/client.pem $imageroot/etc/emulab/client.pem
if [ $? -ne 0 ]; then
echo " updating $imageroot/etc/emulab/client.pem"
cp -p $ETCDIR/client.pem $imageroot/etc/emulab/ || {
echo "Failed to create $ETCDIR/client.pem"
umount $rootdev
return 1
}
fi
fi
# Check the root keys
if [ -e /root/.ssh/authorized_keys2 ]; then
cmp -s /root/.ssh/authorized_keys2 $imageroot/root/.ssh/authorized_keys
if [ $? -ne 0 ]; then
echo " updating /root/.ssh/authorized_keys"
if [ ! -d $imageroot/root/.ssh ]; then
mkdir -m 700 $imageroot/root/.ssh || {
echo "Failed to mkdir /root/.ssh"
umount $rootdev
return 1
}
fi
# copy to both authorized_keys and _keys2
cp -p /root/.ssh/authorized_keys2 $imageroot/root/.ssh/authorized_keys || {
echo "Failed to create /root/.ssh/authorized_keys"
umount $rootdev
return 1
}
cp -p /root/.ssh/authorized_keys2 $imageroot/root/.ssh/ || {
echo "Failed to create /root/.ssh/authorized_keys2"
umount $rootdev
return 1
}
fi
fi
# Check the host keys.
changehostkeys=0
if [ -e /etc/ssh/ssh_host_key ]; then
cmp -s /etc/ssh/ssh_host_key $imageroot/etc/ssh/ssh_host_key
if [ $? -ne 0 ]; then
changehostkeys=1
fi
fi
if [ -e /etc/ssh/ssh_host_rsa_key ]; then
cmp -s /etc/ssh/ssh_host_rsa_key $imageroot/etc/ssh/ssh_host_rsa_key
if [ $? -ne 0 ]; then
changehostkeys=1
fi
fi
if [ -e /etc/ssh/ssh_host_dsa_key ]; then
cmp -s /etc/ssh/ssh_host_dsa_key $imageroot/etc/ssh/ssh_host_dsa_key
if [ $? -ne 0 ]; then
changehostkeys=1
fi
fi
if [ $changehostkeys -eq 1 ]; then
echo " updating /etc/ssh/hostkeys"
if [ ! -d $imageroot/etc/ssh ]; then
mkdir -m 755 $imageroot/etc/ssh || {
echo "Failed to mkdir $imageroot/etc/ssh"
umount $rootdev
return 1
}
fi
cp -p /etc/ssh/ssh_host_* $imageroot/etc/ssh/ || {
echo "Failed to create /etc/ssh/hostkeys"
umount $rootdev
return 1
}
fi
# Check the time zone.
if [ -e /etc/localtime ]; then
cmp -s /etc/localtime $imageroot/etc/localtime
if [ $? -ne 0 ]; then
echo " updating /etc/localtime"
cp -p /etc/localtime $imageroot/etc/localtime || {
echo "Failed to create /etc/localtime"
umount $rootdev
return 1
}
fi
fi
fi
# hardwire the boss node
if [ $setboss -eq 1 -a -d $imageroot/etc/emulab ]; then
echo "Hardwiring boss to $bossnode"
......
......@@ -13,6 +13,7 @@ my $MKSWAP = '/sbin/mkswap';
my $UUIDGEN = 'uuidgen';
my $LOSETUP = 'losetup';
my $TUNE2FS = 'tune2fs';
my $LOCALIZED = '/.localized';
use constant GZHDR1 => 0x1f8b0800;
use constant GZHDR2 => 0x1f8b0808;
......@@ -793,6 +794,124 @@ sub update_random_seed
close SEED;
}
#
# Localize the image. We only do this if the MFS we are running in
# has the necessary files.
#
sub localize
{
my ($imageroot) = @_;
if (! -e "$LOCALIZED") {
return;
}
# Check the certs.
if (! -d "$imageroot/etc/emulab") {
if (!mkdir("$imageroot/etc/emulab", 0755)) {
print STDERR "Failed to mkdir $imageroot/etc/emulab\n";
return;
}
}
if (-e "$ETCDIR/emulab.pem") {
system("cmp -s $ETCDIR/emulab.pem $imageroot/etc/emulab/emulab.pem >/dev/null 2>&1");
if ($?) {
print "Updating $imageroot/etc/emulab/emulab.pem\n";
system("cp -p $ETCDIR/emulab.pem $imageroot/etc/emulab/");
if ($?) {
print STDERR "Failed to create $ETCDIR/emulab.pem\n";
return;
}
}
}
if (-e "$ETCDIR/client.pem") {
system("cmp -s $ETCDIR/client.pem $imageroot/etc/emulab/client.pem >/dev/null 2>&1");
if ($?) {
print "Updating $imageroot/etc/emulab/client.pem\n";
system("cp -p $ETCDIR/client.pem $imageroot/etc/emulab/");
if ($?) {
print STDERR "Failed to create $ETCDIR/client.pem\n";
return;
}
}
}
# Check the root keys
if (-e "/root/.ssh/authorized_keys2") {
system("cmp -s /root/.ssh/authorized_keys2 $imageroot/root/.ssh/authorized_keys >/dev/null 2>&1");
if ($?) {
print "Updating /root/.ssh/authorized_keys\n";
if (! -d "$imageroot/root/.ssh") {
if (!mkdir("$imageroot/root/.ssh", 0700)) {
print STDERR "Failed to mkdir /root/.ssh\n";
return;
}
}
# copy to both authorized_keys and _keys2
system("cp -p /root/.ssh/authorized_keys2 $imageroot/root/.ssh/authorized_keys");
if ($?) {
print STDERR "Failed to create /root/.ssh/authorized_keys\n";
return;
}
system("cp -p /root/.ssh/authorized_keys2 $imageroot/root/.ssh/");
if ($?) {
print STDERR "Failed to create /root/.ssh/authorized_keys2\n";
return;
}
}
}
# Check the host keys.
my $changehostkeys = 0;
if (-e "/etc/ssh/ssh_host_key") {
system("cmp -s /etc/ssh/ssh_host_key $imageroot/etc/ssh/ssh_host_key >/dev/null 2>&1");
if ($?) {
$changehostkeys = 1;
}
}
if (-e "/etc/ssh/ssh_host_rsa_key") {
system("cmp -s /etc/ssh/ssh_host_rsa_key $imageroot/etc/ssh/ssh_host_rsa_key >/dev/null 2>&1");
if ($?) {
$changehostkeys = 1;
}
}
if (-e "/etc/ssh/ssh_host_dsa_key") {
system("cmp -s /etc/ssh/ssh_host_dsa_key $imageroot/etc/ssh/ssh_host_dsa_key >/dev/null 2>&1");
if ($?) {
$changehostkeys = 1;
}
}
if ($changehostkeys) {
print "Updating /etc/ssh/hostkeys\n";
if (! -d "$imageroot/etc/ssh") {
if (!mkdir("$imageroot/etc/ssh", 0755)) {
print STDERR "Failed to mkdir $imageroot/etc/ssh\n";
return;
}
}
system("cp -p /etc/ssh/ssh_host_* $imageroot/etc/ssh/");
if ($?) {
print STDERR "Failed to create /etc/ssh/hostkeys\n";
return;
}
}
# Check the time zone.
if (-e "/etc/localtime") {
system("cmp -s /etc/localtime $imageroot/etc/localtime >/dev/null 2>&1");
if ($?) {
print "Updating /etc/localtime\n";
system("cp -p /etc/localtime $imageroot/etc/localtime");
if ($?) {
print STDERR "Failed to create /etc/localtime\n";
return;
}
}
}
}
sub hardwire_boss_node
{
my ($imageroot) = @_;
......@@ -972,6 +1091,7 @@ sub main
$kernel_has_ide ? $old_root : undef );
update_random_seed($imageroot);
localize($imageroot);
hardwire_boss_node($imageroot);
# Run any postconfig scripts
......
#!/bin/sh
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -13,9 +13,22 @@ else
ETCDIR=/etc/emulab
fi
freebsd_disk="ad0"
OS=`uname -s`
if [ $OS = FreeBSD ]; then
# XXX should fix paths.sh but I am afraid of the consequences
if [ -d "/etc/emulab" -a "$ETCDIR" = "/etc/testbed" ]; then
ETCDIR=/etc/emulab
for f in isvgaonly isflash bossnode emulab.pem client.pem; do
if [ -e "/etc/testbed/$f" -a ! -e "/etc/emulab/$f" ]; then
mv /etc/testbed/$f /etc/emulab/$f
fi
done
fi
fi
freebsd_disk="ad0"
case $# in
1)
part=$1
......@@ -81,6 +94,24 @@ case $NOCLFLUSH in
;;
esac
VGAONLY=${SLICEFIX_VGAONLY:-'unknown'}
case $VGAONLY in
0|no|NO)
VGAONLY=no
;;
1|yes|YES)
VGAONLY=yes
;;
*)
# XXX check the MFS filesystem
if [ -r $ETCDIR/isvgaonly ]; then
VGAONLY=yes
else
VGAONLY=unknown
fi
;;
esac
#
# ...or the filesystem
#
......@@ -97,6 +128,17 @@ else
setboss=0
fi
# Indicates the MFS has been properly localized and we can copy stuff
# into the image.
LOCALIZED="/.localized"
islocalized() {
if [ -e $LOCALIZED ]; then
return 0;
fi
return 1;
}
dofreebsd() {
#
# ARGH! FreeBSD 5, which primarily uses UFS2, internally converts
......@@ -144,8 +186,12 @@ dofreebsd() {
rootdev=/dev/${disk}s${part}a
echo "fixing FreeBSD root partition ${disk}s${part}a"
fsck -p $rootdev || {
echo "Fsck of $rootdev failed"
return 1
# 8.x fsck fails to determine the FS type, try again with ufs
echo "retrying fsck with '-t ufs'"
fsck -t ufs -p $rootdev || {
echo "Fsck of $rootdev failed"
return 1
}
}
fstype=ufs
......@@ -177,6 +223,12 @@ dofreebsd() {
changeentropy=0
changeacpi=0
changeasf=0
changeclflush=0
changecons=0
changecerts=0
changehostkeys=0
changerootkeys=0
changezone=0
fixit=0
......@@ -273,6 +325,21 @@ dofreebsd() {
fixit=1
fi
#
# If node doesn't have a serial port, make sure comconsole is not set!
#
if [ $VGAONLY = "yes" ]; then
grep "^console=\"comconsole\"" /mnt/boot/loader.conf >/dev/null 2>&1
case $? in
0)
changecons=1
fixit=1
;;
*)
;;
esac
fi
# check to see if we need to download any postconfig scripts:
doosconfig=0
if [ -x $BINDIR/osconfig ]; then
......@@ -283,6 +350,69 @@ dofreebsd() {
fi
fi
#
# Localize the image. We only do this if the MFS we are running in
# has the necessary files.
#
if islocalized; then
# Check the certs.
if [ -e $ETCDIR/emulab.pem ]; then
cmp -s $ETCDIR/emulab.pem /mnt/etc/emulab/emulab.pem
if [ $? -ne 0 ]; then
changecerts=1
fixit=1
fi
fi
if [ -e $ETCDIR/client.pem ]; then
cmp -s $ETCDIR/client.pem /mnt/etc/emulab/client.pem
if [ $? -ne 0 ]; then
changecerts=1
fixit=1
fi
fi
# Check the root keys
if [ -e /root/.ssh/authorized_keys2 ]; then
cmp -s /root/.ssh/authorized_keys2 /mnt/root/.ssh/authorized_keys
if [ $? -ne 0 ]; then
changerootkeys=1
fixit=1
fi
fi
# Check the host keys
if [ -e /etc/ssh/ssh_host_key ]; then
cmp -s /etc/ssh/ssh_host_key /mnt/etc/ssh/ssh_host_key
if [ $? -ne 0 ]; then
changehostkeys=1
fixit=1