#!/bin/bash # Get the current working directory cwd=$(pwd) 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 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 required packages are missing if [ "$valid" = false ] ; then exit 1 fi } install_vegvisir() { if ! [ -d "vegvisir" ] ; then git submodule add https://codeberg.org/vegvisir/vegvisir fi # Update submodules git submodule update --init --recursive # 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." exit_report 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 echo "A Vegvisir configuration file already exists at: ${cwd}/vegvisir/.env.ini" read -p "Do you want to overwrite this file? (y/n): " choice # Check the user's response if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then echo "Removing existing Vegvisir configuration and proceeding with the installation in ${cwd}..." rm vegvisir/.env.ini else echo "Installation aborted." exit 1 fi fi local config=( "; This config file was generated automatically by https://codeberg.org/vegvisir/install" "; Refer to '.env.example.ini' or https://vegvisir.vlw.se/docs/Reference/Env for more information" "root_path = '${cwd}'" "shell_page = 'public/shell'" "public_path = 'public/'" "worker_magic_pathname = '/__vvnavwrkr'" "rfc_4288_url = 'https://raw.githubusercontent.com/apache/httpd/refs/heads/trunk/docs/conf/mime.types'" ) for line in "${config[@]}" ; do echo "${line}" >> 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() { 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 # Check the user's response if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then generate_example_website fi echo "Done! Thank you for choosing Vegvisir :)" } # Prompt the user for confirmation echo "You are currently in: ${cwd}" read -p "Do you want to proceed with the installation in this directory? (y/n): " choice # Check the user's response if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then echo "Proceeding with the installation in ${cwd}..." main else echo "Installation aborted." fi