add new deb sources
[automated-distro-installer] / lk
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 usage() {
19 cat <<EOF
20 Usage: ${0##*/} [-h|--help] [HOST]
21 fai kexec from upstream live cds, i.e. curl|bash
22
23 If HOST argument, ssh to root@HOST before doing kexec. This does what
24 pxe would do, but skipping boot sequence up to and including the pxe
25 dhcp.
26
27
28 You can copy this to a http server, then wget -O- url|sudo bash
29 curl is sometimes not preinstalled on a live cd.
30
31 Alternative to http server:
32 1. on install machine nc -l 1234 | sudo bash
33 2. On another machine nc INSTALL_MACHINE 1234 <live-kexec
34 Obviously beware that anyone on your network could send commands to the install machine.
35
36 This has been tested on trisquel 7 & 8 & ubuntu 16.04 & 18.10. With
37 18.10 and trisquel 8 on an x200, kexec was unreliable, resulting in
38 freezes and kernel panics. On t11, linux 5.15.0-40-generic, after kexec,
39 black screen, ping worked but nothing else. Debian 11 live image worked.
40
41 If the screen just sits in a weird color inverted, corrupted looking state,
42 it's probably nothing wrong with the computer, but a problem
43 with the fai server. If you can do this from a virtual terminal,
44 it will print out more info (I know from running it on a vm).
45 EOF
46 exit $1
47 }
48 case $1 in
49 -h|--help) usage ;;
50 ?*) host=$1
51 esac
52
53 if [[ $host ]]; then
54 ssh root@$host bash -s < $(readlink -f "$BASH_SOURCE")
55 exit $?
56 fi
57
58 set -ex
59 if grep -q ID=ubuntu /etc/os-release; then
60 # add universe, pxe-kexec is there
61 sed -ri '/^\s*deb/{/universe/!s/$/ universe/}' /etc/apt/sources.list
62 fi
63 if ! type -p pxe-kexec >/dev/null 2>&1; then
64 apt-get update ||: # try even if we fail
65 apt-get install -y debconf
66 debconf-set-selections <<EOF
67 kexec-tools kexec-tools/load_kexec boolean false
68 EOF
69 apt-get install -y pxe-kexec
70 fi
71 # running this piped to bash on belenos, the apt-get goes
72 # into the background while it's still installing, and pxe-kexec
73 # just exits right away. sleep calls are strangely ignored.
74 # I don't know whats going on, but just running the same
75 # command again once it finishes works, and this is only
76 # rarely used and done manually anyways, so whatever.
77 pxe-kexec -n --ignore-whitelist -l fai-generated faiserver