summaryrefslogtreecommitdiffstats
path: root/ship/src/arch_autoinstall
blob: baa9e2a0d5dfe6db6a4c62b2dbc8b6ba93912312 (plain)
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
159
160
161
#/bin/sh
#@strict
#@include core
#@include color
#@include network
pass=shackit
shack_printer_ip=10.42.0.135
extra_pkg="xorg vim xfce4 feh chromium zsh sudo git flashplugin alsa-oss alsa-lib alsa-utils grub-bios slim ntp tor network-manager-applet networkmanager openssh cups cups-filters"

info "writing stdout to /tmp/install.log"
exec >> /tmp/install.log
tail -f /tmp/install.log&
defer 'pkill tail'

installer_disk(){
    find /dev/disk/by-label/ -name ARCH_\* 2>/dev/null | xargs readlink
}

find_rootdisk(){
    for i in sd vd hd;do
        for j in a b;do
            dsk="/dev/$i$j"
            test "$(installer_disk)" == "$dsk" && continue
            test -e "$dsk" && echo "$dsk" && return
        done
    done
}

rootdisk=$(find_rootdisk)
test "$rootdisk" || die "cannot find your root disk"

info "Your rootdisk is $rootdisk"
sleep 3

umount /mnt/boot ||:
umount /mnt ||:
info "starting partitioning"
(printf "o\nn\np\n\n\n+256M\n\a\nn\np\n\n\n\nw\n\n") |fdisk $rootdisk
info "done partitioning"
sleep 1
info "generating filesystem on /boot"
mkfs.ext2 ${rootdisk}1
info "Done"
sleep 1
info "starting LVM magic"
vgchange -an ||:
vgremove -f pool0 ||:
pvcreate ${rootdisk}2
vgcreate -ff pool0 ${rootdisk}2
lvcreate -l 100%free -n root pool0
info "finished creating LVM"
sleep 1
info "generating filesystems on the LVM"
mkfs.ext4 /dev/mapper/pool0-root
info "finished generating filesystems"
sleep 1
info "mounting"
mount /dev/mapper/pool0-root /mnt
mkdir /mnt/boot
mount ${rootdisk}1 /mnt/boot

info "finished mounting!"
sleep 1
info "installing!"

info "Setting http proxy"
if http_head heidi.shack:3142 &>/dev/null; then
    http_proxy=heidi.shack:3142 
    info "Heidi is reachable, will use this box as proxy"
else
    http_proxy=''
    info "Will not use any proxy"
fi
info "Installing the following packages: $extra_pkg"
if [ -n "${user_pkg:-}" ] ;then
  info "User chooses additional packages: $user_pkg"
else
  info "No additional packages set by user (\$user_pkg unset)"
fi
http_proxy=${http_proxy} pacstrap /mnt base base-devel $extra_pkg ${user_pkg:-}
info "installation done"
sleep 1
info "generating configs"
genfstab -U -p /mnt > /mnt/etc/fstab

info "beginning chroot!"
arch-chroot /mnt | tee -a /tmp/install.log  << EOF

msg() { printf "\$*\n" >&2; }
info()  { msg "$green\$*$nc"; }
error() { msg "$green\$*$nc"; }

info "generating locales"
ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
echo "LANG=en_US.UTF-8"  >> /etc/locale.conf
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "shackbook$RANDOM" > /etc/hostname
sed -i 's/block/& lvm2/g' /etc/mkinitcpio.conf 
info "Done! "
mkinitcpio -p linux
info "setting root password"
printf "${pass}\n${pass}\n" | (passwd )
info "adding user"
useradd -d /home/shack -m -G audio,video,wheel -s /usr/bin/zsh shack
printf "${pass}\n${pass}\n" | (passwd shack)

info "editing sudoers"
printf "root ALL=(ALL) ALL\n%s ALL=(ALL) ALL\n" %wheel >> /etc/sudoers
info "configuring slim"
printf "default_user\tshack\nfocus_password\tyes\nauto_login\tyes\n" >> /etc/slim.conf
info "configuring .xinitrc"
printf "exec startxfce4\n" >> /home/shack/.xinitrc

for i in slim NetworkManager ntpd tor cups; do
    info "enabling \$i"
    systemctl enable \$i
done

### CUPS
mkdir -p /etc/cups
cat >>/etc/cups/printers.conf<<EOF
<Printer HP_LaserJet_5000_Series>
Info Shack Printer HP 5000
Location lounge
MakeModel HP LaserJet Series PCL 6 CUPS
DeviceURI socket://$shack_printer_ip
State Idle
StateTime 1387400063
Type 8400964
Accepting Yes
Shared No
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
</Printer>
EOF

info "installing grub"
grub-install ${rootdisk} 2>/dev/null
echo "GRUB_DISABLE_LINUX_UUID=true" >> /etc/default/grub
grub-mkconfig > /boot/grub/grub.cfg 2>/dev/null

info "installing oh-my-zsh"
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sudo -u shack sh
sed -i 's/robbyrussell/afowler/g' /home/shack/.zshrc
info "fixing chrome for incognito use"
sed -i 's/Exec=chromium/Exec=chromium --incognito/g' /usr/share/applications/chromium.desktop
exit
EOF

info "configuring tor"
torrc=/mnt/etc/tor/torrc
hidden_service_dir=/var/lib/tor/hidden_service/
#@include tor
configure_hidden_service

info "We're all done, simply reboot!"