File: pdb

package info (click to toggle)
puppetdb 8.8.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 19,692 kB
  • sloc: javascript: 23,285; ruby: 5,620; sh: 3,457; python: 389; xml: 114; makefile: 38
file content (82 lines) | stat: -rwxr-xr-x 2,657 bytes parent folder | download | duplicates (3)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash

# Starts PuppetDB using an existing uberjar
# The uberjar location can be defined with PDB_JAR environment variable
# The Bouncycastle dependency jars can be specified with BCPROV_JAR and BCPKIX_JAR
# Must have PostgreSQL running for PuppetDB to work
# Any arguments get passed straight to PuppetDB
# Example: pdb --help
# Example: pdb services --config ~/tmp/pdb-sandbox/conf.d

set -eo pipefail

# Extract version of a Maven package from `lein deps :tree` output
dep-ver()
{
    # Example:
    #  [org.bouncycastle/bcpkix-jdk18on "1.71"]
    local artifact="$1" deps="$2"
    artifact_rx="${artifact//./\\.}"' "([0-9.]+)"'
    [[ $deps =~ $artifact_rx ]]
    echo "${BASH_REMATCH[1]}"
}

cache_checked=''

# Save Bouncy Castle package versions to local filesystem
ensure-cache()
{
    if test ! -e ./pdb.bcprov -o ./project.clj -nt ./pdb.bcprov \
            -o ! -e ./pdb.bcpkix -o ./project.clj -nt ./pdb.bcpkix; then
        if test "$cache_checked"; then
            echo 'error: pdb.* or project.clj changed during execution' 1>&2
            exit 2
        fi
        local deps=$(lein deps :tree)
        dep-ver org.bouncycastle/bcpkix-jdk18on "$deps" > ./pdb.bcpkix
        dep-ver org.bouncycastle/bcprov-jdk18on "$deps" > ./pdb.bcprov
    fi
    cache_checked=true
}

# Ensure a file exists. Otherwise prints the command to use to create the file.
require-file()
{
    local file="$1" fix="$2"
    if ! test -e "$file"; then
    printf 'Unable to find %q; have you run %q?\n' "$file" "$fix" 1>&2
    exit 2
    fi
}

jar="${PDB_JAR:-target/puppetdb.jar}"
bcprov=''
bcpkix=''

# Load Bouncy Castle Crypto package jar from a custom location or Maven cache
# https://mavenlibs.com/maven/dependency/org.bouncycastle/bcprov-jdk18on
if test "$BCPROV_JAR"; then
    bcprov="$BCPROV_JAR"
else
    ensure-cache
    bcprov_ver=$(<./pdb.bcprov)
    bcprov="$HOME/.m2/repository/org/bouncycastle/bcprov-jdk18on/$bcprov_ver/bcprov-jdk18on-$bcprov_ver.jar"
fi

# Load another necessary Bouncy Castle jar from a custom location or Maven cache
# https://mavenlibs.com/maven/dependency/org.bouncycastle/bcpkix-jdk18on
if test "$BCPKIX_JAR"; then
    bcpkix="$BCPKIX_JAR"
else
    ensure-cache
    bcpkix_ver=$(<./pdb.bcpkix)
    bcpkix="$HOME/.m2/repository/org/bouncycastle/bcpkix-jdk18on/$bcpkix_ver/bcpkix-jdk18on-$bcpkix_ver.jar"
fi

# Validate that PuppetDB jar and Bouncy Castle jars exist
require-file "$jar" "lein uberjar"
require-file "$bcprov" "lein deps"
require-file "$bcpkix" "lein deps"

# Start PuppetDB and pass all received arguments to it
exec java -cp "$jar:$bcprov:$bcpkix" clojure.main -m puppetlabs.puppetdb.core "$@"