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