xref: /dragonfly/share/examples/rconfig/auto.sh (revision 19fe1c42)
1#!/bin/csh
2#
3# A file like this is typically copied to /usr/local/etc/rconfig/auto.sh on
4# the rconfig server and the rconfig demon is run via 'rconfig -s -a'.  When
5# you boot the DragonFly CD you have to bring up the network, typically
6# via 'dhclient interfacename', then run 'rconfig -a' or
7# 'rconfig -a ip_of_server' if the server is not on the same LAN.
8#
9# WARNING!  THIS SCRIPT WILL COMPLETELY WIPE THE DISK!
10#
11# $DragonFly: src/share/examples/rconfig/auto.sh,v 1.2 2008/09/03 02:22:25 dillon Exp $
12
13set disk = ad0
14set slice = s1
15set xdisk = $disk$slice
16
17# Refuse to do anything if the machine wasn't booted from CD
18#
19set cdboot = 0
20foreach i ( `df / | awk '{ print $1; }'` )
21    if ( $i =~ acd* ) then
22	set cdboot = 1
23    endif
24end
25
26if ( $cdboot == 0 ) then
27    echo "Aborting auto init script, machine was not booted from CD"
28    exit 1
29endif
30
31# Wipe the disk entirely
32#
33
34echo "FDISK - ALL DATA ON THE DRIVE WILL BE LOST"
35foreach i ( 5 4 3 2 1 )
36    echo -n " $i"
37    sleep 1
38end
39
40dd if=/dev/zero of=/dev/$disk bs=32k count=16
41fdisk -IB $disk
42boot0cfg -B $disk
43boot0cfg -v $disk
44dd if=/dev/zero of=/dev/$xdisk bs=32k count=16
45
46echo "DISKLABEL"
47sleep 1
48
49disklabel -B -r -w $xdisk auto
50disklabel $xdisk > /tmp/disklabel.$xdisk
51cat >> /tmp/disklabel.$xdisk << EOF
52a: 256m * 4.2BSD
53b: 1024m * swap
54d: 256m * 4.2BSD
55e: 256m * 4.2BSD
56f: 6144m * 4.2BSD
57g: * * 4.2BSD
58EOF
59disklabel -R $xdisk /tmp/disklabel.$xdisk
60disklabel $xdisk
61
62echo "NEWFS"
63sleep 1
64
65newfs /dev/${xdisk}a
66newfs -U /dev/${xdisk}d
67newfs -U /dev/${xdisk}e
68newfs -U /dev/${xdisk}f
69newfs -U /dev/${xdisk}g
70
71echo "MOUNT"
72sleep 1
73
74mount /dev/${xdisk}a /mnt
75mkdir /mnt/var
76mkdir /mnt/tmp
77mkdir /mnt/usr
78mkdir /mnt/home
79
80mount /dev/${xdisk}d /mnt/var
81mount /dev/${xdisk}e /mnt/tmp
82mount /dev/${xdisk}f /mnt/usr
83mount /dev/${xdisk}g /mnt/home
84
85echo "CPDUP ROOT"
86cpdup / /mnt
87echo "CPDUP VAR"
88cpdup /var /mnt/var
89echo "CPDUP ETC"
90cpdup /etc.hdd /mnt/etc
91echo "CPDUP DEV"
92cpdup /dev /mnt/dev
93echo "CPDUP USR"
94cpdup /usr /mnt/usr
95
96echo "CLEANUP"
97chmod 1777 /mnt/tmp
98rm -rf /mnt/var/tmp
99ln -s /tmp /mnt/var/tmp
100
101cat >/mnt/etc/fstab << EOF
102# Example fstab based on /README.
103#
104# Device                Mountpoint      FStype  Options         Dump    Pass#
105/dev/${xdisk}a		/		ufs	rw		1	1
106/dev/${xdisk}b		none		swap	sw		0	0
107/dev/${xdisk}d		/var		ufs	rw		2	2
108/dev/${xdisk}e		/tmp		ufs	rw		2	2
109/dev/${xdisk}f		/usr		ufs	rw		2	2
110/dev/${xdisk}g		/home		ufs	rw		2	2
111proc			/proc		procfs	rw		0	0
112# example MFS remount (for a pristine MFS filesystem do not use -C)
113#swap			/mnt		mfs	rw,-C,-s=4000	0	0
114EOF
115
116cat >/mnt/etc/rc.conf << EOF
117ifconfig_em0="DHCP"
118sshd_enable="YES"
119usbd_enable="YES"
120sendmail_enable="NONE"
121dumpdev="/dev/${xdisk}b"
122EOF
123
124if ( ! -d /mnt/root/.ssh ) then
125    mkdir /mnt/root/.ssh
126endif
127cat > /mnt/root/.ssh/authorized_keys << EOF
128# put your ssh public keys here so you can ssh into the 
129# newly configured machine
130EOF
131
132# Allow public-key-only access to the root account
133#
134sed -e 's/#PermitRootLogin no/PermitRootLogin without-password/' < /mnt/etc/ssh/sshd_config > /mnt/etc/ssh/sshd_config.new
135mv -f /mnt/etc/ssh/sshd_config.new /mnt/etc/ssh/sshd_config
136
137