mirror of
https://github.com/hackacad/bastille.git
synced 2026-03-25 02:05:11 +01:00
epair-name: final revision
This commit is contained in:
@@ -263,8 +263,8 @@ update_jailconf_vnet() {
|
||||
while echo "${BASTILLE_EPAIR_LIST}" | grep -oq "bastille${epair_num}"; do
|
||||
epair_num=$((epair_num + 1))
|
||||
done
|
||||
local host_epair="e0a_bastille${epair_num}"
|
||||
local jail_epair="e0b_bastille${epair_num}"
|
||||
local _new_host_epair="e0a_bastille${epair_num}"
|
||||
local _new_jail_epair="e0b_bastille${epair_num}"
|
||||
fi
|
||||
|
||||
local _new_if_prefix="$(echo ${_new_host_epair} | awk -F'_' '{print $1}')"
|
||||
@@ -375,16 +375,8 @@ update_jailconf_vnet() {
|
||||
|
||||
local _ngif_num="$(echo "${_old_if_prefix}" | grep -Eo "[0-9]+")"
|
||||
local _old_ngif="${_if}"
|
||||
|
||||
if [ "$(echo -n "ng${_ngif_num}_${NEWNAME}" | awk '{print length}')" -lt 16 ]; then
|
||||
# Generate new netgraph interface name
|
||||
local _new_ngif="ng${_ngif_num}_${NEWNAME}"
|
||||
else
|
||||
name_prefix="$(echo ${NEWNAME} | cut -c1-7)"
|
||||
name_suffix="$(echo ${NEWNAME} | rev | cut -c1-2 | rev)"
|
||||
local _new_ngif="ng${_ngif_num}_${name_prefix}xx${name_suffix}"
|
||||
fi
|
||||
|
||||
# Generate new netgraph interface name
|
||||
local _new_ngif="ng${_ngif_num}_${NEWNAME}"
|
||||
local _new_if_prefix="$(echo ${_if} | awk -F'_' '{print $1}')"
|
||||
local _new_if_suffix="$(echo ${_if} | awk -F'_' '{print $2}')"
|
||||
|
||||
@@ -560,4 +552,4 @@ info "\nAttempting to clone '${TARGET}' to '${NEWNAME}'..."
|
||||
|
||||
clone_validate_jail_name
|
||||
|
||||
clone_jail
|
||||
clone_jail
|
||||
@@ -124,7 +124,7 @@ check_target_is_stopped() {
|
||||
get_bastille_epair_count() {
|
||||
for _config in /usr/local/etc/bastille/*.conf; do
|
||||
local bastille_jailsdir="$(sysrc -f "${_config}" -n bastille_jailsdir)"
|
||||
BASTILLE_EPAIR_LIST="$(printf '%s\n%s' "$( (grep -Ehos '(epair[0-9]+|bastille[0-9]+)' ${bastille_jailsdir}/*/jail.conf; ifconfig -g epair | grep -Eos "_bastille[0-9]+$"; ifconfig -g epair | grep -vs 'bastille' | grep -Eos 'e[0-9]+a_') | grep -Eos '[0-9]+')" "${_epair_list}")"
|
||||
BASTILLE_EPAIR_LIST="$(printf '%s\n%s' "$( (grep -Ehos "bastille[0-9]+" ${bastille_jailsdir}/*/jail.conf; ifconfig -g epair | grep -Eos "e[0-9]+a_bastille[0-9]+$" | grep -Eos 'bastille[0-9]+') | sort -u)" "${_epair_list}")"
|
||||
done
|
||||
BASTILLE_EPAIR_COUNT=$(printf '%s' "${BASTILLE_EPAIR_LIST}" | sort -u | wc -l | awk '{print $1}')
|
||||
export BASTILLE_EPAIR_LIST
|
||||
|
||||
@@ -1173,5 +1173,3 @@ if check_target_exists "${NAME}"; then
|
||||
fi
|
||||
|
||||
create_jail "${NAME}" "${RELEASE}" "${IP}" "${INTERFACE}"
|
||||
|
||||
echo
|
||||
|
||||
@@ -247,7 +247,7 @@ add_interface() {
|
||||
if [ "${bastille_network_vnet_type}" = "if_bridge" ]; then
|
||||
local _if_list="$(grep -Eo 'e[0-9]+a_[^;" ]+' ${_jail_config} | sort -u)"
|
||||
local _epair_count="$(echo "${_if_list}" | grep -Eo "[0-9]+" | wc -l)"
|
||||
local _epair_num_range=$((_epair_count + 1))
|
||||
local _epair_num_range=$((_epair_count + 1))
|
||||
elif [ "${bastille_network_vnet_type}" = "netgraph" ]; then
|
||||
local _if_list="$(grep -Eo 'ng[0-9]+_[^;" ]+' ${_jail_config} | sort -u)"
|
||||
local _ngif_count="$(echo "${_if_list}" | grep -Eo "[0-9]+" | wc -l)"
|
||||
@@ -261,10 +261,13 @@ add_interface() {
|
||||
local host_epair=e${_epair_num}a_${_jailname}
|
||||
local jail_epair=e${_epair_num}b_${_jailname}
|
||||
else
|
||||
name_prefix="$(echo ${_jailname} | cut -c1-7)"
|
||||
name_suffix="$(echo ${_jailname} | rev | cut -c1-2 | rev)"
|
||||
local host_epair="e${_epair_num}a_${name_prefix}xx${name_suffix}"
|
||||
local jail_epair="e${_epair_num}b_${name_prefix}xx${name_suffix}"
|
||||
get_bastille_epair_count
|
||||
local global_epair_num=1
|
||||
while echo "${BASTILLE_EPAIR_LIST}" | grep -oq "bastille${global_epair_num}"; do
|
||||
global_epair_num=$((global_epair_num + 1))
|
||||
done
|
||||
local host_epair="e0a_bastille${global_epair_num}"
|
||||
local jail_epair="e0b_bastille${global_epair_num}"
|
||||
fi
|
||||
# Remove ending brace (it is added again with the netblock)
|
||||
sed -i '' '/^}$/d' "${_jail_config}"
|
||||
@@ -326,11 +329,14 @@ EOF
|
||||
local jail_epair=e${_epair_num}b_${_jailname}
|
||||
local jib_epair=${_jailname}
|
||||
else
|
||||
name_prefix="$(echo ${_jailname} | cut -c1-7)"
|
||||
name_suffix="$(echo ${_jailname} | rev | cut -c1-2 | rev)"
|
||||
local host_epair="e${_epair_num}a_${name_prefix}xx${name_suffix}"
|
||||
local jail_epair="e${_epair_num}b_${name_prefix}xx${name_suffix}"
|
||||
local jib_epair="${name_prefix}xx${name_suffix}"
|
||||
get_bastille_epair_count
|
||||
local global_epair_num=1
|
||||
while echo "${BASTILLE_EPAIR_LIST}" | grep -oq "bastille${global_epair_num}"; do
|
||||
global_epair_num=$((global_epair_num + 1))
|
||||
done
|
||||
local host_epair="e0a_bastille${global_epair_num}"
|
||||
local jail_epair="e0b_bastille${global_epair_num}"
|
||||
local jib_epair="bastille${global_epair_num}"
|
||||
fi
|
||||
# Remove ending brace (it is added again with the netblock)
|
||||
sed -i '' '/^}$/d' "${_jail_config}"
|
||||
@@ -387,11 +393,6 @@ EOF
|
||||
# Generate new netgraph interface name
|
||||
local _ngif="ng${_ngif_num}_${_jailname}"
|
||||
local jng_if="${_jailname}"
|
||||
else
|
||||
name_prefix="$(echo ${_jailname} | cut -c1-7)"
|
||||
name_suffix="$(echo ${_jailname} | rev | cut -c1-2 | rev)"
|
||||
local _ngif="ng${_ngif_num}_${name_prefix}xx${name_suffix}"
|
||||
local jng_if="${name_prefix}xx${name_suffix}"
|
||||
fi
|
||||
# Remove ending brace (it is added again with the netblock)
|
||||
sed -i '' '/^}$/d' "${_jail_config}"
|
||||
|
||||
Reference in New Issue
Block a user