This repository was archived by the owner on Jan 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-hrm-lxc-container.sh
More file actions
executable file
·81 lines (68 loc) · 2.04 KB
/
create-hrm-lxc-container.sh
File metadata and controls
executable file
·81 lines (68 loc) · 2.04 KB
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
#!/bin/bash
# exit immediately on any error
set -e
usage_exit() {
echo
echo "Usage:"
echo
echo " $0 container_name distribution suite"
echo
echo " e.g.: $0 hrm35_deb8 debian 8_jessie"
echo
exit $1
}
if [ -z "$1" ] ; then
echo "ERROR: No name given for container!"
usage_exit 1
fi
VM_HOSTNAME=$1
if [ -z "$2" ] ; then
echo "ERROR: No distribution given!"
usage_exit 2
fi
DISTRIBUTION=$2
if [ -z "$3" ] ; then
echo "ERROR: No suite for distribution '$DISTRIBUTION' given!"
usage_exit 2
fi
SUITE=$3
if [ "$4" == "--dry-run" ] ; then
export DRY_RUN="true"
fi
cd $(dirname $0)
SETUP_SCRIPTS="distributions/$DISTRIBUTION/$SUITE"
if ! [ -d "$SETUP_SCRIPTS" ] ; then
echo "ERROR: can't find directory [$SETUP_SCRIPTS]!"
usage_exit 3
fi
AUTH_KEYS="${AUTH_KEYS:-$(readlink settings/authorized_keys)}"
if ! [ -r "$AUTH_KEYS" ] ; then
echo "ERROR: can't find or read authorized keys file: $AUTH_KEYS"
usage_exit 4
fi
LOCALPKGS="$(readlink settings/localpkgs)/$DISTRIBUTION/$SUITE"
if [ -n "$LOCALPKGS" ] ; then
echo LOCALPKGS=$LOCALPKGS
export LOCALPKGS
else
echo "WARNING: no 'settings/localpkgs' found, network connection required!"
fi
LXCPATH="$(readlink settings/lxcpath)"
if [ -n "$LXCPATH" ] ; then
echo LXCPATH=$LXCPATH
export LXCPATH
else
echo "WARNING: no 'settings/lxcpath' found, using LXC default!"
fi
RUN_SCRIPT="$SETUP_SCRIPTS/lxc-create-base.sh"
echo -e "----------------------------------\nLaunching [$RUN_SCRIPT]"
bash $RUN_SCRIPT $VM_HOSTNAME $AUTH_KEYS
echo -e "----------------------------------\nFinished [$RUN_SCRIPT]"
echo "----------------------------------"
echo
echo "Use the following commands to start it and/or check its status:"
echo " # lxc-start --lxcpath=$LXCPATH --name=$VM_HOSTNAME -d"
echo " # lxc-attach --lxcpath=$LXCPATH --name=$VM_HOSTNAME"
echo " # lxc-ls --lxcpath=$LXCPATH --fancy"
echo " # IPV4=$(lxc-ls --lxcpath=$LXCPATH --filter=$VM_HOSTNAME --fancy-format=IPV4 --fancy | tail -n 1)"
echo " # ssh -i ${AUTH_KEYS/.pub/} root@\$IPV4"