-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.sh
74 lines (51 loc) · 1.52 KB
/
provision.sh
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
#!/bin/bash
# Get all flags
while getopts h:p: flag
do
case "${flag}" in
h) hostname=${OPTARG};;
p) password=${OPTARG};;
esac
done
if [ -n "$hostname" ]; then
echo "Hostname: $hostname"
else
echo "Error, no hostname provided using '-h'."
exit 0
fi
if [ -n "$password" ]; then
echo "Password: ***********"
else
echo "Error, no password provided using '-p'."
exit 0
fi
apt-get -y update
apt-get -y upgrade
apt -y install vim
echo "set nocompatible" >> ~/.vimrc
echo "Changing password"
##### Change Password #####
echo "pi:$password" | chpasswd
##### Change the hostname of the box######
currentHostname=$(cat /etc/hostname)
# Display the current hostname
echo "The current hostname is $currentHostname"
# Change the hostname
hostnamectl set-hostname $hostname
hostname $hostname
# Change hostname in /etc/hosts & /etc/hostname
sudo sed -i "s/$currentHostname/$hostname/g" /etc/hosts
sudo sed -i "s/$currentHostname/$hostname/g" /etc/hostname
# Display new hostname
echo "The new hostname is $hostname"
##set up cloud features
echo " cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory" >> /boot/cmdline.txt
##### Install Docker #####
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker pi
##### Install K3s ######
export K3S_URL="https://192.168.86.189:6443"
export K3S_TOKEN=”K10d71de45fdfcb53498841a01e636eea5d214a4c8ccc21a2d2f9d9399ff2d80d56::server:5ae70d989cdf8c193770ca93baffc9d5”
curl -sfL https://get.k3s.io | sh -
sudo reboot -h now