#! /usr/bin/env bash

function make_name() {
        local path filename extension
        path=$(dirname "$1")
        filename=$(basename "$1")
        extension="${filename##*.}"
        filename="${filename%.*}"
        if [[ -e $path/$filename.$extension ]] ; then
            i=1
            while [[ -e $path/$filename-$i.$extension ]] ; do
                let i++
            done
            filename=$filename-$i
        fi
        echo "$path/$filename.$extension"
}


export PATH="$PATH:~/bin"

name=/var/www/html/log.html
new=$(make_name $name)
mv "$name" "$new"
mail -s "$new" lars@netapp.com -A "$new" < /dev/null

cat <<-EOF > /var/www/html/.htaccess
RewriteRule ^log$ /$(basename "$new") [R]
EOF

mkdir -p @CMAKE_BINARY_DIR@
cd @CMAKE_BINARY_DIR@ || exit
git pull
cmake -GNinja ..
ninja
bin/server -i eth0 -d /usr/share/apache2/default-site 2>&1 | aha -s > "$name"

#! /usr/bin/env bash

function make_name() {
        local path filename extension
        path=$(dirname "$1")
        filename=$(basename "$1")
        extension="${filename##*.}"
        filename="${filename%.*}"
        if [[ -e $path/$filename.$extension ]] ; then
            i=1
            while [[ -e $path/$filename-$i.$extension ]] ; do
                let i++
            done
            filename=$filename-$i
        fi
        echo "$path/$filename.$extension"
}


export PATH="$PATH:~/bin"

name=/var/www/html/log.html
new=$(make_name $name)
mv "$name" "$new"
mail -s "$new" lars@netapp.com -A "$new" < /dev/null

cat <<-EOF > /var/www/html/.htaccess
RewriteRule ^log$ /$(basename "$new") [R]
EOF

mkdir -p @CMAKE_BINARY_DIR@
cd @CMAKE_BINARY_DIR@ || exit
git pull
cmake -GNinja ..
ninja
bin/server -i eth0 -d /usr/share/apache2/default-site
    -c /etc/letsencrypt/live/quant.eggert.org/fullchain.pem \
    -k /etc/letsencrypt/live/quant.eggert.org/privkey.pem \
    2>&1 | aha -s > "$name"

Fix cert/key path on quant.eggert.org
Fix cert/key path on quant.eggert.org
