Skip to content
Snippets Groups Projects
set-environment 807 B
Newer Older
Jens Nolte's avatar
Jens Nolte committed
#!/bin/bash

set -e

function print_usage {
    echo "Usage: set-environment [ ENVIRONMENT_NAME | ENVIRONMENT_FILE ]"
}

function list_known_environments {
    # TODO
    return 0
}

function link_environment {
    if [[ "$1" == /* ]]; then
        TARGET="$1"
    else
        TARGET="../$1"
    fi
    echo "Linking main/environment.h to $TARGET"
Jens Nolte's avatar
Jens Nolte committed
    rm "main/environment.h" || true
Jens Nolte's avatar
Jens Nolte committed
    ln -s "$TARGET" "main/environment.h"
    touch --no-create "main/environment.h"
}

if [[ -z "$1" ]]; then
    print_usage
    list_known_environments
elif [[ -f "$1" && "$1" == *.h ]]; then
    link_environment "$1"
elif [[ -f "environments/$1.h" ]]; then
    link_environment "environments/$1.h"
else
    echo "Cannot find environment config in the following locations:"
    echo "$1"
    echo "environments/$1.h"
fi