Update rename.sh

This commit is contained in:
tschettervictor
2025-06-11 22:26:32 -06:00
committed by GitHub
parent 84de77031a
commit c2474aa170

View File

@@ -112,7 +112,7 @@ update_jailconf() {
sed -i '' "s|exec.consolelog.*=.*;|exec.consolelog = ${bastille_logsdir}/${NEWNAME}_console.log;|" "${_jail_conf}"
sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${NEWNAME}/root;|" "${_jail_conf}"
sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${NEWNAME}/fstab;|" "${_jail_conf}"
sed -i '' "s|${TARGET}.*{|${NEWNAME} {|" "${_jail_conf}"
sed -i '' "s|^${TARGET}.*{$|${NEWNAME} {|" "${_jail_conf}"
fi
if grep -qo "vnet;" "${_jail_conf}"; then
update_jailconf_vnet
@@ -128,22 +128,22 @@ update_jailconf_vnet() {
# Change bastille interface name (only needed for bridged epairs)
# We still gather interface names for JIB and JNG managed interfaces (for future use)
if [ "${bastille_network_vnet_type}" = "if_bridge" ]; then
local _if_list="$(grep -Eo 'e[0-9]+a_.* ' ${_jail_conf} | sort -u)"
local _if_list="$(grep -Eo 'e[0-9]+a_[^;" ]+' ${_jail_conf} | sort -u)"
elif [ "${bastille_network_vnet_type}" = "netgraph" ]; then
local _if_list="$(grep -Eo 'ng[0-9]+_.* ' ${_jail_conf} | sort -u)"
local _if_list="$(grep -Eo 'ng[0-9]+_[^;" ]+' ${_jail_conf} | sort -u)"
fi
for _if in ${_if_list}; do
local _if_prefix="$(echo ${_if} | awk -F'_' '{print $1}')"
local _if_suffix="$(echo ${_if} | awk -F'_' '{print $2}')"
local _old_if_prefix="$(echo ${_if} | awk -F'_' '{print $1}')"
local _old_if_suffix="$(echo ${_if} | awk -F'_' '{print $2}')"
# For VNET jails that use the JIB script
if grep " ${_if_suffix} " ${_jail_conf} | grep -Eoq "jib addm"; then
# For if_bridge network type
if [ "${bastille_network_vnet_type}" = "if_bridge" ]; then
local _epair_num="$(grep -Eo -m 1 "${_if_prefix}" "${_jail_conf}" | grep -Eo "[0-9]+")"
local _target_host_epair="$(grep -Eo -m 1 "e${_epair_num}a_.* " "${_jail_conf}")"
local _target_jail_epair="$(grep -Eo -m 1 "e${_epair_num}b_.* " "${_jail_conf}")"
local _epair_num=$(echo "${_old_if_prefix}" | grep -Eo "[0-9]+")
local _old_host_epair="${_if}"
local _old_jail_epair="${_old_if_prefix%a}b_${_old_if_suffix}"
if [ "$(echo -n "e${_epair_num}a_${NEWNAME}" | awk '{print length}')" -lt 16 ]; then
# Generate new epair name
@@ -159,85 +159,72 @@ update_jailconf_vnet() {
local _new_if_prefix="$(echo ${_new_host_epair} | awk -F'_' '{print $1}')"
local _new_if_suffix="$(echo ${_new_host_epair} | awk -F'_' '{print $2}')"
# Replace host epair name in jail.conf
sed -i '' "s|jib addm ${_if_suffix}|jib addm ${_new_if_suffix}|g" "${_jail_conf}"
sed -i '' "s|${_target_host_epair} ether|${_new_host_epair} ether|g" "${_jail_conf}"
sed -i '' "s|${_if_suffix} destroy|${_new_if_suffix} destroy|g" "${_jail_conf}"
sed -i '' "s|${_target_host_epair} description|${_new_host_epair} description|g" "${_jail_conf}"
if grep "${_old_if_suffix}" "${_jail_conf}" | grep "jib addm"; then
# For -V jails
# Replace host epair name in jail.conf
sed -i '' "s|jib addm ${_old_if_suffix}|jib addm ${_new_if_suffix}|g" "${_jail_conf}"
sed -i '' "s|${_old_host_epair} ether|${_new_host_epair} ether|g" "${_jail_conf}"
sed -i '' "s|destroy ${_old_if_suffix}|destroy ${_new_if_suffix}|g" "${_jail_conf}"
sed -i '' "s|${_old_host_epair} description|${_new_host_epair} description|g" "${_jail_conf}"
# Replace jail epair name in jail.conf
sed -i '' "s|= ${_target_jail_epair};|= ${_new_jail_epair};|g" "${_jail_conf}"
sed -i '' "s|${_target_jail_epair} ether|${_new_jail_epair} ether|g" "${_jail_conf}"
# Replace jail epair name in jail.conf
sed -i '' "s|= ${_old_jail_epair};|= ${_new_jail_epair};|g" "${_jail_conf}"
sed -i '' "s|${_old_jail_epair} ether|${_new_jail_epair} ether|g" "${_jail_conf}"
# Replace epair description
sed -i '' "s|host interface for Bastille jail ${TARGET}|host interface for Bastille jail ${NEWNAME}|g" "${_jail_conf}"
# Replace epair description
sed -i '' "s|host interface for Bastille jail ${TARGET}|host interface for Bastille jail ${NEWNAME}|g" "${_jail_conf}"
# Replace epair name in /etc/rc.conf
sed -i '' "/ifconfig/ s|${_target_jail_epair}|${_new_jail_epair}|g" "${_rc_conf}"
elif grep " ${_if_suffix} " ${_jail_conf} | grep -Eoq "jng bridge"; then
# Replace epair name in /etc/rc.conf
sed -i '' "/ifconfig/ s|${_old_jail_epair}|${_new_jail_epair}|g" "${_rc_conf}"
else
# For -B jails
# Replace host epair name in jail.conf
sed -i '' "s|up name ${_old_host_epair}|up name ${_new_host_epair}|g" "${_jail_conf}"
sed -i '' "s|addm ${_old_host_epair}|addm ${_new_host_epair}|g" "${_jail_conf}"
sed -i '' "s|${_old_host_epair} ether|${_new_host_epair} ether|g" "${_jail_conf}"
sed -i '' "s|deletem ${_old_host_epair}|deletem ${_new_host_epair}|g" "${_jail_conf}"
sed -i '' "s|${_old_host_epair} destroy|${_new_host_epair} destroy|g" "${_jail_conf}"
sed -i '' "s|${_old_host_epair} description|${_new_host_epair} description|g" "${_jail_conf}"
# Replace jail epair name in jail.conf
sed -i '' "s|= ${_old_jail_epair};|= ${_new_jail_epair};|g" "${_jail_conf}"
sed -i '' "s|up name ${_old_jail_epair}|up name ${_new_jail_epair}|g" "${_jail_conf}"
sed -i '' "s|${_old_jail_epair} ether|${_new_jail_epair} ether|g" "${_jail_conf}"
# Replace epair description
sed -i '' "s|host interface for Bastille jail ${TARGET}|host interface for Bastille jail ${NEWNAME}|g" "${_jail_conf}"
# Replace epair name in /etc/rc.conf
sed -i '' "/ifconfig/ s|${_old_jail_epair}|${_new_jail_epair}|g" "${_rc_conf}"
fi
# For netgraph network type
elif [ "${bastille_network_vnet_type}" = "netgraph" ]; then
local _ngif_num="$(grep -Eo -m 1 "${_if_prefix}" "${_jail_conf}" | grep -Eo "[0-9]+")"
local _target_ngif="$(grep -Eo -m 1 "ng${_ngif_num}_.* " "${_jail_conf}")"
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 epair name
# 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${_epair_num}_${name_prefix}xx${name_suffix}"
local _new_ngif="ng${_ngif_num}_${name_prefix}xx${name_suffix}"
fi
local _new_if_prefix="$(echo ${_if} | awk -F'_' '{print $1}')"
local _new_if_suffix="$(echo ${_if} | awk -F'_' '{print $2}')"
# Replace netgraph interface name
sed -i '' "s|jng bridge ${_if_suffix}|jng bridge ${_new_if_suffix}|g" "${_jail_conf}"
sed -i '' "s|${_target_ngif} ether|${_new_ngif} ether|g" "${_jail_conf}"
sed -i '' "s|jng shutdown ${_if_suffix}|jng shutdown ${_new_if_suffix}|g" "${_jail_conf}"
sed -i '' "s|jng bridge ${_old_if_suffix}|jng bridge ${_new_if_suffix}|g" "${_jail_conf}"
sed -i '' "s|${_old_ngif} ether|${_new_ngif} ether|g" "${_jail_conf}"
sed -i '' "s|jng shutdown ${_old_if_suffix}|jng shutdown ${_new_if_suffix}|g" "${_jail_conf}"
# Replace jail epair name in jail.conf
sed -i '' "s|= ${_target_ngif};|= ${_new_ngif};|g" "${_jail_conf}"
sed -i '' "s|= ${_old_ngif};|= ${_new_ngif};|g" "${_jail_conf}"
# Replace epair name in /etc/rc.conf
sed -i '' "/ifconfig/ s|${_target_ngif}|${_new_ngif}|g" "${_rc_conf}"
elif grep "${_if}" ${_jail_conf} | grep -Eoq "epair create"; then
local _epair_num="$(grep -Eo -m 1 "${_if_prefix}" "${_jail_conf}" | grep -Eo "[0-9]+")"
local _target_host_epair="$(grep -Eo -m 1 "e${_epair_num}a_.* " "${_jail_conf}")"
local _target_jail_epair="$(grep -Eo -m 1 "e${_epair_num}b_.* " "${_jail_conf}")"
if [ "$(echo -n "e${_epair_num}a_${NEWNAME}" | awk '{print length}')" -lt 16 ]; then
# Generate new epair name
local _new_host_epair="e${_epair_num}a_${NEWNAME}"
local _new_jail_epair="e${_epair_num}b_${NEWNAME}"
else
name_prefix="$(echo ${NEWNAME} | cut -c1-7)"
name_suffix="$(echo ${NEWNAME} | rev | cut -c1-2 | rev)"
local _new_host_epair="e${_epair_num}a_${name_prefix}xx${name_suffix}"
local _new_jail_epair="e${_epair_num}b_${name_prefix}xx${name_suffix}"
fi
# Replace host epair name in jail.conf
sed -i '' "s|up name ${_target_host_epair}|up name ${_new_host_epair}|g" "${_jail_conf}"
sed -i '' "s|addm ${_target_host_epair}|addm ${_new_host_epair}|g" "${_jail_conf}"
sed -i '' "s|${_target_host_epair} ether|${_new_host_epair} ether|g" "${_jail_conf}"
sed -i '' "s|deletem ${_target_host_epair}|deletem ${_new_host_epair}|g" "${_jail_conf}"
sed -i '' "s|${_target_host_epair} destroy|${_new_host_epair} destroy|g" "${_jail_conf}"
sed -i '' "s|${_target_host_epair} description|${_new_host_epair} description|g" "${_jail_conf}"
# Replace jail epair name in jail.conf
sed -i '' "s|= ${_target_jail_epair};|= ${_new_jail_epair};|g" "${_jail_conf}"
sed -i '' "s|up name ${_target_jail_epair}|up name ${_new_jail_epair}|g" "${_jail_conf}"
sed -i '' "s|${_target_jail_epair} ether|${_new_jail_epair} ether|g" "${_jail_conf}"
# Replace epair description
sed -i '' "s|host interface for Bastille jail ${TARGET}|host interface for Bastille jail ${NEWNAME}|g" "${_jail_conf}"
# Replace epair name in /etc/rc.conf
sed -i '' "/ifconfig/ s|${_target_jail_epair}|${_new_jail_epair}|g" "${_rc_conf}"
sed -i '' "/ifconfig/ s|${_old_ngif}|${_new_ngif}|g" "${_rc_conf}"
fi
done
}