Skip to content

Commit

Permalink
Remove old ddns script; Change forms schema - We shall indicate the n…
Browse files Browse the repository at this point in the history
…ame of the table on create, no hardcode
  • Loading branch information
olevole committed Mar 10, 2016
1 parent b49c0f8 commit e0c0294
Show file tree
Hide file tree
Showing 52 changed files with 236 additions and 175 deletions.
2 changes: 2 additions & 0 deletions ObsoleteFiles
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ etc/defaults/vm-freebsd-OPNsense-15.7-RELEASE-amd64.conf
etc/defaults/vm-freebsd-kFreeBSD-amd64-7.8.0.conf
etc/defaults/vm-linux-opensuse-x86-13.1.conf
etc/defaults/vm-linux-opennode-2.6.32-358.el6.x86_64.conf
share/forms_version.schema
tools/ddns
"
83 changes: 54 additions & 29 deletions imghelper.subr
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,25 @@ update_params()

}


# $formfile and $table must be present
load_forms()
{
local param _id def def2 link type _env
local param _id def def2 link type _env idx lnk

[ ! -f ${formfile} ] && err 1 "${MAGENTA}formfile not found: ${GREEN}${formfile}${NORMAL}"
[ -z "${table}" ] && table="forms"

idx=0

param="$( cbsdsql ${formfile} SELECT param FROM ${table}|/usr/bin/xargs )"

param=$( cbsdsql ${formfile} SELECT param FROM forms ORDER BY order_id |/usr/bin/xargs )
# eval $( cbsdsql ${formfile} SELECT param,mytable FROM ${table} WHERE type != \"subtable\" ORDER BY order_id |while read _x; do
# idx=$(( idx + 1 ))
# unset _param _mytable
# sqllist "${_x}" _param _mytable
# echo "param${idx}=\"${_param}\""
# echo "table${idx}=\"${_mytable}\""
# done )

helpername=$( cbsdsql ${formfile} SELECT helpername FROM system )
packages=$( cbsdsql ${formfile} SELECT packages FROM system )
Expand All @@ -84,44 +95,58 @@ load_forms()

[ "${packages}" = "0" ] && packages=""

_id=1
_id=0 # First SQL sequence is 1

eval $( for i in ${param}; do
unset _env desc _res cur attr xattr mandatory

# desc="$( cbsdsql ${formfile} SELECT desc FROM forms WHERE param=\"${i}\" |/usr/bin/tr -d "'\"")"
desc="$( cbsdsql ${formfile} SELECT desc FROM forms WHERE idx=\"${_id}\" |/usr/bin/tr -d "'\"")"
_id=$(( _id + 1 ))
desc="$( cbsdsql ${formfile} SELECT desc FROM ${table} WHERE idx=\"${_id}\" |/usr/bin/tr -d "'\"")"

is_delimer=0
is_hiddendelim=0
is_subtable=0
is_value=0

unset type
type="$( cbsdsql ${formfile} SELECT type FROM ${table} WHERE idx=\"${_id}\" )"

# check for special type or its value
case "${type}" in
hiddendelim)
is_hiddendelim=1
;;
subtable)
is_subtable=1
;;
delimer)
is_delimer=1
i="forms_delimer_${_id}"
;;
*)
is_value=1
;;
esac

# check for H_environment
if [ "${i}" != "-" ]; then
eval _res="\$H_${i}"
else
# just get unique name for delimer_field
i="forms_delimer_${_id}"
is_delimer=1
fi
[ ${is_value} -eq 1 ] && eval _res="\$H_${i}"

if [ -n "${_res}" ]; then
# environment is preferred
echo "${i}=\"${_res}\""
elif [ ${is_delimer} -eq 0 ]; then

unset type
type="$( cbsdsql ${formfile} SELECT type FROM forms WHERE param=\"${i}\" )"

elif [ ${is_value} -eq 1 ]; then
# preferred for cur value
cur="$( cbsdsql ${formfile} SELECT cur FROM forms WHERE param=\"${i}\" )"
cur="$( cbsdsql ${formfile} SELECT cur FROM ${table} WHERE idx=\"${_id}\" )"

if [ -n "${cur}" ]; then
def="${cur}"
else
def="$( cbsdsql ${formfile} SELECT def FROM forms WHERE param=\"${i}\" )"
def="$( cbsdsql ${formfile} SELECT def FROM ${table} WHERE idx=\"${_id}\" )"
fi

unset link
link="$( cbsdsql ${formfile} SELECT link FROM forms WHERE param=\"${i}\" )"
link="$( cbsdsql ${formfile} SELECT link FROM ${table} WHERE idx=\"${_id}\" )"

if [ -n "${link}" ]; then
def2="$( cbsdsql ${formfile} SELECT text FROM ${link} WHERE id=\"${def}\" )"
if [ -n "${def2}" ]; then
Expand All @@ -134,32 +159,32 @@ load_forms()
echo "${i}=\"${i}\""
fi

attr="$( cbsdsql ${formfile} SELECT attr FROM forms WHERE param=\"${i}\" )"
xattr="$( cbsdsql ${formfile} SELECT xattr FROM forms WHERE param=\"${i}\" )"
mandatory="$( cbsdsql ${formfile} SELECT mandatory FROM forms WHERE param=\"${i}\" )"
attr="$( cbsdsql ${formfile} SELECT attr FROM ${table} WHERE idx=\"${_id}\" )"
xattr="$( cbsdsql ${formfile} SELECT xattr FROM ${table} WHERE idx=\"${_id}\" )"
mandatory="$( cbsdsql ${formfile} SELECT mandatory FROM ${table} WHERE idx=\"${_id}\" )"

echo "${i}_desc=\"${desc}\""
echo "${i}_mandatory=\"${mandatory}\""
echo "${i}_link=\"${link}\""
echo "${i}_type=\"${type}\""

_id=$(( _id +1 ))
echo "${i}_attr=\"${attr}\""
done )
}


# $formfile and $table must be present
load_new()
{
[ ! -f ${formfile} ] && err 1 "${MAGENTA}formfile not found: ${GREEN}${formfile}${NORMAL}"
[ -z "${table}" ] && table="forms"

local param
param=$( cbsdsql ${formfile} SELECT param FROM forms ORDER BY order_id |/usr/bin/xargs )
param=$( cbsdsql ${formfile} SELECT param FROM ${table} ORDER BY order_id |/usr/bin/xargs )
local _env

eval $( for i in ${param}; do
[ "${i}" = "-" ] && continue
unset _env new
new="$( cbsdsql ${formfile} SELECT new FROM forms WHERE param=\"${i}\" )"
new="$( cbsdsql ${formfile} SELECT new FROM ${table} WHERE param=\"${i}\" )"
[ -z "${new}" ] && continue
echo "${i}=\"${new}\""
done )
Expand Down
16 changes: 15 additions & 1 deletion jailctl/jcleanup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
globalconf="${workdir}/cbsd.conf";
CBSDMODULE="jail"
MYARG="jname"
MYOPTARG=""
MYOPTARG="sharedfs"
MYDESC="Force unmount and cleanup for offline jail"

# Cleanup all items of broken jail
Expand All @@ -12,11 +12,19 @@ MYDESC="Force unmount and cleanup for offline jail"
. ${mdtools}
. ${strings}

sharedfs=0

init $*

. ${jrcconf}
[ $? -eq 1 ] && return 0 #only for registered jails

# remove zombie jail
if [ "${jid}" != "0" ]; then
/usr/sbin/jail -r ${jid}
${miscdir}/sqlcli ${dbdir}/local.sqlite "UPDATE jails SET jid=\"0\" WHERE jname=\"${jname}\""
fi

[ "${mdsize}" != "0" ] && MDFILE=$( eval find_md_by_mountpath ${data} )
[ ${baserw} -eq 1 ] && path=$data

Expand All @@ -37,3 +45,9 @@ fi

umount_cdirs ${path} ${rootflags}
[ "${mdsize}" != "0" -a -n "${MDFILE}" ] && unmountmd md=${MDFILE}

jaillock="${jailsysdir}/${jname}/locked"
if [ ${sharedfs} -eq 0 ]; then
[ -f "${jaillock}" ] && /bin/rm -f ${jaillock}
fi

2 changes: 1 addition & 1 deletion jailctl/jls
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ show_jaildata_from_sql()
sqlfile="local"
fi

cbsdsql ${sqlfile} SELECT jname FROM jails| while read jname; do
cbsdsql ${sqlfile} SELECT jname FROM jails WHERE emulator=\"jail\" | while read jname; do
_status=""
. ${jrcconf}

Expand Down
14 changes: 10 additions & 4 deletions misc/updatesql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/local/bin/cbsd
#v10.1.2
#v10.3.0
# Script for create or upgrade SQLite tables by known scheme from sh file
# Usage: ./updatesql <dbfile> <schema_file>
# Usage: ./updatesql <dbfile> <schema_file> <tablename>

create_table()
{
Expand Down Expand Up @@ -36,13 +36,14 @@ update_table()
}

## MAIN ##
if [ $# -ne 2 ]; then
echo "Usage $0 <dbfile> <path_to_schema>"
if [ $# -ne 3 ]; then
echo "Usage $0 <dbfile> <path_to_schema> <tablename>"
exit 0
fi

MYFILE=${1}
SCHEMA=${2}
MYTABLE=${3}

[ ! -f ${MYFILE} ] && /usr/bin/touch ${MYFILE}
/bin/chmod 0660 ${MYFILE} && /usr/sbin/chown ${cbsduser}:${cbsduser} ${MYFILE}
Expand All @@ -54,5 +55,10 @@ fi

. ${SCHEMA}

if [ -z "${MYTABLE}" ]; then
echo "No MYTABLE variable"
exit 1
fi

create_table
update_table
2 changes: 0 additions & 2 deletions securecmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ bstop \
buildkernel \
buildworld \
carpcfg \
cpr \
ddns \
delete-old-libs \
geli \
getnics-by-ip \
Expand Down
2 changes: 1 addition & 1 deletion share/cbsdtaskd-taskd.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for cbsd taskd
MYTABLE="taskd"
#MYTABLE="taskd"
MYCOL="id st_time end_time user cmd status errcode owner logfile logtype notify autoflush after client_id"

# Possible time:
Expand Down
5 changes: 3 additions & 2 deletions share/forms.schema
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Default SQL scheme for DB img::temp
MYTABLE="forms"
MYCOL="idx group_id order_id param desc def cur new mandatory attr xattr type link"
#MYTABLE="forms"
MYCOL="idx mytable group_id order_id param desc def cur new mandatory attr xattr type link"

idx="INTEGER PRIMARY KEY AUTOINCREMENT"
mytable="VARCHAR(255) DEFAULT ''" # identification myself for VIEW output
group_id="INTEGER DEFAULT 1"
order_id="INTEGER DEFAULT 1"
param="TEXT DEFAULT NULL"
Expand Down
2 changes: 1 addition & 1 deletion share/forms_version.schema → share/forms_system.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for DB img::system
MYTABLE="system"
#MYTABLE="system"
MYCOL="helpername helperdesc version packages have_restart"

helpername="INTEGER DEFAULT 0"
Expand Down
10 changes: 10 additions & 0 deletions share/forms_yesno.schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Default SQL scheme for DB img::system
#MYTABLE="system"
MYCOL="id text order_id"

id="INTEGER PRIMARY KEY AUTOINCREMENT"
text="TEXT DEFAULT NULL"
order_id="INTEGER DEFAULT 0"

INITDB=""
CONSTRAINT=""
2 changes: 1 addition & 1 deletion share/local-bhyve.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/bhyve.conf

# Default SQL scheme for DB local::bhyve
MYTABLE="bhyve"
#MYTABLE="bhyve"

# MYCOL describe in bhyve.conf

Expand Down
2 changes: 1 addition & 1 deletion share/local-bhyvedsk.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/bhyvedsk.conf

# Default SQL scheme for DB local::bhyvedsk
MYTABLE="bhyvedsk"
#MYTABLE="bhyvedsk"

# MYCOL describe in bhyvedsk.conf

Expand Down
2 changes: 1 addition & 1 deletion share/local-bhyvenic.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/bhyvenic.conf

# Default SQL scheme for DB local::bhyvenic
MYTABLE="bhyvenic"
#MYTABLE="bhyvenic"

# MYCOL described in bhyvenic.conf

Expand Down
2 changes: 1 addition & 1 deletion share/local-carp.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/carp.conf

# Default SQL scheme for DB local::bhyve
MYTABLE="carp"
#MYTABLE="carp"

id="INTEGER PRIMARY KEY AUTOINCREMENT"
vhid="integer default 1"
Expand Down
2 changes: 1 addition & 1 deletion share/local-fwcounters.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for fwcounter db
MYTABLE="traffic"
#MYTABLE="traffic"
MYCOL="dt incoming outgoing"

dt="TIMESTAMP DATE DEFAULT (datetime('now','localtime')) UNIQUE PRIMARY KEY"
Expand Down
2 changes: 1 addition & 1 deletion share/local-gw.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for DB local::nics
MYTABLE="gw"
#MYTABLE="gw"
MYCOL="gw val"

gw="TEXT DEFAULT NULL UNIQUE PRIMARY KEY"
Expand Down
2 changes: 1 addition & 1 deletion share/local-jails.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for DB local::jails
MYTABLE="jails"
#MYTABLE="jails"
MYCOL="jname jid path host_hostname ip4_addr mount_devfs allow_mount allow_devfs allow_nullfs mount_fstab mkhostsfile devfs_ruleset interface \
basename slavenode baserw mount_src mount_obj mount_kernel mount_ports astart data vnet applytpl mdsize rcconf floatresolv ver arch masterhost \
exec_start exec_stop exec_poststart exec_poststop exec_prestart exec_prestop exec_master_poststart exec_master_poststop \
Expand Down
2 changes: 1 addition & 1 deletion share/local-local.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for DB local::local
MYTABLE="local"
#MYTABLE="local"
MYCOL="nodename hostname nodeip nodedescr jnameserver nodeippool natip nat_enable fbsdrepo mdtmp repo workdir ipfw_enable \
fs zfsfeat jail_interface ncpu physmem memtype disks cpumodel cpufreq kernhz sched eventtimer nics parallel stable osrelease hostarch \
vimage_feature racct sqlreplica domain platform hammerfeat"
Expand Down
2 changes: 1 addition & 1 deletion share/local-net.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for DB local::nics
MYTABLE="net"
#MYTABLE="net"
MYCOL="nic mac type media ip4 ip6 mask4 mask6 status usr1 usr2 usr3"

nic="TEXT DEFAULT NULL UNIQUE PRIMARY KEY"
Expand Down
2 changes: 1 addition & 1 deletion share/local-rctl.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/rctl.conf

# Default SQL scheme for DB local::jrctl
MYTABLE="rctl"
#MYTABLE="rctl"

# MYCOL describe in rctl.conf

Expand Down
2 changes: 1 addition & 1 deletion share/local-unconfigured.schema
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Default SQL scheme for DB local::unconfigured
MYTABLE="unconfigured"
#MYTABLE="unconfigured"
MYCOL="items"

items="text default null"
Expand Down
2 changes: 1 addition & 1 deletion share/local-virtualbox.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/virtualbox.conf

# Default SQL scheme for DB local::virtualbox
MYTABLE="virtualbox"
#MYTABLE="virtualbox"

# MYCOL describe in virtualbox.conf

Expand Down
2 changes: 1 addition & 1 deletion share/local-virtualboxdsk.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/virtualboxdsk.conf

# Default SQL scheme for DB local::virtualboxdsk
MYTABLE="virtualboxdsk"
#MYTABLE="virtualboxdsk"

# MYCOL describe in virtualboxdsk.conf

Expand Down
2 changes: 1 addition & 1 deletion share/local-virtualboxnic.schema
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ${sharedir}/virtualboxnic.conf

# Default SQL scheme for DB local::virtualboxnic
MYTABLE="virtualboxnic"
#MYTABLE="virtualboxnic"

# MYCOL described in virtualboxnic.conf

Expand Down
Loading

0 comments on commit e0c0294

Please sign in to comment.