-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinstall.sh.dfly
158 lines (132 loc) · 4.13 KB
/
install.sh.dfly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/sh -x
#
# This will format a new machine with a BOOT+HAMMER setup and install
# the live CD. You would boot the live CD, dhclient your network up,
# then run 'rconfig :hammer', assuming you have a rconfig server on the
# LAN. Alternately fetch the script from a known location and just run it.
#
# ad6s1a will be setup as a small UFS /boot. ad6s1d will be setup as
# HAMMER with all remaining disk space. Pseudo file-systems will be
# created for /var, /usr, etc (giving them separate inode spaces and
# backup domains).
#
# WARNING: HAMMER filesystems (and pseudo-filesystems) must be
# occassionally pruned and reblocked. 'man hammer' for more information.
disk=$1
hostname=$2
username=$3
passwd=$4
fullname="$5"
# Format and label the disk.
#
# 'a' small UFS boot
# 'd' HAMMER filesystem
#
# Use PFSs for backup domain separation
#
dd if=/dev/zero of=/dev/${disk} bs=32k count=16
fdisk -IB ${disk}
disklabel64 -r -w ${disk}s1 auto
disklabel64 -B ${disk}s1
disklabel64 ${disk}s1 > /tmp/label
cat >> /tmp/label << EOF
a: 768m 0 4.2BSD
b: 2g * swap
d: * * HAMMER
EOF
disklabel64 -R ${disk}s1 /tmp/label
# Create file systems
newfs /dev/${disk}s1a
newfs_hammer -f -L ROOT /dev/${disk}s1d
# Mount it
mount_hammer /dev/${disk}s1d /mnt
mkdir /mnt/boot
mount /dev/${disk}s1a /mnt/boot
# Create PFS mount points for nullfs.
#
# Do the mounts manually so we can install the system, setup
# the fstab later on.
mkdir /mnt/pfs
hammer pfs-master /mnt/pfs/usr
hammer pfs-master /mnt/pfs/usr.obj
hammer pfs-master /mnt/pfs/var
hammer pfs-master /mnt/pfs/var.crash
hammer pfs-master /mnt/pfs/var.tmp
hammer pfs-master /mnt/pfs/tmp
hammer pfs-master /mnt/pfs/home
mkdir /mnt/usr
mkdir /mnt/var
mkdir /mnt/tmp
mkdir /mnt/home
mount_null /mnt/pfs/usr /mnt/usr
mount_null /mnt/pfs/var /mnt/var
mount_null /mnt/pfs/tmp /mnt/tmp
mount_null /mnt/pfs/home /mnt/home
mkdir /mnt/usr/obj
mkdir /mnt/var/tmp
mkdir /mnt/var/crash
mount_null /mnt/pfs/var.tmp /mnt/var/tmp
mount_null /mnt/pfs/var.crash /mnt/var/crash
mount_null /mnt/pfs/usr.obj /mnt/usr/obj
chmod 1777 /mnt/tmp
chmod 1777 /mnt/var/tmp
# Install the system from the live CD
cpdup -o / /mnt
cpdup -o /boot /mnt/boot
cpdup -o /usr /mnt/usr
cpdup -o /usr/local/etc /mnt/usr/local/etc
cpdup -o /var /mnt/var
cpdup -i0 /etc.hdd /mnt/etc
chflags -R nohistory /mnt/tmp
chflags -R nohistory /mnt/var/tmp
chflags -R nohistory /mnt/var/crash
chflags -R nohistory /mnt/usr/obj
cat > /mnt/etc/fstab << EOF
# Device Mountpoint FStype Options Dump Pass#
/dev/${disk}s1d / hammer rw 1 1
/dev/${disk}s1a /boot ufs rw 1 1
/dev/${disk}s1b none swap sw 0 0
/pfs/usr /usr null rw 0 0
/pfs/var /var null rw 0 0
/pfs/tmp /tmp null rw 0 0
/pfs/home /home null rw 0 0
/pfs/var.tmp /var/tmp null rw 0 0
/pfs/usr.obj /usr/obj null rw 0 0
/pfs/var.crash /var/crash null rw 0 0
proc /proc procfs rw 0 0
EOF
# Because root is not on the boot partition we have to tell the loader
# to tell the kernel where root is.
cat > /mnt/boot/loader.conf << EOF
kernel_options=""
autoboot_delay="1"
vfs.root.mountfrom="hammer:${disk}s1d"
EOF
# Setup interface, configuration, sshd
ifc=$(route -n get default | fgrep interface | awk '{ print $2; }')
cat > /mnt/etc/rc.conf << EOF
ifconfig_${ifc}="DHCP"
sshd_enable="YES"
dntpd_enable="YES"
hostname="${hostname}"
dumpdev="/dev/${disk}s1b"
EOF
# Set up user accounts
echo "$passwd" | pw -V /mnt/etc useradd $username -h 0 -s /bin/sh -G wheel -d /home/$username -c "$fullname";
echo "$passwd" | pw -V /mnt/etc usermod root -h 0;
mkdir -p /mnt/home/$username;
chown 1001:1001 /mnt/home/$username;
#sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/' /mnt/etc/ssh/sshd_config;
sed -i -e 's/PasswordAuthentication.*/PasswordAuthentication yes/' /mnt/etc/ssh/sshd_config;
# Cleanup of files from the LiveISO
rm -R /mnt/README* /mnt/autorun* /mnt/index.html /mnt/dflybsd.ico /mnt/etc.hdd;
rm /mnt/boot.catalog;
# Enable name resoultion in chroot /mnt
cp /etc/resolv.conf /mnt/etc;
# Setup pkg
chroot /mnt pkg update;
# Setup sudo
chroot /mnt pkg install -y sudo;
sed -i -e 's/.*%wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/' /mnt/usr/local/etc/sudoers;
# reboot
reboot