77 lines
1.8 KiB
Bash
Executable File
77 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -ex
|
|
|
|
add_overlayfs(){
|
|
local root_path="$1"
|
|
local rootfs="$root_path/rootfs" local path="$2"
|
|
local lower="$base_rootfs/${path}"
|
|
local upper="$root_path/.${path}-delta"
|
|
local work="$root_path/.${path}-work"
|
|
|
|
[[ -d "$rootfs" ]] || mkdir -p "$rootfs"
|
|
[[ -d "$work" ]] || mkdir -p "$work"
|
|
[[ -d "$upper" ]] || mkdir -p "$upper"
|
|
|
|
echo "none $path overlay lowerdir=$lower,upperdir=$upper,workdir=$work 0 0" >> "$root_path/fstab"
|
|
}
|
|
|
|
options=$(getopt -o n:4:6: -l name:,ipv4:,ipv6:,path:,rootfs:,mapped-uid:,mapped-gid: -- "$@")
|
|
if [ $? -ne 0 ]; then
|
|
usage $(basename $0)
|
|
exit 1
|
|
fi
|
|
|
|
eval set -- "$options"
|
|
while true
|
|
do
|
|
case "$1" in
|
|
-n|--name) name=$2; shift 2;;
|
|
-4|--ipv4) ipv4=$2; shift 2;;
|
|
-6|--ipv6) ipv6=$2; shift 2;;
|
|
--path) path=$2; shift 2;;
|
|
--rootfs) base_rootfs=$2; shift 2;;
|
|
--) shift 1; break ;;
|
|
*) break ;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "${name}" ]; then
|
|
echo "missing required 'name' parameter"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${path}" ]; then
|
|
echo "missing required 'path' parameter"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${base_rootfs}" ]; then
|
|
echo "missing required 'rootfs' parameter"
|
|
exit 1
|
|
fi
|
|
|
|
config="${path}/config"
|
|
|
|
touch "$path/fstab"
|
|
add_overlayfs "$path" "var"
|
|
add_overlayfs "$path" "etc"
|
|
add_overlayfs "$path" "home"
|
|
add_overlayfs "$path" "srv"
|
|
add_overlayfs "$path" "mnt"
|
|
add_overlayfs "$path" "root"
|
|
|
|
cat > "$config" <<EOF
|
|
lxc.include = /etc/lxc/default.conf
|
|
lxc.include = ${path}/local.conf
|
|
lxc.rootfs = ${path}/rootfs
|
|
lxc.utsname = $name
|
|
EOF
|
|
touch "$path/local.conf"
|
|
|
|
export LXC_ROOTFS_PATH="$path/rootfs"
|
|
export LXC_NAME=$name
|
|
export LXC_CONFIG_FILE="$config"
|
|
perl -n -e'/CREATE_HOOKS="([^"]+)"/ && map { system("/etc/lxc/hooks/$_") == 0 or print("executing $_ failed\n") } split(/\s+/, $1)' \
|
|
/etc/lxc/default.conf
|