feat: add optional cli args

This commit is contained in:
Victor Westerlund 2025-08-07 06:28:07 +02:00
parent 0f23cf1e16
commit faf31fc9ee
Signed by: vlw
GPG key ID: D0AD730E1057DFC6

View file

@ -1,7 +1,10 @@
#!/bin/bash
# Get the current working directory
cwd=$(pwd)
# Initialize variables
cwd=""
install=""
example=""
override=""
echo_err() {
echo "!! -> $1"
@ -33,7 +36,7 @@ check_sys_depend() {
install_vegvisir() {
if ! [ -d ".git" ] ; then
echo_err "Not in a git repository"
echo_err "Installation aborted: '$cwd' is not a git repository"
exit 1
fi
@ -61,7 +64,7 @@ configure_vegvisir() {
fi
# A configuration file already exists
if [ -f "vegvisir/.env.ini" ] ; then
if [[ -f "vegvisir/.env.ini" && "$override" != "y" ]] ; then
echo "A Vegvisir configuration file already exists at: ${cwd}/vegvisir/.env.ini"
read -p "Do you want to overwrite this file? (y/n): " choice </dev/tty
@ -152,29 +155,69 @@ generate_example_website() {
}
main() {
# Get the current working directory
cwd=$(pwd)
check_sys_depend
install_vegvisir
configure_vegvisir
echo "Vegvisir has been sucessfully installed."
read -p "Do you want to generate a simple example website to start from? (y/n): " choice </dev/tty
# Check the user's response
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
generate_example_website
if [[ "$example" != "n" ]]; then
read -p "Do you want to generate a simple example website to start from? (y/n): " choice </dev/tty
# Check the user's response
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
generate_example_website
fi
fi
echo "Done! Thank you for choosing Vegvisir :)"
exit 0
}
# Loop through all arguments
for arg in "$@"; do
case $arg in
--install=*)
install="${arg#*=}"
;;
--override=*)
override="${arg#*=}"
;;
--example=*)
example="${arg#*=}"
;;
*)
echo_err "Unknown argument: $arg"
;;
esac
done
# Start execution immediately if an install directory was passed
if [ -n "$install" ]; then
if ! [ -d "$install" ]; then
echo_err "Installation aborted: '$install' is not a directory"
exit 1
fi
# Move to install directory and run main
cd $install
main
fi
# Prompt the user for confirmation
echo "You are currently in: ${cwd}"
echo "You are currently in: $(pwd)"
read -p "Do you want to proceed with the installation in this directory? (y/n): " choice </dev/tty
# Check the user's response
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
echo "Proceeding with the installation in ${cwd}..."
main
echo "Proceeding with the installation in $(pwd)..."
main
else
echo "Installation aborted."
echo "Installation aborted."
fi