Merge from vendor branch BINUTILS:
[dragonfly.git] / share / examples / rconfig / auto.sh
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.1 2004/06/18 18:36:06 dillon Exp $
12
13 set disk = ad0
14 set slice = s1
15 set xdisk = $disk$slice
16
17 # Refuse to do anything if the machine wasn't booted from CD
18 #
19 set cdboot = 0
20 foreach i ( `df / | awk '{ print $1; }'` )
21     if ( $i =~ acd* ) then
22         set cdboot = 1
23     endif
24 end
25
26 if ( $cdboot == 0 ) then
27     echo "Aborting auto init script, machine was not booted from CD"
28     exit 1
29 endif
30
31 # Wipe the disk entirely
32 #
33
34 echo "FDISK - ALL DATA ON THE DRIVE WILL BE LOST"
35 foreach i ( 5 4 3 2 1 )
36     echo -n " $i"
37     sleep 1
38 end
39
40 dd if=/dev/zero of=/dev/$disk bs=32k count=16
41 fdisk -IB $disk
42 boot0cfg -B $disk
43 boot0cfg -v $disk
44 dd if=/dev/zero of=/dev/$xdisk bs=32k count=16
45
46 echo "DISKLABEL"
47 sleep 1
48
49 disklabel -B -r -w $xdisk auto
50 disklabel $xdisk > /tmp/disklabel.$xdisk
51 cat >> /tmp/disklabel.$xdisk << EOF
52 a: 256m * 4.2BSD
53 b: 1024m * swap
54 d: 256m * 4.2BSD
55 e: 256m * 4.2BSD
56 f: 6144m * 4.2BSD
57 g: * * 4.2BSD
58 EOF
59 disklabel -R $xdisk /tmp/disklabel.$xdisk
60 disklabel $xdisk
61
62 echo "NEWFS"
63 sleep 1
64
65 newfs /dev/${xdisk}a
66 newfs -U /dev/${xdisk}d
67 newfs -U /dev/${xdisk}e
68 newfs -U /dev/${xdisk}f
69 newfs -U /dev/${xdisk}g
70
71 echo "MOUNT"
72 sleep 1
73
74 mount /dev/${xdisk}a /mnt
75 mkdir /mnt/var
76 mkdir /mnt/tmp
77 mkdir /mnt/usr
78 mkdir /mnt/home
79
80 mount /dev/${xdisk}d /mnt/var
81 mount /dev/${xdisk}e /mnt/tmp
82 mount /dev/${xdisk}f /mnt/usr
83 mount /dev/${xdisk}g /mnt/home
84
85 echo "CPDUP ROOT"
86 cpdup / /mnt
87 echo "CPDUP VAR"
88 cpdup /var /mnt/var
89 echo "CPDUP ETC"
90 cpdup /etc /mnt/etc
91 echo "CPDUP DEV"
92 cpdup /dev /mnt/dev
93 echo "CPDUP USR"
94 cpdup /usr /mnt/usr
95
96 echo "CLEANUP"
97 chmod 1777 /mnt/tmp
98 rm -rf /mnt/var/tmp
99 ln -s /tmp /mnt/var/tmp
100
101 cat >/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
111 proc                    /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
114 EOF
115
116 cat >/mnt/etc/rc.conf << EOF
117 ifconfig_em0="DHCP"
118 sshd_enable="YES"
119 usbd_enable="YES"
120 sendmail_enable="NONE"
121 dumpdev="/dev/${xdisk}b"
122 EOF
123
124 if ( ! -d /mnt/root/.ssh ) then
125     mkdir /mnt/root/.ssh
126 endif
127 cat > /mnt/root/.ssh/authorized_keys << EOF
128 # put your ssh public keys here so you can ssh into the 
129 # newly configured machine
130 EOF
131
132 # Allow public-key-only access to the root account
133 #
134 sed -e 's/#PermitRootLogin no/PermitRootLogin without-password/' < /mnt/etc/ssh/sshd_config > /mnt/etc/ssh/sshd_config.new
135 mv -f /mnt/etc/ssh/sshd_config.new /mnt/etc/ssh/sshd_config
136