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