Skip to content

Commit

Permalink
Rewrite jrctl-tui to forms functional. This is also fix for Issue #139
Browse files Browse the repository at this point in the history
  • Loading branch information
olevole committed Mar 8, 2017
1 parent e8a639f commit aa8b1f6
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 287 deletions.
32 changes: 0 additions & 32 deletions etc/defaults/vm-freebsd-BSDRP-x64-1.56.conf

This file was deleted.

35 changes: 35 additions & 0 deletions etc/defaults/vm-freebsd-BSDRP-x64-1.70.conf
@@ -0,0 +1,35 @@
# don't remove this line:
vm_profile="BSDRP-x64-1.70"

# this is one-string additional info strings in dialogue menu
long_description="Embedded free and open source router distribution"

# custom settings:
fetch=1

iso_site="https://netcologne.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.70/amd64/ http://garr.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.70/amd64/ http://cznic.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.70/amd64/"

iso_img="BSDRP-1.70-full-amd64-vga.img"
iso_img_dist="BSDRP-1.70-full-amd64-vga.img.xz"

# register_iso as:
register_iso_name="cbsd-iso-${iso_img}"
register_iso_as="iso-BSDRP-x64-1.70"

iso_extract="/usr/bin/xz -d "

default_jailname="bsdrp"
imgsize="4g"

vm_ram="1g"

active=0

# VNC
vm_vnc_port="0"
vm_efi="uefi"

vm_ram="1g"

# VirtualBox Area
virtualbox_ostype="FreeBSD_64"
45 changes: 35 additions & 10 deletions jailctl/brename
@@ -1,16 +1,18 @@
#!/usr/local/bin/cbsd
#v10.0.10
MYARG="old new"
MYOPTARG="host_hostname"
MYOPTARG="host_hostname restart"
MYDESC="Rename jail"
CBSDMODULE="bhyve"
ADDHELP="restart=1 - for online jails. Force to stop if online, rename and start again\n"
EXTHELP="wf_jrename.html"

. ${subr}
. ${tools}
. ${jfs}
. ${strings}

restart=0
init $*

[ -z "${old}" ] && err 1 "${MAGENTA}Give me old jname${NORMAL}"
Expand All @@ -30,24 +32,40 @@ SYSDIRNEW="${jailsysdir}/${new}"
jname="${old}"
. ${jrcconf}
[ "${emulator}" != "bhyve" ] && err 1 "${MAGENTA}Not bhyve mode${NORMAL}"
[ "${status}" != "0" ] && err 1 "${MAGENTA}Jail is online. Please stop them: ${GREEN}${old}${NORMAL}"

myjid=$( cbsdsql local SELECT jname FROM jails WHERE jname=\"${new}\" 2>/dev/null)
myjid=$( cbsdsql local SELECT jname FROM jails WHERE jname=\"${new}\" 2>/dev/null)
[ -n "${myjid}" ] && err 1 "${MAGENTA}Jail already exist: ${GREEN}${new}${NORMAL}"

[ ! -d "${SRC}" ] && err 1 "${MAGENTA}No jail data: ${GREEN}${SRC}${NORMAL}"

if [ -x "${moduledir}/cbsd_queue.d/cbsd_queue" ]; then
[ "${cbsd_queue_name}" != "none" ] && cbsd_queue cbsd_queue_name=${cbsd_queue_name} id="${old}" jname="${new}" cmd=brename status=1
fi

oldjid=${status}

case ${status} in
0)
;;
*)
if [ ${restart} -eq 1 ]; then
bstop jname=${old}
else
if [ -x "${moduledir}/cbsd_queue.d/cbsd_queue" ]; then
[ "${cbsd_queue_name}" != "none" ] && cbsd_queue cbsd_queue_name=${cbsd_queue_name} id="${new}" jname="${new}" cmd=brename status=2
fi
err 1 "${MAGENTA}VM is online. Please stop them: ${GREEN}${old}${MAGENTA} or add ${GREEN}restart=1${MAGENTA} to auto stop and start VM during rename${NORMAL}"
fi
;;
esac

[ ! -d "${SRC}" ] && err 1 "${MAGENTA}No VM data: ${GREEN}${SRC}${NORMAL}"

if [ -d "${DST}" ]; then
/bin/rmdir ${DST} >/dev/null 2>&1
[ -d "${DST}" ] && err 1 "${MAGENTA}Jail data already exist and it not empty: ${GREEN}${DST}${NORMAL}"
[ -d "${DST}" ] && err 1 "${MAGENTA}VM data already exist and it not empty: ${GREEN}${DST}${NORMAL}"
fi

[ ! -d "${JAILDIR}" ] && mkdir -p ${JAILDIR}
[ ! -d "${jailfstab}" ] && mkdir -p $jailfstabdir
[ ! -d "${JAILDIR}" ] && /bin/mkdir -p ${JAILDIR}
[ ! -d "${jailfstab}" ] && /bin/mkdir -p ${jailfstabdir}

printf "${MAGENTA}Rename${NORMAL}"

Expand All @@ -56,7 +74,7 @@ if [ -f "${JAILFSTABORIG}" ]; then
/usr/bin/sed -i '' s:/${old}:/${new}:g ${JAILFSTAB}
fi

[ -f "${JAILLOCALFSTABORIG}" ] && mv ${JAILLOCALFSTABORIG} ${JAILLOCALFSTAB} && dot "mv fstablocal"
[ -f "${JAILLOCALFSTABORIG}" ] && /bin/mv ${JAILLOCALFSTABORIG} ${JAILLOCALFSTAB} && dot "mv fstablocal"

cbsdsql local UPDATE jails SET jname=\"${new}\",path=\"${jaildir}/${new}\",mount_fstab=\"${jailfstabdir}/${jailfstabpref}${new}\",data=\"${jaildatadir}/${new}-${jaildatapref}\",rcconf=\"${jailrcconfdir}/rc.conf_${new}\" WHERE jname=\"${old}\"
cbsdsql local UPDATE rctl SET jname=\"${new}\" WHERE jname=\"${old}\" 2>/dev/null
Expand Down Expand Up @@ -122,8 +140,15 @@ if [ -d "$SYSDIROLD" ]; then
[ -r ${jailsysdir}/${jname}/local.sqlite ] && cbsdsql ${jailsysdir}/${jname}/local.sqlite "UPDATE bhyvenic set jname=\"${jname}\""
fi

if [ ${restart} -eq 1 -a ${oldjid} -ne 0 ]; then
bstart jname=${new}
data_status=1
else
data_status=0
fi

if [ -x "${moduledir}/cbsd_queue.d/cbsd_queue" ]; then
[ "${cbsd_queue_name}" != "none" ] && cbsd_queue cbsd_queue_name=${cbsd_queue_name} id="${new}" cmd=brename status=2 data_status=0
[ "${cbsd_queue_name}" != "none" ] && cbsd_queue cbsd_queue_name=${cbsd_queue_name} id="${new}" cmd=brename status=2 data_status=${data_status}
fi

[ -d "${SRC}" ] && /bin/rmdir ${SRC}
Expand Down
85 changes: 60 additions & 25 deletions jailctl/jrctl
@@ -1,5 +1,5 @@
#!/usr/local/bin/cbsd
#v10.0.7
#v11.0.10
CBSDMODULE="jail"
MYARG=""
MYOPTARG="mode jname alljails shownode display node header human"
Expand Down Expand Up @@ -41,14 +41,27 @@ show_header()
# if $1 = "Unregister" then overwrite status to "Unregister"
populate_output_data()
{
local _formfile

_formfile="${jailsysdir}/${jname}/helpers/jrctl.sqlite"

#populate values for in output string
for _i in ${mydisplay}; do
_val=""
eval _val=\$$_i
[ -z "${_val}" ] && _val="-"
if rctl_humanize ${_i}; then
if conv2human ${_val}; then
_val="${convval}"

_val="0"

if [ "${_i}" = "jname" ]; then
_val="${jname}"
else
if [ -r "${_formfile}" ]; then
_val=$( cbsdsql ${_formfile} "SELECT cur FROM forms WHERE param=\"${_i}\" LIMIT 1" 2>/dev/null )
[ -z "${_val}" ] && _val="0"
fi

if rctl_humanize ${_i}; then
if conv2human ${_val}; then
_val="${convval}"
fi
fi
fi

Expand Down Expand Up @@ -127,19 +140,56 @@ show_jails()

}

set_limit()
{
local LIMITS="${jailsysdir}/${jname}/jail.limits"
local _formfile
local _val
local i

_formfile="${jailsysdir}/${jname}/helpers/jrctl.sqlite"

[ ! -r "${_formfile}" ] && return 0

/usr/bin/truncate -s0 ${LIMITS}

for i in ${RCTL}; do
_val=$( cbsdsql ${_formfile} "SELECT cur FROM forms WHERE param=\"${i}\" LIMIT 1" 2>/dev/null )
[ -z "${_val}" ] && _val=0
[ "${_val}" = "0" ] && continue
echo "${i}:deny=${_val}" >> ${LIMITS}
done

if [ -f "${LIMITS}" ]; then
printf "${MAGENTA}${mode} resource limit: [ ${GREEN}"
cat ${LIMITS} |while read _p; do
case ":${_p}" in
:#* | :)
continue
;;
esac
_str="/usr/bin/rctl -a jail:${jname}:$_p"
_out=$( eval $_str )
[ $? -eq 0 ] && printf "${_p} "
done
printf "${MAGENTA}]${NORMAL}\n"
fi

}


jail_rctl()
{
local _action _str _p _out
local LIMITS="${jailsysdir}/${jname}/jail.limits"

case "${mode}" in
"set")
set_limit
_action="/usr/bin/rctl -a "
;;
"unset")
[ -z "${jname}" ] && err 1 "${MAGENTA}jname= must be set${NORMAL}"
/usr/bin/rctl -r jail:${jname}
#_action="rctl -r "
return 0
;;
"show")
Expand All @@ -163,24 +213,9 @@ jail_rctl()
return 0
;;
*)
show_jails|/usr/bin/column -t
show_jails | /usr/bin/column -t
;;
esac

if [ -f "${LIMITS}" ]; then
printf "${MAGENTA}${mode} resource limit: [ ${GREEN}"
cat ${LIMITS} |while read _p; do
case ":${_p}" in
:#* | :)
continue
;;
esac
_str="${_action} jail:${jname}:$_p"
_out=$( eval $_str )
[ $? -eq 0 ] && printf "${_p} "
done
printf "${MAGENTA}]${NORMAL}\n"
fi
}

#### MAIN
Expand Down

0 comments on commit aa8b1f6

Please sign in to comment.