-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbasic-setup.sh
executable file
·141 lines (114 loc) · 4.16 KB
/
basic-setup.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
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
#!/usr/bin/env bash
#
# SPDX-License-Identifier: MPL-2.0
#
# Copyright: © 2023-2024 Serpent OS Developers
#
# shared-setup.sh:
# script with shared utility functions for conveniently creating a
# clean serpent-os root directory directory suitable for use as the
# root in serpent os systemd-nspawn container or linux-kvm kernel driven
# qemu-kvm virtual machine.
# target dirs
# use a default sosroot
SOSROOT="${DESTDIR:-${PWD}/sosroot}"
BOULDERCACHE="${HOME}/.cache/boulder"
# utility functions
BOLD='\033[1m'
RED='\033[0;31m'
RESET='\033[0m'
YELLOW='\033[0;33m'
printInfo () {
local INFO="${BOLD}INFO${RESET}"
echo -e "${INFO} ${*}"
}
printWarning () {
local WARNING="${YELLOW}${BOLD}WARNING${RESET}"
echo -e "${WARNING} ${*}"
}
printError () {
local ERROR="${RED}${BOLD}ERROR${RESET}"
echo -e "${ERROR} ${*}"
}
die() {
printError "${*} failed, exiting.\n"
exit 1
}
checkPrereqs () {
printInfo "Checking prerequisites..."
test -f ./pkglist-base || die "\nRun this script from the root of the img-tests/ repo clone!\n"
test -x $(command -v moss) || die "\n${0} assumes moss is installed. See https://github.com/serpent-os/moss/\n"
}
# base packages
readarray -t PACKAGES < ./pkglist-base
#echo "${PACKAGES[@]}"
#die "Test of PACKAGES."
createNssswitchConf () {
cat << EOF > ./nsswitch.conf
passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
EOF
}
basicSetup () {
# NB: This will fail if moss is an alias!
local moss="$(command -v moss)"
printInfo "Using moss binary found here: ${moss} ($(${moss} version))"
MSG="Removing old ${SOSROOT} directory..."
printInfo "${MSG}"
sudo rm -rf "${SOSROOT}" || die "${MSG}"
MSG="Making sure ${BOULDERCAHCE} directory exists..."
printInfo "${MSG}"
sudo mkdir -pv "${BOULDERCACHE}"
MSG="Creating new ${SOSROOT} directory w/baselayout skeleton..."
printInfo "${MSG}"
sudo mkdir -pv "${SOSROOT}"/{etc,proc,run,sys,var,var/local,"${BOULDERCACHE}"} || die "${MSG}"
# No longer necessary -- moss triggers have been fixed to respect trigger dep order now
#MSG="Ensuring that we get a working nss-systemd-compatible nssswitch.conf..."
#printInfo "${MSG}"
#createNssswitchConf || die "${MSG}"
#sudo cp -v ./nsswitch.conf "${SOSROOT}"/etc/ || die "${MSG}"
MSG="Ensuring that various network protocols function..."
printInfo "${MSG}"
sudo cp -va /etc/protocols "${SOSROOT}"/etc/ || die "${MSG}"
MSG="Adding volatile serpent os repository..."
printInfo "${MSG}"
sudo ${moss} -D "${SOSROOT}" -y repo add volatile https://packages.serpentos.com/volatile/x86_64/stone.index -p0 || die "${MSG}"
MSG="Installing packages..."
printInfo "${MSG}"
sudo ${moss} -D "${SOSROOT}" -y --cache "${BOULDERCACHE}" install "${PACKAGES[@]}" || die "${MSG}"
MSG="Setting up an empty root password by default..."
printInfo "${MSG}"
sudo chroot "${SOSROOT}" /usr/bin/passwd -d root
sudo rm -vf issue
test -f "${SOSROOT}"/etc/issue && cp -v "${SOSROOT}"/etc/issue issue
echo -e "By default, the root user has no password.\n\nUse the passwd command to change it.\n" >> issue
sudo mv -v issue "${SOSROOT}"/etc/issue
MSG="Preparing local-x86_64 profile directory..."
printInfo "${MSG}"
sudo mkdir -pv "${SOSROOT}/${BOULDERCACHE}/repos/local-x86_64/" || die "${MSG}"
MSG="Creating a moss stone.index file for the local-x86_64 profile..."
printInfo "${MSG}"
sudo ${moss} -y index "${SOSROOT}/${BOULDERCACHE}/repos/local-x86_64/" || die "${MSG}"
MSG="Adding local-x86_64 profile to list of active repositories..."
printInfo "${MSG}"
sudo chroot "${SOSROOT}" moss -y repo add local-x86_64 "file://${BOULDERCACHE}/repos/local-x86_64/stone.index" -p10 || die "${MSG}"
}
# clean up env
cleanEnv () {
unset BOULDERCACHE
unset MSG
unset PACKAGES
unset SOSROOT
unset BOLD
unset RED
unset RESET
unset YELLOW
}