Skip to content

Commit

Permalink
user/lxc: fix lxc-create template scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryLhm committed Dec 31, 2024
1 parent fa519ae commit 7e21bae
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
11 changes: 11 additions & 0 deletions user/lxc/patches/lxc-busybox.in.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/templates/lxc-busybox.in
+++ b/templates/lxc-busybox.in
@@ -260,7 +260,7 @@ EOF
return 0
}

-if ! options=$(getopt -o hp:n: -l help,rootfs:,path:,name:,mapped-uid:,mapped-gid:,busybox-path: -- "$@"); then
+if ! options=$(ugetopt -o hp:n: -l help,rootfs:,path:,name:,mapped-uid:,mapped-gid:,busybox-path: -- "$@"); then
usage
exit 1
fi
48 changes: 48 additions & 0 deletions user/lxc/patches/lxc-download.in.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--- a/templates/lxc-download.in
+++ b/templates/lxc-download.in
@@ -137,7 +137,7 @@ EOF
return 0
}

-if ! options=$(getopt -o d:r:a:hl -l dist:,release:,arch:,help,list,variant:,\
+if ! options=$(ugetopt -o d:r:a:hl -l dist:,release:,arch:,help,list,variant:,\
server:,flush-cache,force-cache,verbose,name:,path:,\
rootfs:,mapped-uid:,mapped-gid: -- "$@"); then
usage
@@ -413,10 +413,10 @@ if [ ! -e "${configfile}" ]; then
fi

## Extract all the network config entries
-sed -i -e "/lxc.net.0/{w ${LXC_PATH}/config-network" -e "d}" "${LXC_PATH}/config"
+gsed -i -e "/lxc.net.0/{w ${LXC_PATH}/config-network" -e "d}" "${LXC_PATH}/config"

## Extract any other config entry
-sed -i -e "/lxc./{w ${LXC_PATH}/config-auto" -e "d}" "${LXC_PATH}/config"
+gsed -i -e "/lxc./{w ${LXC_PATH}/config-auto" -e "d}" "${LXC_PATH}/config"

## Append the defaults
{
@@ -471,17 +471,17 @@ OLD_IFS=${IFS}
IFS=";"
for file in ${TEMPLATE_FILES}; do
[ ! -f "${file}" ] && continue
- sed -i "s#LXC_NAME#${LXC_NAME}#g" "${file}"
- sed -i "s#LXC_PATH#${LXC_PATH}#g" "${file}"
- sed -i "s#LXC_ROOTFS#${LXC_ROOTFS}#g" "${file}"
- sed -i "s#LXC_TEMPLATE_CONFIG#${LXC_TEMPLATE_CONFIG}#g" "${file}"
- sed -i "s#LXC_HOOK_DIR#${LXC_HOOK_DIR}#g" "${file}"
+ gsed -i "s#LXC_NAME#${LXC_NAME}#g" "${file}"
+ gsed -i "s#LXC_PATH#${LXC_PATH}#g" "${file}"
+ gsed -i "s#LXC_ROOTFS#${LXC_ROOTFS}#g" "${file}"
+ gsed -i "s#LXC_TEMPLATE_CONFIG#${LXC_TEMPLATE_CONFIG}#g" "${file}"
+ gsed -i "s#LXC_HOOK_DIR#${LXC_HOOK_DIR}#g" "${file}"
done
IFS=${OLD_IFS}

# prevent mingetty from calling vhangup(2) since it fails with userns on CentOS / Oracle
if [ -f "${LXC_ROOTFS}/etc/init/tty.conf" ]; then
- sed -i 's|mingetty|mingetty --nohangup|' "${LXC_ROOTFS}/etc/init/tty.conf"
+ gsed -i 's|mingetty|mingetty --nohangup|' "${LXC_ROOTFS}/etc/init/tty.conf"
fi

if [ -n "${LXC_MAPPED_UID}" ] && [ "${LXC_MAPPED_UID}" != "-1" ]; then
55 changes: 55 additions & 0 deletions user/lxc/patches/lxc-local.in.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--- a/templates/lxc-local.in
+++ b/templates/lxc-local.in
@@ -72,7 +72,7 @@ EOF
}

# Show usage and exit if invalid arguments are passed
-if ! options=$(getopt -o hm:f: -l help,metadata:,fstree:,no-dev:,name:,path:,rootfs:,mapped-uid:,mapped-gid: -- "$@"); then
+if ! options=$(ugetopt -o hm:f: -l help,metadata:,fstree:,no-dev:,name:,path:,rootfs:,mapped-uid:,mapped-gid: -- "$@"); then
usage
exit 1
fi
@@ -184,7 +184,7 @@ extract_config() {
# The config will be merged later.

# Extract all the network config entries
- sed -i -e "/lxc.net.0/{w ${LXC_PATH}/config-network" -e "d}" "${LXC_PATH}/config"
+ gsed -i -e "/lxc.net.0/{w ${LXC_PATH}/config-network" -e "d}" "${LXC_PATH}/config"

if [ -e "${LXC_PATH}/config-network" ]; then
echo "Extracted network config to: ${LXC_PATH}/config-network"
@@ -192,7 +192,7 @@ extract_config() {
fi

# Extract any other config entry
- sed -i -e "/lxc./{w ${LXC_PATH}/config-extra" -e "d}" "${LXC_PATH}/config"
+ gsed -i -e "/lxc./{w ${LXC_PATH}/config-extra" -e "d}" "${LXC_PATH}/config"

if [ -e "${LXC_PATH}/config-extra" ]; then
echo "Extracted additional config to: ${LXC_PATH}/config-extra"
@@ -342,11 +342,11 @@ replace_template_vars() {
for file in ${TEMPLATE_FILES}; do
[ ! -f "${file}" ] && continue

- sed -i "s#LXC_NAME#${LXC_NAME}#g" "${file}"
- sed -i "s#LXC_PATH#${LXC_PATH}#g" "${file}"
- sed -i "s#LXC_ROOTFS#${LXC_ROOTFS}#g" "${file}"
- sed -i "s#LXC_TEMPLATE_CONFIG#${LXC_TEMPLATE_CONFIG}#g" "${file}"
- sed -i "s#LXC_HOOK_DIR#${LXC_HOOK_DIR}#g" "${file}"
+ gsed -i "s#LXC_NAME#${LXC_NAME}#g" "${file}"
+ gsed -i "s#LXC_PATH#${LXC_PATH}#g" "${file}"
+ gsed -i "s#LXC_ROOTFS#${LXC_ROOTFS}#g" "${file}"
+ gsed -i "s#LXC_TEMPLATE_CONFIG#${LXC_TEMPLATE_CONFIG}#g" "${file}"
+ gsed -i "s#LXC_HOOK_DIR#${LXC_HOOK_DIR}#g" "${file}"
done
IFS=${OLD_IFS}
}
@@ -355,7 +355,7 @@ fix_tty() {
# prevent mingetty from calling vhangup(2) since it fails with userns on CentOS / Oracle
if [ -f "${LXC_ROOTFS}/etc/init/tty.conf" ]; then
echo "Patching ${LXC_ROOTFS}/etc/init/tty.conf to prevent mingetty from calling vhangup."
- sed -i 's|mingetty|mingetty --nohangup|' "${LXC_ROOTFS}/etc/init/tty.conf"
+ gsed -i 's|mingetty|mingetty --nohangup|' "${LXC_ROOTFS}/etc/init/tty.conf"
fi
}

11 changes: 11 additions & 0 deletions user/lxc/patches/lxc-oci.in.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/templates/lxc-oci.in
+++ b/templates/lxc-oci.in
@@ -250,7 +250,7 @@ EOF
return 0
}

-if ! options=$(getopt -o u:h -l help,url:,username:,password:,no-cache,dhcp,name:,path:,rootfs:,mapped-uid:,mapped-gid:,mount-helper: -- "$@"); then
+if ! options=$(ugetopt -o u:h -l help,url:,username:,password:,no-cache,dhcp,name:,path:,rootfs:,mapped-uid:,mapped-gid:,mount-helper: -- "$@"); then
usage
exit 1
fi
2 changes: 2 additions & 0 deletions user/lxc/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"openssl-devel",
]
depends = [
"ugetopt",
"gsed",
"xz",
"wget2",
]
Expand Down

0 comments on commit 7e21bae

Please sign in to comment.