Skip to content

Commit

Permalink
ifcfg template
Browse files Browse the repository at this point in the history
  • Loading branch information
KathrynMorgan committed Apr 6, 2018
1 parent a0b869f commit ec84518
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ifcfg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Write network interface .cfg file & push to target lxd interfaces.d
# Usage:
# [command] [container_name] [interface_name] [subnet_mask]

# Read Arguments from CMD Line
container_NAME="$1"
ip_IFACE="$2"
ip_ADDR="$3"
ip_MASK="$4"

# Set Temp, Destination, & Template Files
tmp_FILE="/tmp/ccio/$ip_IFACE.cfg"
ifcfg_TEMPLATE="/etc/ccio/lib/ifcfg.static"
target_DIR="/etc/network/interfaces.d/"

# Make Temp Directory if Not Found
[[ -d /tmp/ccio/ ]] || mkdir -p /tmp/ccio/

# Test if template found & abort if fail
[[ ! -d /etc/ccio/lib/ifcfg.template ]] || \
echo "ERROR: Template File Not Found!" && \
echo "Aborting!" && exit 1

pipe_template () {
eval "echo \"$(cat $1)\""
}

gen_config () {
ifcfg_CONFIG=$(pipe_template $ifcfg_TEMPLATE)
}

make_ifcfg () {
gen_config
echo "Writing Config to $tmp_FILE"
echo -e "$ifcfg_CONFIG" | tee $tmp_FILE
}

push_ifcfg () {
lxc file push $tmp_FILE $container_NAME$target_DIR
}

make_ifcfg
#push_ifcfg

0 comments on commit ec84518

Please sign in to comment.