diff options
| author | Your Name <you@example.com> | 2024-12-22 19:03:49 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2024-12-22 19:03:49 +0800 |
| commit | f7f159a04671690786de2f84e34046c103521d58 (patch) | |
| tree | 22b45e904c1aa6800250ec6e998d0022fd018ade /others/vm3/test.sh | |
| parent | 2916e3eff503473f6bf8b90e0921b0ccd347166f (diff) | |
vm.shupdate
Diffstat (limited to 'others/vm3/test.sh')
| -rwxr-xr-x | others/vm3/test.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/others/vm3/test.sh b/others/vm3/test.sh new file mode 100755 index 0000000..0dafc23 --- /dev/null +++ b/others/vm3/test.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Default values +vcpu=2 +ram_gb=4 +disk_gb=20 + +# Parse named arguments +while [[ $# -gt 0 ]]; do + case $1 in + --vcpu) + vcpu="$2" + shift 2 + ;; + --ram) + ram_gb="$2" + shift 2 + ;; + --disk-size) + disk_gb="$2" + shift 2 + ;; + *) + # Handle positional arguments (vmname and os) + if [ -z "$vmname" ]; then + vmname="$1" + elif [ -z "$os" ]; then + os="$1" + else + echo "Unknown argument: $1" + exit 1 + fi + shift + ;; + esac +done + +# Check mandatory arguments +if [ -z "$vmname" ] || [ -z "$os" ]; then + echo "Usage: $0 <vm-name> <os> [--vcpu N] [--ram N] [--disk-size N]" + exit 1 +fi + +# Now you can use the variables +echo "VM Name: $vmname" +echo "OS: $os" +echo "VCPU: $vcpu" +echo "RAM: $ram_gb GB" +echo "Disk: $disk_gb GB" |
