swmodd: Add support for EnvVariable in InstallDU command

This commit is contained in:
Vivek Kumar Dutta 2024-11-20 19:13:25 +05:30
parent c56cb30b3b
commit 8366ad85e7
3 changed files with 28 additions and 6 deletions

View file

@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=swmodd PKG_NAME:=swmodd
PKG_VERSION:=2.5.17 PKG_VERSION:=2.5.18
LOCAL_DEV:=0 LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1) ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/lcm/swmodd.git PKG_SOURCE_URL:=https://dev.iopsys.eu/lcm/swmodd.git
PKG_SOURCE_VERSION:=f14859ab9a5e829ebbe9b3736c2677ee7e7c36cf PKG_SOURCE_VERSION:=c50b1deb62bc931f350b799a65a5ac3aa88352dd
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip PKG_MIRROR_HASH:=skip
endif endif

View file

@ -56,7 +56,7 @@ configure_lxc_container() {
} }
configure_crun_container() { configure_crun_container() {
local name type autostart du_status requested_state url username password capability local name type autostart du_status requested_state url username password capability envlist
local BRIDGE BUNDLE BOOT PERM local BRIDGE BUNDLE BOOT PERM
local RUNNER="/etc/swmodd/run.sh" local RUNNER="/etc/swmodd/run.sh"
@ -74,6 +74,12 @@ configure_crun_container() {
config_get username "${1}" username "" config_get username "${1}" username ""
config_get password "${1}" password "" config_get password "${1}" password ""
config_get capability "${1}" capability "" config_get capability "${1}" capability ""
config_get envlist "${1}" env_var ""
if [ -n "${envlist}" ]; then
envlist="${envlist// /;}"
fi
if [ -n "${capability}" ]; then if [ -n "${capability}" ]; then
PERM="-p ${capability// /,}" PERM="-p ${capability// /,}"
fi fi
@ -152,7 +158,7 @@ configure_crun_container() {
if [ "${BOOT}" -eq "1" ]; then if [ "${BOOT}" -eq "1" ]; then
if [ "${autostart}" -eq 1 ]; then if [ "${autostart}" -eq 1 ]; then
${RUNNER} -U -b "${BUNDLE}" -n "${name}" ${PERM} ${RUNNER} -U -b "${BUNDLE}" -n "${name}" -e "${envlist}" ${PERM}
result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description") result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description")
if [ "${result}" != "null" ]; then if [ "${result}" != "null" ]; then
uci_set ocicontainer "${1}" description "${result}" uci_set ocicontainer "${1}" description "${result}"
@ -185,7 +191,7 @@ configure_crun_container() {
${RUNNER} -u -n "${name}" -i "${BRIDGE}" ${PERM} ${RUNNER} -u -n "${name}" -i "${BRIDGE}" ${PERM}
crun resume "${name}" crun resume "${name}"
else else
${RUNNER} -U -b "${BUNDLE}" -n "${name}" ${PERM} ${RUNNER} -U -b "${BUNDLE}" -n "${name}" -e "${envlist}" ${PERM}
result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description") result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description")
if [ "${result}" != "null" ]; then if [ "${result}" != "null" ]; then
uci_set ocicontainer "${1}" description "${result}" uci_set ocicontainer "${1}" description "${result}"

View file

@ -144,6 +144,20 @@ update_config_json() {
json_add_string hostname "${NAME}" json_add_string hostname "${NAME}"
fi fi
if [ -n "${ENVLIST}" ]; then
json_select process
json_get_values preenv env
json_select env
for i in ${ENVLIST//;/ }; do
key="$(echo $i|cut -d= -f1)"
if [[ "${preenv}" != *"${key}="* ]]; then
json_add_string "" "${i}"
fi
done
json_select ..
json_select ..
fi
# Update cabalities # Update cabalities
if [ -n "${PERM}" ]; then if [ -n "${PERM}" ]; then
log "Updating Permission in the json ..." log "Updating Permission in the json ..."
@ -264,10 +278,11 @@ clean=0
net_update=0 net_update=0
update_json=0 update_json=0
PERM="" PERM=""
ENVLIST=""
log "## Runner [$@] ##" log "## Runner [$@] ##"
while getopts b:n:i:r:l:t:p:cuU options while getopts b:n:i:r:l:t:p:e:cuU options
do do
case "${options}" in case "${options}" in
b) BUNDLE=${OPTARG};; b) BUNDLE=${OPTARG};;
@ -278,6 +293,7 @@ do
r) REGURL=${OPTARG};; r) REGURL=${OPTARG};;
l) LOGIN=${OPTARG};; l) LOGIN=${OPTARG};;
t) TIMEOUT=${OPTARG};; t) TIMEOUT=${OPTARG};;
e) ENVLIST=${OPTARG};;
u) net_update=1;; u) net_update=1;;
U) update_json=1;; U) update_json=1;;
*) log "Invalid options";; *) log "Invalid options";;