Merge pull request #311 from postster/postster/tarball-strip-components-option

lxc-template: add parameter strip-components
This commit is contained in:
Fabio Rehm 2014-09-22 22:44:29 -03:00
commit 46640fbd3d

View file

@ -33,6 +33,7 @@ LXC_PATH=
LXC_ROOTFS= LXC_ROOTFS=
LXC_TARBALL= LXC_TARBALL=
LXC_CONFIG= LXC_CONFIG=
LXC_STRIP_COMPONENTS=2
usage() { usage() {
cat <<EOF cat <<EOF
@ -51,11 +52,12 @@ LXC internal arguments (do not pass manually!):
[ --rootfs <rootfs> ]: The path to the container's rootfs [ --rootfs <rootfs> ]: The path to the container's rootfs
[ --mapped-uid <map> ]: A uid map (user namespaces) [ --mapped-uid <map> ]: A uid map (user namespaces)
[ --mapped-gid <map> ]: A gid map (user namespaces) [ --mapped-gid <map> ]: A gid map (user namespaces)
[ --strip-components <num> ]: Number of path components to strip from tarball
EOF EOF
return 0 return 0
} }
options=$(getopt -o h -l tarball:,config:,help:,name:,path:,rootfs:,mapped-uid:,mapped-gid: -- "$@")SS options=$(getopt -o h -l tarball:,config:,help:,name:,path:,rootfs:,mapped-uid:,mapped-gid:,strip-components: -- "$@")SS
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
usage $(basename $0) usage $(basename $0)
@ -74,6 +76,7 @@ do
--rootfs) LXC_ROOTFS=$2; shift 2;; --rootfs) LXC_ROOTFS=$2; shift 2;;
--mapped-uid) LXC_MAPPED_UID=$2; shift 2;; --mapped-uid) LXC_MAPPED_UID=$2; shift 2;;
--mapped-gid) LXC_MAPPED_GID=$2; shift 2;; --mapped-gid) LXC_MAPPED_GID=$2; shift 2;;
--strip-components) LXC_STRIP_COMPONENTS=$2; shift 2;;
*) break;; *) break;;
esac esac
done done
@ -121,7 +124,7 @@ mkdir -p /var/lock/subsys
fi fi
mkdir -p ${LXC_ROOTFS} mkdir -p ${LXC_ROOTFS}
(cd ${LXC_ROOTFS} && tar xfz ${LXC_TARBALL} --strip-components=2) (cd ${LXC_ROOTFS} && tar xfz ${LXC_TARBALL} --strip-components=${LXC_STRIP_COMPONENTS})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to extract rootfs" echo "Failed to extract rootfs"
exit 1 exit 1