mirror of
https://codeberg.org/vegvisir/install.git
synced 2025-09-14 00:33:41 +02:00
feat: add optional CLI arguments (#5)
This PR makes headless installation possible by passing optional named arguments to the install script. Reviewed-on: https://codeberg.org/vegvisir/install/pulls/5
This commit is contained in:
parent
0f23cf1e16
commit
7484c2370b
2 changed files with 83 additions and 19 deletions
35
README.md
35
README.md
|
@ -1,13 +1,34 @@
|
||||||
# Vegvisir installer
|
# Vegvisir installer
|
||||||
This script will automatically install and configure Vegvisir from in a fresh git repository.
|
Run this script from a git repository to automatically install and configure Vegvisir as a git submodule to your project.
|
||||||
|
|
||||||
## Important
|
> [!IMPORTANT]
|
||||||
The script will only run on Linux environments with `coreutils` installed (for now).
|
> The script will only run in environments with Bash and `coreutils` installed (for now).
|
||||||
|
|
||||||
# Get started
|
# Get started
|
||||||
1. Create a repository for your website
|
1. Create a git repository for your project.
|
||||||
2. Run this command from the root directory of your local repository
|
2. Run this command from the root directory of your local repository.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -fsSL https://href.vlw.se/vegvisir/install | bash
|
curl -fsSL https://codeberg.org/vegvisir/install/raw/branch/master/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
You can pass optional named arguments to this script for headless installation of Vegvisir.
|
||||||
|
|
||||||
|
## `--install` - Installation directory
|
||||||
|
```sh
|
||||||
|
./install.sh --install="/path/to/project"
|
||||||
|
```
|
||||||
|
Pass an `--install` argument with a value of a directory Vegvisir should consider its [`root_path`](https://vegvisir.vlw.se/docs/Reference/Env#root_path).
|
||||||
|
|
||||||
|
## `--override` - Overwrite configuration files
|
||||||
|
```sh
|
||||||
|
./install.sh --overwrite=y
|
||||||
|
```
|
||||||
|
Pass `--overwrite=y` to replace existing Vegvisir configuration files.
|
||||||
|
|
||||||
|
## `--example` - Generate example website
|
||||||
|
```sh
|
||||||
|
./install.sh --example=n
|
||||||
|
```
|
||||||
|
Pass `--overwrite=n` to disable generation of an example website after installation.
|
67
install.sh
67
install.sh
|
@ -1,7 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Get the current working directory
|
# Initialize variables
|
||||||
cwd=$(pwd)
|
cwd=""
|
||||||
|
install=""
|
||||||
|
example=""
|
||||||
|
overwrite=""
|
||||||
|
|
||||||
echo_err() {
|
echo_err() {
|
||||||
echo "!! -> $1"
|
echo "!! -> $1"
|
||||||
|
@ -33,7 +36,7 @@ check_sys_depend() {
|
||||||
|
|
||||||
install_vegvisir() {
|
install_vegvisir() {
|
||||||
if ! [ -d ".git" ] ; then
|
if ! [ -d ".git" ] ; then
|
||||||
echo_err "Not in a git repository"
|
echo_err "Installation aborted: '$cwd' is not a git repository"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -61,7 +64,7 @@ configure_vegvisir() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# A configuration file already exists
|
# A configuration file already exists
|
||||||
if [ -f "vegvisir/.env.ini" ] ; then
|
if [[ -f "vegvisir/.env.ini" && "$overwrite" != "y" ]] ; then
|
||||||
echo "A Vegvisir configuration file already exists at: ${cwd}/vegvisir/.env.ini"
|
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
|
read -p "Do you want to overwrite this file? (y/n): " choice </dev/tty
|
||||||
|
|
||||||
|
@ -152,29 +155,69 @@ generate_example_website() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
# Get the current working directory
|
||||||
|
cwd=$(pwd)
|
||||||
|
|
||||||
check_sys_depend
|
check_sys_depend
|
||||||
install_vegvisir
|
install_vegvisir
|
||||||
configure_vegvisir
|
configure_vegvisir
|
||||||
|
|
||||||
echo "Vegvisir has been sucessfully installed."
|
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 [[ "$example" != "n" ]]; then
|
||||||
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
read -p "Do you want to generate a simple example website to start from? (y/n): " choice </dev/tty
|
||||||
generate_example_website
|
|
||||||
|
# Check the user's response
|
||||||
|
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
||||||
|
generate_example_website
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Done! Thank you for choosing Vegvisir :)"
|
echo "Done! Thank you for choosing Vegvisir :)"
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Loop through all arguments
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $arg in
|
||||||
|
--install=*)
|
||||||
|
install="${arg#*=}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
--overwrite=*)
|
||||||
|
overwrite="${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
|
# 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
|
read -p "Do you want to proceed with the installation in this directory? (y/n): " choice </dev/tty
|
||||||
|
|
||||||
# Check the user's response
|
# Check the user's response
|
||||||
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
||||||
echo "Proceeding with the installation in ${cwd}..."
|
echo "Proceeding with the installation in $(pwd)..."
|
||||||
main
|
main
|
||||||
else
|
else
|
||||||
echo "Installation aborted."
|
echo "Installation aborted."
|
||||||
fi
|
fi
|
Loading…
Add table
Reference in a new issue