summaryrefslogtreecommitdiffstats
path: root/packager/openslx
blob: 6a75fc47dba7184f859614b16614838fd114743c (plain) (blame)
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
#!/bin/bash
# ------------------------------------------------------------------------------
#
#                        OpenSLX Toolkit Next Gen
#
# ------------------------------------------------------------------------------
#
# The next generation toolkit to build a stateless linux system bootable
# over the network. Composed of dracut-built initramfs and a full system clone.
#
# ------------------------------------------------------------------------------
#
#                           OpenSLX-NG Functions
#
# ------------------------------------------------------------------------------
pinfo() {
	echo -e "\033[38;5;10m[info]\033[0m $@"
}

perror() {
	echo -e "\033[38;5;9m[error]\033[0m $@"
	kill "$SELF_PID"
	exit 1
}

print_usage() {
	perror "$ARG0 <remote_ip> <stage4_sync_dir> <target_qcow2_container>"
}

# ------------------------------------------------------------------------------
#
#                           OpenSLX-NG Main Code
#
# ------------------------------------------------------------------------------

declare -rg ARG0="$0"
declare -rg SELF="$(readlink -f "$ARG0")"
declare -rg ROOT_DIR="$(dirname "${SELF}")"
declare -rg SELF_PID="$$"

# root check
if [ "$(id -u)" -ne 0 ]; then
	perror "ERROR: You need to be root to use this toolkit."
else
	pinfo ""
fi

# do we even have tools?
for TOOL in qemu-img qemu-nbd mkfs.ext4; do
	which $TOOL &>/dev/null || perror "Could not find '$TOOL'."
done

# let's keep it simple for now, just source our main functions file
. "${ROOT_DIR}/$ARG0".functions || perror "Could not source functions."

# ok, now check that we have 3 args
[ $# -ne 3 ] && print_usage

# even though functions check their parameter, we also do it to be safe.
valid_ip "$1" || perror "'$1' is not a valid IP adress, aborting..."
[ ! -d "$2" ] || perror "'$2' already exists, aborting..."
[ ! -f "$3" ] || perror "'$3' already exists, aborting..."

# all good, let's start
pinfo " ## RUNNING ##"
clone_stage4 $1 $2 || perror "Failed to clone stage4 with: $1 $2"
export_qcow2 $2 $3 || perror "Failed to export stage4 with: $2 $3"
pinfo " ## COMPLETE ##"