This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstboot
51 lines (35 loc) · 1.37 KB
/
firstboot
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
#!/bin/sh
PXESERVER=10.0.0.1
# This script will run the first time the system boots. Even
# though we've told it to run after networking is enabled,
#
# Introducing a brief sleep makes things work right all the
# time. The time for DHCP to catch up.
sleep 60
# install our new sources
cat > /etc/apt/sources.list <<EOF
deb http://$PXESERVER:3142/debian stretch main contrib non-free
deb http://repo.saltstack.com/apt/debian/9/amd64/latest stretch main
EOF
#echo "APT::Get::AllowUnauthenticated yes;" > /etc/apt/apt.conf.d/99auth
# add salt key
wget -O - https://repo.saltstack.com/apt/debian/9/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
# update apt
/usr/bin/apt-get update
# Install the salt client
apt-get install --yes --no-install-recommends --force-yes salt-minion
sed -i -e "s|#master: salt|master: $PXESERVER|" /etc/salt/minion
# download configuration files
/usr/bin/curl -o /tmp/iplist http://$PXESERVER/iplist
# get ip and detect hostname
_ip=`ip addr list eno1 |grep 'inet ' |cut -d' ' -f6|cut -d/ -f1`
hostname=`grep $_ip /tmp/iplist | awk '{print $1}'`
rm /tmp/iplist
# set hostname
echo $hostname > /etc/hostname
echo $hostname > /etc/salt/minion_id
/etc/init.d/salt-minion restart
# Remove our firstboot service so that it won't run again
rm -f /etc/init.d/firstboot /root/firstboot /lib/systemd/system/firstboot.service
# Reboot into the new kernel
/sbin/reboot