summaryrefslogtreecommitdiff
path: root/src/lib/config.source.sh
blob: c3c073152575ce3767ced109ce694fdcf300e12f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
existing_parent_dir() {
    local -r path="$1"; shift
    local existing_parent

    existing_parent=$(dirname "$path")

    while [ ! -e "$existing_parent" ]; do
        existing_parent=$(dirname "$existing_parent")
    done

    printf '%s\n' "$existing_parent"
}

resolve_config_file() {
    local -r config_file="${1:-}"

    if [ -n "$config_file" ]; then
        printf '%s\n' "$config_file"
    else
        printf '%s\n' ./shuriken.conf
    fi
}

missing_config() {
    local -r config_file="$1"; shift

    printf 'Error: Can not find config file %s\n' "$config_file" >&2
    printf 'Run shuriken --init to create ./shuriken.conf.\n' >&2
    exit 1
}

apply_config_defaults() {
    # Empty FAVICON means use the bundled default favicon; otherwise it is a path
    # to a custom favicon file copied into the album as favicon.ico.
    FAVICON="${FAVICON:-}"
    HEIGHT="${HEIGHT:-}"
    IMAGE_JOBS="${IMAGE_JOBS:-3}"
    IMAGEMAGICK_TIMEOUT="${IMAGEMAGICK_TIMEOUT:-60}"
    ORIGINAL_BASEPATH="${ORIGINAL_BASEPATH:-}"
    RANDOM_SEED="${RANDOM_SEED:-}"
    SHUFFLE="${SHUFFLE:-no}"
    # SOURCE_URL is the project/source link shown in the page footer ("Site
    # generated ... with <SOURCE_URL>"). Defaults to the shuriken.sh repo;
    # override it per site (e.g. to the album's own repo) via config or
    # --source-url. The footer derives the displayed text from the URL itself.
    SOURCE_URL="${SOURCE_URL:-https://codeberg.org/snonux/shuriken.sh}"
    SPLASH_PAGE="${SPLASH_PAGE:-yes}"
    STATS_PAGE="${STATS_PAGE:-yes}"
    SYNC_DELETE="${SYNC_DELETE:-yes}"
    TARBALL_INCLUDE="${TARBALL_INCLUDE:-no}"
    TARBALL_SUFFIX="${TARBALL_SUFFIX:-.tar}"
    TAR_TIMEOUT="${TAR_TIMEOUT:-120}"
    if ! declare -p TAR_OPTS >/dev/null 2>&1; then
        TAR_OPTS=(-c)
    fi
    if ! declare -p SYNC_DESTINATIONS >/dev/null 2>&1; then
        SYNC_DESTINATIONS=()
    fi
}