Skip to content

Commit 19be04f

Browse files
committed
Deploy_freenas splitted for two scripts
1 parent 7b26f8c commit 19be04f

File tree

5 files changed

+167
-124
lines changed

5 files changed

+167
-124
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
deploy_config
2+
acme.sh
3+
http.header

deploy/freenas.sh

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env sh
2+
3+
# Script to deploy certificate to a FreeNAS server
4+
5+
# The following variables exported from environment will be used.
6+
# If not set then values previously saved in domain.conf file are used.
7+
8+
# Required variables:
9+
# export FREENAS_PASSWORD="xxxxxxx"
10+
#
11+
# Optional variables (default values described):
12+
# export FREENAS_HOST="http://localhost:80"
13+
# export FREENAS_VERIFY=false
14+
15+
#domain keyfile certfile cafile fullchain
16+
freenas_deploy() {
17+
_cdomain="$1"
18+
_ckey="$2"
19+
_ccert="$3"
20+
_cca="$4"
21+
_cfullchain="$5"
22+
23+
_debug _cdomain "$_cdomain"
24+
_debug _ckey "$_ckey"
25+
_debug _ccert "$_ccert"
26+
_debug _cca "$_cca"
27+
_debug _cfullchain "$_cfullchain"
28+
29+
if [ -z "$FREENAS_PASSWORD" ]; then
30+
if [ -z "$Le_Deploy_FreeNAS_password" ]; then
31+
_err "FREENAS_PASSWORD not defined."
32+
return 1
33+
fi
34+
else
35+
Le_Deploy_FreeNAS_password="$FREENAS_PASSWORD"
36+
_savedomainconf Le_Deploy_FreeNAS_password "$Le_Deploy_FreeNAS_password"
37+
fi
38+
39+
if [ -z "$FREENAS_HOST" ]; then
40+
if [ -z "$Le_Deploy_FreeNAS_host" ]; then
41+
Le_Deploy_FreeNAS_host="http://localhost:80"
42+
_savedomainconf Le_Deploy_freenas_host "$Le_Deploy_FreeNAS_host"
43+
fi
44+
else
45+
Le_Deploy_FreeNAS_host="$FREENAS_HOST"
46+
_savedomainconf Le_Deploy_freenas_host "$Le_Deploy_FreeNAS_host"
47+
fi
48+
49+
if [ -z "$FREENAS_VERIFY" ]; then
50+
if [ -z "$Le_Deploy_FreeNAS_verify" ]; then
51+
Le_Deploy_FreeNAS_verify=false
52+
_savedomainconf Le_Deploy_FreeNAS_verify "$Le_Deploy_FreeNAS_verify"
53+
fi
54+
else
55+
Le_Deploy_FreeNAS_verify="$FREENAS_VERIFY"
56+
_savedomainconf Le_Deploy_FreeNAS_verify "$Le_Deploy_FreeNAS_verify"
57+
fi
58+
59+
api_base="${Le_Deploy_FreeNAS_host}/api/v1.0"
60+
cert=$(date +letsencrypt-%Y-%m-%d-%H%M%S)
61+
credentials=$(printf "%s:%s" "root" "$Le_Deploy_FreeNAS_password" | _base64)
62+
63+
_err "Not implemented yet"
64+
return 1
65+
}

deploy_freenas.sh

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env sh
2+
3+
DEBUG=3
4+
5+
6+
7+
_locate() {
8+
fname=$1
9+
shift
10+
for dir in $*; do
11+
dir=$(cd ${dir} 2>/dev/null && pwd)
12+
if [ -r "${dir}/${fname}" ]; then echo "${dir}/${fname}"; exit; fi
13+
done
14+
}
15+
16+
17+
18+
WDIR=$(cd `dirname $0` && pwd)
19+
20+
FETCH=$(which fetch 2>/dev/null)
21+
CURL=$(which curl 2>/dev/null)
22+
WGET=$(which wget 2>/dev/null)
23+
24+
IS_OPNSENSE=$([ -d "/usr/local/opnsense/" ] && echo 1)
25+
26+
# Locate acme.sh and load it as a library
27+
ACME=$(_locate acme.sh /root/.acme.sh /usr/local/sbin "$WDIR")
28+
29+
if [ -z "$ACME" ] || [ `find "$ACME" -mtime +30` ]; then
30+
if [ ! -z "$FETCH" ]; then
31+
"$FETCH" https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
32+
elif [ ! -z "$CURL" ]; then
33+
"$CURL" -O https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
34+
elif [ ! -z "$WGET" ]; then
35+
"$WGET" https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
36+
fi
37+
ACME=$(_locate acme.sh "$WDIR")
38+
fi
39+
if [ -z "$ACME" ]; then echo "ERROR: Can't locate acme.sh"; exit 1; fi
40+
41+
if [ "$IS_OPNSENSE" == "1" ]; then
42+
LE_WORKING_DIR="$WDIR"
43+
else
44+
LE_WORKING_DIR=`dirname $ACME`
45+
fi
46+
47+
. "$ACME" >/dev/null
48+
49+
50+
51+
_parse_ini() {
52+
inFile="$1"
53+
prefix="${2:-ini}"
54+
55+
if [ ! -f "$inFile" ]; then _err "File $inFile not found!"; exit 1; fi
56+
57+
local IFS="="
58+
echo "[]" | cat "$inFile" - | sed 's/\t/ /g;s/^ +//;s/ +$//;/^#/d;/^$/d' | while read name value; do
59+
name=${name/ /}
60+
[ -z "$name" ] && continue
61+
62+
local IFS=" "
63+
if [ "${name:0:1}" == "[" ]; then
64+
section=${name/'['/}
65+
section=${section/']'/}
66+
else
67+
value=${value/# /}
68+
value=${value/% /}
69+
value=${value/#\"/}
70+
value=${value/%\"/}
71+
72+
value=${value//\"/\\\"}
73+
echo "${prefix}__${section}__${name}=\"${value}\""
74+
fi
75+
local IFS="="
76+
done
77+
}
78+
79+
80+
81+
# Parse configuration file
82+
CONFIG=$(_locate deploy_config ${WDIR}/../.. ${WDIR})
83+
84+
if [ -z "$CONFIG" ]; then _err "ERROR: Can't locate deploy_config!"; exit 1; fi
85+
86+
eval $(_parse_ini ${CONFIG})
87+
88+
if [ -z "${ini__deploy__password}" ]; then _err "ERROR: Root password not defined!"; exit 1; fi
89+
90+
DOMAIN_NAME=${ini__deploy__cert_fqdn:-$(hostname)}
91+
export FREENAS_PASSWORD=${ini__deploy__password}
92+
export FREENAS_HOST="${ini__deploy__protocol:-"http://"}${ini__deploy__connect_host:-"localhost"}:${ini__deploy__port:-"80"}"
93+
export FREENAS_VERIFY=${ini__deploy__verify:-"true"}
94+
95+
_debug DOMAIN_NAME ${DOMAIN_NAME}
96+
_debug FREENAS_PASSWORD ${FREENAS_PASSWORD}
97+
_debug FREENAS_HOST ${FREENAS_HOST}
98+
_debug FREENAS_VERIFY ${FREENAS_VERIFY}
99+
100+
_deploy ${DOMAIN_NAME} "freenas"

util/opnsense/.gitignore

-2
This file was deleted.

util/opnsense/deploy_freenas.sh

-122
This file was deleted.

0 commit comments

Comments
 (0)