erdgeistify styles, remove white spaces, support multiple ip addresses better
This commit is contained in:
parent
3d9f2923b5
commit
055caedade
57
ezjail-admin
57
ezjail-admin
@ -149,7 +149,7 @@ fetchjailinfo () {
|
|||||||
ezjail_name=$1
|
ezjail_name=$1
|
||||||
|
|
||||||
# Clean variables, prevent polution
|
# Clean variables, prevent polution
|
||||||
unset ezjail_config ezjail_running ezjail_hostname ezjail_rootdir ezjail_image ezjail_imagetype ezjail_imagedevice ezjail_devicelink ezjail_ip ezjail_id ezjail_attached ezjail_device ezjail_device_geom
|
unset ezjail_config ezjail_running ezjail_hostname ezjail_rootdir ezjail_image ezjail_imagetype ezjail_imagedevice ezjail_devicelink ezjail_ips ezjail_id ezjail_attached ezjail_device ezjail_device_geom
|
||||||
|
|
||||||
ezjail_safename=`echo -n "${ezjail_name}" | tr -c '[:alnum:]' _`
|
ezjail_safename=`echo -n "${ezjail_name}" | tr -c '[:alnum:]' _`
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ fetchjailinfo () {
|
|||||||
. "${ezjail_config}"
|
. "${ezjail_config}"
|
||||||
eval ezjail_hostname=\"\$jail_${ezjail_safename}_hostname\"
|
eval ezjail_hostname=\"\$jail_${ezjail_safename}_hostname\"
|
||||||
eval ezjail_rootdir=\"\$jail_${ezjail_safename}_rootdir\"
|
eval ezjail_rootdir=\"\$jail_${ezjail_safename}_rootdir\"
|
||||||
eval ezjail_ip=\"\$jail_${ezjail_safename}_ip\"
|
eval ezjail_ips=\"\$jail_${ezjail_safename}_ip\"
|
||||||
eval ezjail_image=\"\$jail_${ezjail_safename}_image\"
|
eval ezjail_image=\"\$jail_${ezjail_safename}_image\"
|
||||||
eval ezjail_imagetype=\"\$jail_${ezjail_safename}_imagetype\"
|
eval ezjail_imagetype=\"\$jail_${ezjail_safename}_imagetype\"
|
||||||
eval ezjail_attachparams=\"\$jail_${ezjail_safename}_attachparams\"
|
eval ezjail_attachparams=\"\$jail_${ezjail_safename}_attachparams\"
|
||||||
@ -337,28 +337,19 @@ parse_gbde_attach_args () {
|
|||||||
check_for_zfs () {
|
check_for_zfs () {
|
||||||
# check the ZFS version
|
# check the ZFS version
|
||||||
_zfs_version=`sysctl -nq vfs.zfs.version.spa`
|
_zfs_version=`sysctl -nq vfs.zfs.version.spa`
|
||||||
[ "${_zfs_version}" ] || _zfs_version=0
|
[ -z "${_zfs_version}" -o "${_zfs_version}" -lt 13 ] && exerr "Error: ZFS is not loaded or your ZFS version is not supported."
|
||||||
if [ "${_zfs_version}" -lt "13" ]; then
|
|
||||||
echo "ERROR: ZFS is not loaded or your ZFS version is not supported."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check if ZFS is enabled when managing basejail/newjail in ZFS
|
# check if ZFS is enabled when managing basejail/newjail in ZFS
|
||||||
. /etc/rc.subr
|
. /etc/rc.subr
|
||||||
load_rc_config_var zfs zfs_enable
|
load_rc_config_var zfs zfs_enable
|
||||||
if [ "${ezjail_use_zfs}" = "YES" -a "${zfs_enable}" != "YES" ]; then
|
checkyesno ezjail_use_zfs && checkyesno zfs_enable && echo "Warning: You should enable ZFS in /etc/rc.conf"
|
||||||
echo "WARNING: You should enable ZFS in /etc/rc.conf"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_for_zpool () {
|
check_for_zpool () {
|
||||||
# check for the ZFS zpool to be online
|
# check for the ZFS zpool to be online
|
||||||
check_for_zfs
|
check_for_zfs
|
||||||
_zpoolstatus=`/sbin/zpool list -H -o health ${ezjail_jailzfs%%/*} 2> /dev/null`
|
_zpoolstatus=`/sbin/zpool list -H -o health ${ezjail_jailzfs%%/*} 2> /dev/null`
|
||||||
if [ ! "${_zpoolstatus}" = "ONLINE" ]; then
|
[ "${_zpoolstatus}" = "ONLINE" ] || exerr "Error: Your zpool does not exist or is not online."
|
||||||
echo "Your zpool does not exist or is not online."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
@ -387,10 +378,10 @@ create)
|
|||||||
?) exerr ${ezjail_usage_create};;
|
?) exerr ${ezjail_usage_create};;
|
||||||
esac; done; shift $(( ${OPTIND} - 1 ))
|
esac; done; shift $(( ${OPTIND} - 1 ))
|
||||||
|
|
||||||
ezjail_name=$1; ezjail_ip=$2
|
ezjail_name=$1; ezjail_ips=$2
|
||||||
|
|
||||||
# we need at least a name and an ip for new jail
|
# we need at least a name and an ip for new jail
|
||||||
[ "${ezjail_name}" -a "${ezjail_ip}" -a $# -eq 2 ] || exerr ${ezjail_usage_create}
|
[ "${ezjail_name}" -a "${ezjail_ips}" -a $# -eq 2 ] || exerr ${ezjail_usage_create}
|
||||||
|
|
||||||
# show the user the type of image used
|
# show the user the type of image used
|
||||||
echo "TYPE: $ezjail_imagetype"
|
echo "TYPE: $ezjail_imagetype"
|
||||||
@ -556,7 +547,7 @@ create)
|
|||||||
mount "/dev/${ezjail_device}" "${ezjail_rootdir}" || detach_images || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_root}."
|
mount "/dev/${ezjail_device}" "${ezjail_rootdir}" || detach_images || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_root}."
|
||||||
else
|
else
|
||||||
if [ -e "${ezjail_rootdir}" -a ! -d "${ezjail_rootdir}" ]; then
|
if [ -e "${ezjail_rootdir}" -a ! -d "${ezjail_rootdir}" ]; then
|
||||||
[ "${ezjail_rootdir%%*.img}" ] || exerr "Error: Could not create mount point for your jails image.\n A file exists at its location.\n Try '${ezjail_admin} create -x -r ${ezjail_rootdir%%.img} ${ezjail_name} ${ezjail_ip}' instead."
|
[ "${ezjail_rootdir%%*.img}" ] || exerr "Error: Could not create mount point for your jails image.\n A file exists at its location.\n Try '${ezjail_admin} create -x -r ${ezjail_rootdir%%.img} ${ezjail_name} ${ezjail_ips}' instead."
|
||||||
exerr "Error: Could not create mount point for your jails image.\n A file exists at its location."
|
exerr "Error: Could not create mount point for your jails image.\n A file exists at its location."
|
||||||
fi
|
fi
|
||||||
[ -d "${ezjail_rootdir}" ] || mkdir -p "${ezjail_rootdir}"
|
[ -d "${ezjail_rootdir}" ] || mkdir -p "${ezjail_rootdir}"
|
||||||
@ -605,7 +596,7 @@ create)
|
|||||||
echo -e "#\n# PROVIDE: standard_ezjail\n# REQUIRE: \n# BEFORE: \n#\n"
|
echo -e "#\n# PROVIDE: standard_ezjail\n# REQUIRE: \n# BEFORE: \n#\n"
|
||||||
fi
|
fi
|
||||||
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
||||||
echo export jail_${ezjail_safename}_ip=\"${ezjail_ip}\"
|
echo export jail_${ezjail_safename}_ip=\"${ezjail_ips}\"
|
||||||
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
||||||
echo export jail_${ezjail_safename}_exec=\"/bin/sh /etc/rc\"
|
echo export jail_${ezjail_safename}_exec=\"/bin/sh /etc/rc\"
|
||||||
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
||||||
@ -647,17 +638,21 @@ create)
|
|||||||
# For user convenience some scenarios commonly causing headaches are checked
|
# For user convenience some scenarios commonly causing headaches are checked
|
||||||
#
|
#
|
||||||
|
|
||||||
|
TIFS=${IFS}; IFS=,
|
||||||
|
for ezjail_ip in ${ezjail_ips}; do
|
||||||
# check, whether IP is configured on a local interface, warn if it isnt
|
# check, whether IP is configured on a local interface, warn if it isnt
|
||||||
ping -c 1 -m 1 -t 1 -q ${ezjail_ip} > /dev/null
|
ping -c 1 -m 1 -t 1 -q ${ezjail_ip} > /dev/null
|
||||||
[ $? -eq 0 ] || echo "Warning: IP ${ezjail_ip} not configured on a local interface."
|
[ $? -eq 0 ] || echo "Warning: IP ${ezjail_ip} not configured on a local interface."
|
||||||
|
|
||||||
# check, whether some host system services do listen on the Jails IP
|
# check, whether some host system services do listen on the Jails IP
|
||||||
TIFS=${IFS}; IFS=_
|
IFS=_
|
||||||
ezjail_listener=`sockstat -4 -l | grep "${ezjail_ip}:[[:digit:]]"`
|
ezjail_listener=`sockstat -4 -l | grep "${ezjail_ip}:[[:digit:]]"`
|
||||||
[ $? -eq 0 ] && echo -e "Warning: Some services already seem to be listening on IP ${ezjail_ip}\n This may cause some confusion, here they are:\n${ezjail_listener}"
|
[ $? -eq 0 ] && echo -e "Warning: Some services already seem to be listening on IP ${ezjail_ip}\n This may cause some confusion, here they are:\n${ezjail_listener}"
|
||||||
|
|
||||||
ezjail_listener=`sockstat -4 -l | grep "*:[[:digit:]]"`
|
ezjail_listener=`sockstat -4 -l | grep "*:[[:digit:]]"`
|
||||||
[ $? -eq 0 ] && echo -e "Warning: Some services already seem to be listening on all IP, (including ${ezjail_ip})\n This may cause some confusion, here they are:\n${ezjail_listener}"
|
[ $? -eq 0 ] && echo -e "Warning: Some services already seem to be listening on all IP, (including ${ezjail_ip})\n This may cause some confusion, here they are:\n${ezjail_listener}"
|
||||||
|
IFS=,
|
||||||
|
done
|
||||||
IFS=${TIFS}
|
IFS=${TIFS}
|
||||||
|
|
||||||
[ "${ezjail_imagetype}" -a "${ezjail_imagetype}" != "zfs" ] && echo "Note: To administrate your image jail, attach it using the '${ezjail_admin} config -i attach ${ezjail_hostname}' command."
|
[ "${ezjail_imagetype}" -a "${ezjail_imagetype}" != "zfs" ] && echo "Note: To administrate your image jail, attach it using the '${ezjail_admin} config -i attach ${ezjail_hostname}' command."
|
||||||
@ -747,7 +742,16 @@ list)
|
|||||||
fi
|
fi
|
||||||
[ "${ezjail_safename}" != "${ezjail}" ] && ezjail_state="${ezjail_state}N"
|
[ "${ezjail_safename}" != "${ezjail}" ] && ezjail_state="${ezjail_state}N"
|
||||||
|
|
||||||
|
TIFS=${IFS}; IFS=,; unset _multiline
|
||||||
|
for ezjail_ip in ${ezjail_ips}; do
|
||||||
|
if[ -z "${_multiline}" ]; then
|
||||||
printf "%-3s %-5s %-15s %-28s %s\\n" "${ezjail_state}" "${ezjail_id:-N/A}" "${ezjail_ip}" "${ezjail_hostname}" "${ezjail_rootdir}"
|
printf "%-3s %-5s %-15s %-28s %s\\n" "${ezjail_state}" "${ezjail_id:-N/A}" "${ezjail_ip}" "${ezjail_hostname}" "${ezjail_rootdir}"
|
||||||
|
else
|
||||||
|
echo " ${ezjail_ip}"
|
||||||
|
_multiline=yes
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
IFS=${TIFS}
|
||||||
done
|
done
|
||||||
|
|
||||||
;;
|
;;
|
||||||
@ -1145,10 +1149,10 @@ restore)
|
|||||||
fetchjailinfo ${ezjail_safename} ${ezjail_config}
|
fetchjailinfo ${ezjail_safename} ${ezjail_config}
|
||||||
|
|
||||||
# Now all parameters are here, invoke ezjail-admin create
|
# Now all parameters are here, invoke ezjail-admin create
|
||||||
[ "${ezjail_rootdir}" -a "${ezjail_ip}" -a "${ezjail_hostname}" ] || exerr "Error: Archive does not contain a valid ezjail properties file.\n Some jails properties are missing."
|
[ "${ezjail_rootdir}" -a "${ezjail_ips}" -a "${ezjail_hostname}" ] || exerr "Error: Archive does not contain a valid ezjail properties file.\n Some jails properties are missing."
|
||||||
[ "${ezjail_imagetype}" ] && ezjail_imagedata="-c ${ezjail_imagetype} -C '${ezjail_attachparams}' -s ${ezjail_nameprop_imgagesize}"
|
[ "${ezjail_imagetype}" ] && ezjail_imagedata="-c ${ezjail_imagetype} -C '${ezjail_attachparams}' -s ${ezjail_nameprop_imgagesize}"
|
||||||
|
|
||||||
$0 create -a "${ezjail_fromarchive}" -A "${ezjail_config}" ${ezjail_imagedata} -r "${ezjail_rootdir}" "${ezjail_hostname}" "${ezjail_ip}" || exerr "Error: Create failed."
|
$0 create -a "${ezjail_fromarchive}" -A "${ezjail_config}" ${ezjail_imagedata} -r "${ezjail_rootdir}" "${ezjail_hostname}" "${ezjail_ips}" || exerr "Error: Create failed."
|
||||||
rm -f "${ezjail_config}"
|
rm -f "${ezjail_config}"
|
||||||
|
|
||||||
done
|
done
|
||||||
@ -1242,11 +1246,8 @@ config)
|
|||||||
unset ezjail_new_image
|
unset ezjail_new_image
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${ezjail_imagetype}" = "zfs" ]; then
|
|
||||||
# ZFS: using the zfs rename feature to rename the filesystem, remounting is done by ZFS
|
# ZFS: using the zfs rename feature to rename the filesystem, remounting is done by ZFS
|
||||||
zfs rename ${ezjail_jailzfs}/${ezjail_hostname} ${ezjail_jailzfs}/${ezjail_new_hostname}
|
[ "${ezjail_imagetype}" = "zfs" ] && zfs rename ${ezjail_jailzfs}/${ezjail_hostname} ${ezjail_jailzfs}/${ezjail_new_hostname}
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# adjust softlink
|
# adjust softlink
|
||||||
if [ -L "${ezjail_softlink}" ]; then
|
if [ -L "${ezjail_softlink}" ]; then
|
||||||
@ -1310,7 +1311,7 @@ config)
|
|||||||
grep -e ^\# "${ezjail_config}"
|
grep -e ^\# "${ezjail_config}"
|
||||||
echo
|
echo
|
||||||
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
||||||
echo export jail_${ezjail_safename}_ip=\"${ezjail_ip}\"
|
echo export jail_${ezjail_safename}_ip=\"${ezjail_ips}\"
|
||||||
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
||||||
echo export jail_${ezjail_safename}_exec=\"${ezjail_exec}\"
|
echo export jail_${ezjail_safename}_exec=\"${ezjail_exec}\"
|
||||||
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
||||||
@ -1339,7 +1340,7 @@ config)
|
|||||||
grep -e ^\# "${ezjail_config}"
|
grep -e ^\# "${ezjail_config}"
|
||||||
echo
|
echo
|
||||||
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
||||||
echo export jail_${ezjail_safename}_ip=\"${ezjail_ip}\"
|
echo export jail_${ezjail_safename}_ip=\"${ezjail_ips}\"
|
||||||
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
||||||
echo export jail_${ezjail_safename}_exec=\"${ezjail_exec}\"
|
echo export jail_${ezjail_safename}_exec=\"${ezjail_exec}\"
|
||||||
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
||||||
@ -1370,7 +1371,7 @@ config)
|
|||||||
grep -e ^\# "${ezjail_config}"
|
grep -e ^\# "${ezjail_config}"
|
||||||
echo
|
echo
|
||||||
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
echo export jail_${ezjail_safename}_hostname=\"${ezjail_hostname}\"
|
||||||
echo export jail_${ezjail_safename}_ip=\"${ezjail_ip}\"
|
echo export jail_${ezjail_safename}_ip=\"${ezjail_ips}\"
|
||||||
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
echo export jail_${ezjail_safename}_rootdir=\"${ezjail_rootdir}\"
|
||||||
echo export jail_${ezjail_safename}_exec=\"${ezjail_exec}\"
|
echo export jail_${ezjail_safename}_exec=\"${ezjail_exec}\"
|
||||||
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
echo export jail_${ezjail_safename}_mount_enable=\"${ezjail_mount_enable}\"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user