deploy-output.sh (1331B)
1 #!/usr/bin/env bash 2 3 set -o errexit 4 #set -o nounset 5 #set -o xtrace 6 7 # Expected inputs 8 # $1: Packer lxc output directory with rootfs and config template 9 # $2: Name of the new container 10 output="$1" 11 name="$2" 12 13 if [[ $# -eq 0 ]]; then 14 cat <<EOF 15 This script deploys templates built with the lxc builder for Packer: 16 https://www.packer.io/docs/builders/lxc.html 17 18 No arguments supplied, required args: 19 PACKER_OUTPUT_DIR: Packer lxc output directory with rootfs and config template 20 CONTAINER_NAME: Name of the new container 21 22 Usage: deploy-output.sh PACKER_OUTPUT_DIR CONTAINER_NAME 23 24 Copy lxc template from PACKER_OUTPUT_DIR to /var/lib/lxc/CONTAINER_NAME 25 EOF 26 exit 1 27 elif [[ -z "$1" ]]; then 28 echo "No packer lxc output dir specified" 29 exit 1 30 elif [[ -z "$2" ]]; then 31 echo "No packer lxc output dir specified" 32 exit 1 33 fi 34 35 36 # Prepare lxc config directory 37 target_config="/srv/lxc/$name/config" 38 mkdir -p "/srv/lxc/$name" 39 40 # Extract the rootfs tarball and add the config 41 tar -xvf "$output/rootfs.tar.gz" -C "/srv/lxc/$name" 42 43 # copy config 44 cp "$output/lxc-config" $target_config 45 46 # adjust rootfs path 47 echo -e "\nlxc.rootfs.path = dir:/srv/lxc/$name/rootfs" >> $target_config 48 49 # set hostname 50 echo "${name}.local" > "/srv/lxc/$name/rootfs/etc/hostname" 51 sed -i "s/LXC_NAME/${name}.local/g" "/srv/lxc/$name/rootfs/etc/hosts"