mirror of
https://codeberg.org/scip/jaildk.git
synced 2025-12-17 04:31:02 +01:00
fix #24 (part I): get rid of perl, check for external programs
This commit is contained in:
@@ -112,7 +112,7 @@ die() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
load-jail-config() {
|
load_jail_config() {
|
||||||
local jail=$1
|
local jail=$1
|
||||||
if test -d $j/etc/$jail; then
|
if test -d $j/etc/$jail; then
|
||||||
# everything inside gets global
|
# everything inside gets global
|
||||||
@@ -229,7 +229,7 @@ jaildk_build() {
|
|||||||
|
|
||||||
die_if_not_exist $jail $VERSION
|
die_if_not_exist $jail $VERSION
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
if test -n "$VERSION"; then
|
if test -n "$VERSION"; then
|
||||||
# overridden with -v
|
# overridden with -v
|
||||||
@@ -338,7 +338,7 @@ rc_pf() {
|
|||||||
conf=$j/etc/$jail/pf.conf
|
conf=$j/etc/$jail/pf.conf
|
||||||
ruleset=$j/etc/$jail/pf-ruleset.conf
|
ruleset=$j/etc/$jail/pf-ruleset.conf
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - put this into a separate function
|
# - put this into a separate function
|
||||||
@@ -520,7 +520,7 @@ rc_ports() {
|
|||||||
rw=$5
|
rw=$5
|
||||||
rcscript=ports
|
rcscript=ports
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
if test -z "$ports"; then
|
if test -z "$ports"; then
|
||||||
# ports not configured, abort
|
# ports not configured, abort
|
||||||
@@ -563,7 +563,7 @@ rc_mount() {
|
|||||||
rw=$5
|
rw=$5
|
||||||
rcscript=mount
|
rcscript=mount
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
conf=$j/etc/$jail/$rcscript.conf
|
conf=$j/etc/$jail/$rcscript.conf
|
||||||
|
|
||||||
@@ -1063,7 +1063,7 @@ jaildk_clone() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
die_if_not_exist $src "Source jail"
|
die_if_not_exist $src "Source jail"
|
||||||
load-jail-config $src
|
load_jail_config $src
|
||||||
|
|
||||||
if test -z "$srcversion"; then
|
if test -z "$srcversion"; then
|
||||||
srcversion=$version
|
srcversion=$version
|
||||||
@@ -1178,8 +1178,7 @@ jaildk_create() {
|
|||||||
mkdir -p $j/etc/$jail
|
mkdir -p $j/etc/$jail
|
||||||
|
|
||||||
jaildk_clone -s $src -d $jail -o $srcversion -n $newversion
|
jaildk_clone -s $src -d $jail -o $srcversion -n $newversion
|
||||||
# some perl magic to extract the hostname (if any) from /etc/jail.conf - and write it into the jails rc.conf
|
jailhostname=$(cat /etc/jail.conf | grep -E "^$jail" -A50 | sed '/\}/q' | grep hostname | cut -d\" -f2)
|
||||||
jailhostname=$(cat /etc/jail.conf | tr -d '\t\r\n ' | perl -ne '$_ =~ /.*'"$newjail"'(\{(?:\{.*\}|[^{])*\})|\w+/; print $1;' | grep -oE 'hostname=[^;]+' | cut -d= -f2)
|
|
||||||
if [ -n "$jailhostname" ]; then
|
if [ -n "$jailhostname" ]; then
|
||||||
echo "new name: $jailhostname"
|
echo "new name: $jailhostname"
|
||||||
echo "in path $j/etc/$jail/local-etc-$newversion/rc.conf"
|
echo "in path $j/etc/$jail/local-etc-$newversion/rc.conf"
|
||||||
@@ -1300,7 +1299,7 @@ jaildk_jail() {
|
|||||||
build='no'
|
build='no'
|
||||||
base=''
|
base=''
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
_eip=''
|
_eip=''
|
||||||
for map in $maps; do
|
for map in $maps; do
|
||||||
@@ -1312,8 +1311,8 @@ jaildk_jail() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if jls -j $jail > /dev/null 2>&1; then
|
if jls -j $jail > /dev/null 2>&1; then
|
||||||
# jail is running
|
# jail is running, get some data about jail
|
||||||
eval `jls -j $jail -qn | perl -n -e 'chomp; %j = map { ($a,$b) = split /=/; $a=~ s/\.//g; $a => $b } split/ /; foreach (keys %j) {print "$_=$j{$_}\n"}'`
|
eval $(jls -j v6 -qn ip4.addr ip6.addr jid)
|
||||||
if test -n "$ip4addr"; then
|
if test -n "$ip4addr"; then
|
||||||
ip=$ip4addr
|
ip=$ip4addr
|
||||||
else
|
else
|
||||||
@@ -1592,7 +1591,7 @@ jaildk_reinstall() {
|
|||||||
sync
|
sync
|
||||||
|
|
||||||
if test -n "$NEWBASE" -o -n "$NEWVERSION"; then
|
if test -n "$NEWBASE" -o -n "$NEWVERSION"; then
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
ts=`date +%Y%m%d%H%M`
|
ts=`date +%Y%m%d%H%M`
|
||||||
change=''
|
change=''
|
||||||
if test $NEWBASE != $base; then
|
if test $NEWBASE != $base; then
|
||||||
@@ -1900,7 +1899,7 @@ jaildk_freeze() {
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
if test -n "$VERSION"; then
|
if test -n "$VERSION"; then
|
||||||
version=$VERSION
|
version=$VERSION
|
||||||
@@ -2114,7 +2113,7 @@ ipfw_add() {
|
|||||||
jail=$1
|
jail=$1
|
||||||
|
|
||||||
# support jail variables as well
|
# support jail variables as well
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
if test -z $ip; then
|
if test -z $ip; then
|
||||||
# Getting current jails IP..
|
# Getting current jails IP..
|
||||||
@@ -2208,7 +2207,7 @@ jaildk_vnet() {
|
|||||||
|
|
||||||
die_if_not_exist $jail
|
die_if_not_exist $jail
|
||||||
|
|
||||||
load-jail-config $jail
|
load_jail_config $jail
|
||||||
|
|
||||||
if test -z "$ip" -a -z "$gw"; then
|
if test -z "$ip" -a -z "$gw"; then
|
||||||
usage_vnet
|
usage_vnet
|
||||||
@@ -2333,7 +2332,7 @@ jaildk_prune() {
|
|||||||
|
|
||||||
elif test -n "$JAIL"; then
|
elif test -n "$JAIL"; then
|
||||||
die_if_not_exist $JAIL
|
die_if_not_exist $JAIL
|
||||||
load-jail-config $JAIL
|
load_jail_config $JAIL
|
||||||
|
|
||||||
if test -z "$UNUSED"; then
|
if test -z "$UNUSED"; then
|
||||||
bold "Current Active jail version for jail $JAIL:" > /dev/stderr
|
bold "Current Active jail version for jail $JAIL:" > /dev/stderr
|
||||||
@@ -2470,6 +2469,16 @@ mustberoot() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sanitycheck() {
|
||||||
|
# check if certain programs are installed
|
||||||
|
for program in cpdup; do
|
||||||
|
if ! command -v $program 2>&1 >/dev/null; then
|
||||||
|
echo "$program must be installed!" >&2
|
||||||
|
exit1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
#
|
#
|
||||||
# main()
|
# main()
|
||||||
@@ -2494,6 +2503,8 @@ if test -z "$runner"; then
|
|||||||
usage_jaildk
|
usage_jaildk
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
sanitycheck
|
||||||
|
|
||||||
case $runner in
|
case $runner in
|
||||||
start|stop|restart)
|
start|stop|restart)
|
||||||
# running jails
|
# running jails
|
||||||
|
|||||||
Reference in New Issue
Block a user