-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-recipe-find
executable file
·52 lines (44 loc) · 1.22 KB
/
docker-recipe-find
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
#!/usr/bin/env bash
set -e
DOCKER_RECIPE_BASE="$( cd "$(dirname "$0")" ; pwd -P )"
DOCKER_RECIPE_PATH=${DOCKER_RECIPE_PATH-"$DOCKER_RECIPE_BASE/recipes"}
DOCKER_RECIPE_OS=${DOCKER_RECIPE_OS-"debian"}
# Resolving recipe file
#
# Usage:
#
# docker_recipe_find foo
#
# Looks for:
#
# - foo.debian.sh
# - foo.sh
# - foo.debian.df
# - foo.df
# - foo/ (directory)
#
# If "debian" is the current DOCKER_RECIPE_OS.
# In case of an directory it will return all files that are in there on the first level.
#
function docker_recipe_find() {
# Security: disallow walking into another directory
templateBase=${DOCKER_RECIPE_PATH}/${1//\.\./}
# Resolve sh first then normal df files using os specific before general recipes.
for extension in ${DOCKER_RECIPE_OS}.sh sh ${DOCKER_RECIPE_OS}.df df; do
if [[ -f ${templateBase}.${extension} ]]; then
echo ${templateBase}.${extension};
return;
fi
done
# Including a whole directory is possible too.
if [[ -d $templateBase ]]; then
ls ${templateBase}/*.df ${templateBase}/*.sh 2>/dev/null
return
fi
echo "Could not resolve $1" >& 2
exit 1
}
if [[ ! -z "$1" ]]; then
docker_recipe_find $1
exit $?
fi