mirror of
https://codeberg.org/vegvisir/install.git
synced 2025-09-13 16:23:42 +02:00
Reviewed-on: https://codeberg.org/vegvisir/install/pulls/3 Co-authored-by: vlw <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
180 lines
No EOL
4.6 KiB
Bash
Executable file
180 lines
No EOL
4.6 KiB
Bash
Executable file
#!/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 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 "Not in a git repository"
|
|
exit 1
|
|
fi
|
|
|
|
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 </dev/tty
|
|
|
|
# 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=(
|
|
"<!DOCTYPE html>"
|
|
"<html lang="en">"
|
|
"<head>"
|
|
" <meta charset="UTF-8">"
|
|
" <title>Welcome to Vegvisir</title>"
|
|
"</head>"
|
|
"<body>"
|
|
" <?php // Replace this comment with elements you wish to keep loaded between pages ?>"
|
|
" "
|
|
" <vv-shell></vv-shell>"
|
|
" "
|
|
" <?= VV::init() ?>"
|
|
"</body>"
|
|
"</html>"
|
|
)
|
|
|
|
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=(
|
|
"<h1>Welcome to Vegvisir!</h1>"
|
|
"<p>This file 'public/index.php' is your website's main landing page</p>"
|
|
"<p><a href='/another-page'>Click here</a> to soft-navigate to another page on this website</p>"
|
|
)
|
|
|
|
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=(
|
|
"<h1>And this is another page</h1>"
|
|
"<p>This is another page on your website 'public/another-page.php'</p>"
|
|
"<p><a href='/'>Click here</a> to go back to the main landingpage '/'</p>"
|
|
"<p>Enjoy! <a href='https://codeberg.org/vegvisir/vegvisir/issues'>Reach out on Codeberg</a> if you experience any problems.</p>"
|
|
"<p>Thank you for choosing Vegvisir!</p>"
|
|
)
|
|
|
|
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 </dev/tty
|
|
|
|
# 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 </dev/tty
|
|
|
|
# Check the user's response
|
|
if [[ "$choice" == "y" || "$choice" == "Y" ]] ; then
|
|
echo "Proceeding with the installation in ${cwd}..."
|
|
main
|
|
else
|
|
echo "Installation aborted."
|
|
fi |