swmodd: uci-default scrip to migrate lxc-auto config

In release-6.5 lxc-auto used for autostart of lxc containers, this uci-default
migration script shall migrate the autostart info to the configured path.
This commit is contained in:
suvendhu 2023-06-05 13:24:00 +05:30 committed by Vivek Kumar Dutta
parent 81bfe4cc1b
commit 6e3490b985
No known key found for this signature in database
GPG key ID: 65C818099F37097D
2 changed files with 51 additions and 3 deletions

View file

@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=swmodd
PKG_VERSION:=2.2.4
PKG_VERSION:=2.2.5
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
@ -76,23 +76,24 @@ define Package/swmodd/install
$(INSTALL_DIR) $(1)/usr/lib/bbfdm
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/usr/share/swmodd/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/init.d/swmodd $(1)/etc/init.d/swmodd
$(INSTALL_BIN) ./files/etc/config/swmodd $(1)/etc/config/swmodd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/swmodd $(1)/usr/sbin/swmodd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/libswmodd.so $(1)/usr/lib/bbfdm/libswmodd.so
$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/opkg_offline.sh $(1)/usr/share/swmodd/opkg_offline
$(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-bundle-path $(1)/etc/uci-defaults/01-fix-bundle-path
ifeq ($(CONFIG_PACKAGE_liblxc),y)
$(INSTALL_DIR) $(1)/usr/share/lxc/templates/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/templates/lxc-iopsys $(1)/usr/share/lxc/templates/lxc-iopsys
$(INSTALL_BIN) ./files/etc/uci-defaults/02-migrate-lxc $(1)/etc/uci-defaults/02-migrate-lxc
endif
ifeq ($(CONFIG_PACKAGE_crun),y)
$(INSTALL_DIR) $(1)/etc/swmodd
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/swmodd/run.sh $(1)/etc/swmodd/run.sh
$(INSTALL_BIN) ./files/etc/init.d/crun $(1)/etc/init.d/crun
$(INSTALL_BIN) ./files/etc/config/crun $(1)/etc/config/crun
$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/crun_create $(1)/usr/sbin/crun_create
$(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-bundle-path $(1)/etc/uci-defaults/01-fix-bundle-path
endif
endef

View file

@ -0,0 +1,47 @@
#!/bin/sh
. /lib/functions.sh
config_change=0
migrate_lxc() {
config_get name "${1}" name ""
if [ -z "${name}" ]; then
return 0;
fi
# Now lets check if already present in lxccontainer
exist=$(uci -q -c "${2}" show lxccontainer | grep ".name='$name'")
if [ -z "${exist}" ]; then
# Not present, need to migrate
sec=$(uci -q -c "${2}" add lxccontainer container)
if [ -n "${sec}" ]; then
uci -q -c "${2}" set lxccontainer."${sec}".name="${name}"
uci -q -c "${2}" set lxccontainer."${sec}".type='lxc'
uci -q -c "${2}" set lxccontainer."${sec}".autostart='1'
uci -q -c "${2}" set lxccontainer."${sec}".timeout='300'
config_change=1
fi
fi
}
config_load swmodd
config_get lxc_bundle globals lxc_bundle_root ""
if [ -z "${lxc_bundle}" ]; then
return 0
fi
if [ ! -d "${lxc_bundle}" ]; then
return 0
fi
touch "${lxc_bundle}"/lxccontainer
config_load lxc-auto
config_foreach migrate_lxc container "${lxc_bundle}"
if [ $config_change -eq 1 ]; then
uci -q -c "${lxc_bundle}" commit lxccontainer
fi