mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-06-14 14:29:29 +00:00
lxc-create: use posix shell instead of bash
- use '[ -x /path/prog ]' instead of 'type /path/prog' - avoid getopt --longoptions - add \ at after && and || when those are at end of line - make sure condition expands to empty string if variable is empty Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com> Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
c3752c0b59
commit
e60a8164c1
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# lxc: linux Container library
|
# lxc: linux Container library
|
||||||
@ -54,16 +54,26 @@ help() {
|
|||||||
echo " $(basename $0) -t ubuntu -h" >&2
|
echo " $(basename $0) -t ubuntu -h" >&2
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
type ${templatedir}/lxc-$lxc_template 2>/dev/null
|
if [ -x ${templatedir}/lxc-$lxc_template ]; then
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo >&2
|
echo >&2
|
||||||
echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
|
echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
|
||||||
${templatedir}/lxc-$lxc_template -h
|
${templatedir}/lxc-$lxc_template -h
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
shortoptions='hn:f:t:B:'
|
usage_err() {
|
||||||
longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'
|
[ -n "$1" ] && echo "$1" >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
optarg_check() {
|
||||||
|
local opt="$1" optarg="$2"
|
||||||
|
if [ -z "$optarg" ]; then
|
||||||
|
usage_err "option '$opt' requires an argument"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
lxc_path=@LXCPATH@
|
lxc_path=@LXCPATH@
|
||||||
bindir=@BINDIR@
|
bindir=@BINDIR@
|
||||||
templatedir=@LXCTEMPLATEDIR@
|
templatedir=@LXCTEMPLATEDIR@
|
||||||
@ -73,68 +83,69 @@ fssize=500M
|
|||||||
vgname=lxc
|
vgname=lxc
|
||||||
custom_rootfs=""
|
custom_rootfs=""
|
||||||
|
|
||||||
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
while [ $# -gt 0 ]; do
|
||||||
if [ $? != 0 ]; then
|
local opt="$1"
|
||||||
usage
|
shift
|
||||||
exit 1;
|
case "$opt" in
|
||||||
fi
|
|
||||||
|
|
||||||
eval set -- "$getopt"
|
|
||||||
|
|
||||||
while true; do
|
|
||||||
case "$1" in
|
|
||||||
-h|--help)
|
-h|--help)
|
||||||
help
|
help
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
-n|--name)
|
-n|--name)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
lxc_name=$1
|
lxc_name=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-f|--config)
|
-f|--config)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
lxc_config=$1
|
lxc_config=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-t|--template)
|
-t|--template)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
lxc_template=$1
|
lxc_template=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-B|--backingstore)
|
-B|--backingstore)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
backingstore=$1
|
backingstore=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--dir)
|
--dir)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
custom_rootfs=$1
|
custom_rootfs=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--lvname)
|
--lvname)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
lvname=$1
|
lvname=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--vgname)
|
--vgname)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
vgname=$1
|
vgname=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--fstype)
|
--fstype)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
fstype=$1
|
fstype=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--fssize)
|
--fssize)
|
||||||
shift
|
optarg_check $opt "$1"
|
||||||
fssize=$1
|
fssize=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break;;
|
break;;
|
||||||
|
-?)
|
||||||
|
usage_err "unknown option '$opt'"
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
# split opts -abc into -a -b -c
|
||||||
|
set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"
|
|||||||
|
|
||||||
if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
|
if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
|
||||||
# if no backing store was given, then see if btrfs would work
|
# if no backing store was given, then see if btrfs would work
|
||||||
if which btrfs >/dev/null 2>&1 &&
|
if which btrfs >/dev/null 2>&1 && \
|
||||||
btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
|
btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
|
||||||
backingstore="btrfs"
|
backingstore="btrfs"
|
||||||
else
|
else
|
||||||
@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [ $backingstore = "lvm" ]; then
|
if [ "$backingstore" = "lvm" ]; then
|
||||||
umount $rootfs
|
umount $rootfs
|
||||||
lvremove -f $rootdev
|
lvremove -f $rootdev
|
||||||
elif [ $backingstore = "btrfs" ]; then
|
elif [ "$backingstore" = "btrfs" ]; then
|
||||||
btrfs subvolume delete "$rootfs"
|
btrfs subvolume delete "$rootfs"
|
||||||
fi
|
fi
|
||||||
${bindir}/lxc-destroy -n $lxc_name
|
${bindir}/lxc-destroy -n $lxc_name
|
||||||
@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then
|
|||||||
template_path=${templatedir}/lxc-$lxc_template
|
template_path=${templatedir}/lxc-$lxc_template
|
||||||
fi
|
fi
|
||||||
|
|
||||||
type $template_path 2>/dev/null
|
if ! [ -x "$template_path" ]; then
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "$(basename $0): unknown template '$lxc_template'" >&2
|
echo "$(basename $0): unknown template '$lxc_template'" >&2
|
||||||
cleanup
|
cleanup
|
||||||
fi
|
fi
|
||||||
@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then
|
|||||||
echo "'$lxc_template' template installed"
|
echo "'$lxc_template' template installed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $backingstore = "lvm" ]; then
|
if [ "$backingstore" = "lvm" ]; then
|
||||||
echo "Unmounting LVM"
|
echo "Unmounting LVM"
|
||||||
umount $rootfs
|
umount $rootfs
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user