#!/bin/bash
set -eo pipefail
# Set locale to C.UTF-8
export "LANG=C.UTF-8"
export "LC_LOCALE=${LANG}"
# Create and cd into 'out' directory
if [ -n "${LINKGEN_TRASH_OUT_DIR}" ]; then
echo ":: Removing \"out\" directory"
rm -rf out
mkdir -p out
elif [ ! -d "out" ]; then
echo ":: Creating \"out\" directory"
mkdir -p out
fi
cd out
if [ -n "${LINKGEN_VERBOSE}" ]; then
echo ":: Enabling verbose output"
set -x
fi
# Function to generate a link
function generate-link() {
echo ":: Creating link '${1}' titled '${2}' redirecting to '${3}'"
cp ../template.html "${1}.html"
sed -i "s/\_TITLE\_/${2//\//\\/}/g" "${1}.html"
sed -i "s/\_RDURL\_/${3//\//\\/}/g" "${1}.html"
}
if [ -z "${LINKGEN_NO_DEFAULT}" ]; then
# LINKGEN_NO_DEFAULT is undefined, generate default links
echo ":: Generating StarOpenSource's default links"
# Index
cat << EOF > index.html
Redirecting to nowhere
Hello! You've landed on StarOpenSource's redirection website.
You can visit the source code for this website here.