-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vmctl-init-conf: add initialization script support
To initialize a configuration folder with vmctl command in PATH and all examples. If the configuration folder exists, just ensure vmctl command is available. vmctl$ source vmctl-init-conf confdir vmctl/confdir$ vmctl --help Next time, repeating the first command would only navigate the user to the confdir. Provide guidance of this new script in README. Signed-off-by: Daniel Gomez <[email protected]>
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-3.0-or-late | ||
# | ||
# Run source vmctl-init-conf <confdir> | ||
|
||
usage() { | ||
echo "Usage: source $0 <confdir>" | ||
} | ||
|
||
if [ -z "$1" ]; then | ||
usage | ||
return 2 | ||
fi | ||
|
||
if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then | ||
usage | ||
return 2 | ||
fi | ||
|
||
CONFDIR="$1" | ||
if [ -n "${BASH_SOURCE[0]}" ]; then | ||
VMCTLDIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") | ||
else | ||
VMCTLDIR=$(dirname "$(realpath "$0")") | ||
fi | ||
EXAMPLESDIR=$VMCTLDIR/examples/vm | ||
|
||
# Create CONFDIR if necessary | ||
if [ ! -d "$CONFDIR" ]; then | ||
mkdir --parent "$CONFDIR" | ||
if [ $? -ne 0 ]; then | ||
return 1 | ||
fi | ||
cp --recursive --verbose "$EXAMPLESDIR"/* "$CONFDIR" | ||
if [ $? -ne 0 ]; then | ||
return 1 | ||
fi | ||
fi | ||
|
||
# Ensure vmctl is available | ||
if ! command -v vmctl &> /dev/null; then | ||
# Add the parent directory of this script to PATH | ||
export PATH="$VMCTLDIR:$PATH" | ||
if ! command -v vmctl &> /dev/null; then | ||
echo "Error: vmctl tool is still not found after adding $VMCTLDIR to PATH." | ||
return 1 | ||
fi | ||
fi | ||
|
||
cd $CONFDIR | ||
vmctl --help |