#!/bin/bash # Initialize variables cwd="" dir="" install="" example="" overwrite="" echo_err() { echo "!! -> $1" } # Bail out from an error with a message asking the user to report the incident exit_report() { echo_err "Please report this error at: https://codeberg.org/vegvisir/install/issues" exit 1 } # Make sure we have all the system packages we need to proceed with the installation check_sys_depend() { local valid=true local packages=("git" "composer") for package in "${packages[@]}" ; do if ! dpkg -l | grep -qw "ii ${package}" ; then echo_err "Package '${package}' is not installed." valid=false fi done # Bail out if any required package is missing if [ "$valid" = false ] ; then exit 1 fi } install_vegvisir() { if ! [ -d ".git" ] ; then echo_err "Installation aborted: '$cwd' is not a git repository" exit 1 fi # Download and install the Vegvisir repository if [[ "$install" != "n" ]]; then if ! [ -d "vegvisir" ] ; then git submodule add https://codeberg.org/vegvisir/vegvisir fi # Update submodules git submodule update --init --recursive fi # Install dependencies with composer (cd vegvisir && composer install --classmap-authoritative) # Bail out if composer didn't create a vendor folder if ! [ -d "vegvisir/vendor" ] ; then echo_err "Something went wrong with the installation." # Script was not run with the install flag disabled, this is probably a bug if [[ "$install" != "n" ]]; then exit_report fi echo_err "Make sure you have cloned the Vegvisir repository. Or run without '--install=n'." exit 1 fi } configure_vegvisir() { if ! [ -d "vegvisir" ] ; then echo_err "Vegvisir is not installed." exit_report fi # A configuration file already exists if [[ -f "vegvisir/.env.ini" ]] ; then if ! [[ -n "$overwrite" ]]; then echo "A Vegvisir configuration file already exists at: ${cwd}/vegvisir/.env.ini" read -p "Do you want to overwrite this file? (y/n): " overwrite > vegvisir/.env.ini done } generate_example_website() { if ! [ -d "public" ] ; then mkdir public fi # --- Create shell file --- local shell_page=( "" "" "" " " " Welcome to Vegvisir" "" "" " " " " " " " " " " "" "" ) if ! [ -f "public/shell.php" ] ; then for line in "${shell_page[@]}" ; do echo "${line}" >> public/shell.php done fi # --- Create index page --- local index_page=( "

Welcome to Vegvisir!

" "

This file 'public/index.php' is your website's main landing page

" "

Click here to soft-navigate to another page on this website

" ) if ! [ -f "public/index.php" ] ; then for line in "${index_page[@]}" ; do echo "${line}" >> public/index.php done fi # --- Create example second page --- local another_page=( "

And this is another page

" "

This is another page on your website 'public/another-page.php'

" "

Click here to go back to the main landingpage '/'

" "

Enjoy! Reach out on Codeberg if you experience any problems.

" "

Thank you for choosing Vegvisir!

" ) if ! [ -f "public/another-page.php" ] ; then for line in "${another_page[@]}" ; do echo "${line}" >> public/another-page.php done fi } main() { # Get the current working directory cwd=$(pwd) check_sys_depend install_vegvisir configure_vegvisir echo "Vegvisir has been sucessfully installed." if [[ "$example" != "n" ]]; then read -p "Do you want to generate a simple example website to start from? (y/n): " choice