You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
19 KiB

5 years ago
  1. #!/bin/bash
  2. ################################################################################
  3. # ACME.sh 3rd party deploy plugin for Synology DSM
  4. ################################################################################
  5. # Authors: Brian Hartvigsen (creator), https://github.com/tresni
  6. # Martin Arndt (contributor), https://troublezone.net/
  7. # Updated: 2023-07-03
  8. # Issues: https://github.com/acmesh-official/acme.sh/issues/2727
  9. ################################################################################
  10. # Usage (shown values are the examples):
  11. # 1. Set required environment variables:
  12. # - use automatically created temp admin user to authenticate
  13. # export SYNO_USE_TEMP_ADMIN=1
  14. # - or provide your own admin user credential to authenticate
  15. # 1. export SYNO_USERNAME="adminUser"
  16. # 2. export SYNO_PASSWORD="adminPassword"
  17. # 2. Set optional environment variables
  18. # - common optional variables
  19. # - export SYNO_SCHEME="http" - defaults to "http"
  20. # - export SYNO_HOSTNAME="localhost" - defaults to "localhost"
  21. # - export SYNO_PORT="5000" - defaults to "5000"
  22. # - export SYNO_CREATE=1 - to allow creating the cert if it doesn't exist
  23. # - export SYNO_CERTIFICATE="" - to replace a specific cert by its
  24. # description
  25. # - 2FA-OTP optional variables (with your own admin user)
  26. # - export SYNO_OTP_CODE="XXXXXX" - if set, script won't require to
  27. # interactive input the OTP code
  28. # - export SYNO_DEVICE_NAME="CertRenewal" - if set, script won't require to
  29. # interactive input the device name
  30. # - export SYNO_DEVICE_ID="" - (deprecated) required for omitting 2FA-OTP
  31. # (please auth with OTP code instead)
  32. # - temp admin optional variables
  33. # - export SYNO_LOCAL_HOSTNAME=1 - if set to 1, force to treat hostname is
  34. # targeting current local machine (since
  35. # this method only locally supported)
  36. # 3. Run command:
  37. # acme.sh --deploy --deploy-hook synology_dsm -d example.com
  38. ################################################################################
  39. # Dependencies:
  40. # - curl
  41. # - synouser & synogroup (When available and SYNO_USE_TEMP_ADMIN is set)
  42. ################################################################################
  43. # Return value:
  44. # 0 means success, otherwise error.
  45. ################################################################################
  46. ########## Public functions ####################################################
  47. #domain keyfile certfile cafile fullchain
  48. synology_dsm_deploy() {
  49. _cdomain="$1"
  50. _ckey="$2"
  51. _ccert="$3"
  52. _cca="$4"
  53. _debug _cdomain "$_cdomain"
  54. # Get username and password, but don't save until we authenticated successfully
  55. _migratedeployconf SYNO_Username SYNO_USERNAME
  56. _migratedeployconf SYNO_Password SYNO_PASSWORD
  57. _migratedeployconf SYNO_Device_ID SYNO_DEVICE_ID
  58. _migratedeployconf SYNO_Device_Name SYNO_DEVICE_NAME
  59. _getdeployconf SYNO_USERNAME
  60. _getdeployconf SYNO_PASSWORD
  61. _getdeployconf SYNO_DEVICE_ID
  62. _getdeployconf SYNO_DEVICE_NAME
  63. # Prepare to use temp admin if SYNO_USE_TEMP_ADMIN is set
  64. _debug2 SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  65. _getdeployconf SYNO_USE_TEMP_ADMIN
  66. __check2cleardeployconfexp SYNO_USE_TEMP_ADMIN
  67. _debug2 SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  68. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  69. if ! _exists synouser || ! _exists synogroup; then
  70. _err "Tools are missing for creating temp admin user, please set SYNO_USERNAME and SYNO_PASSWORD instead."
  71. return 1
  72. fi
  73. [ -n "$SYNO_USERNAME" ] || _savedeployconf SYNO_USERNAME ""
  74. [ -n "$SYNO_PASSWORD" ] || _savedeployconf SYNO_PASSWORD ""
  75. _debug "Setting temp admin user credential..."
  76. SYNO_USERNAME=sc-acmesh-tmp
  77. SYNO_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)
  78. # Set 2FA-OTP settings to empty consider they won't be needed.
  79. SYNO_DEVICE_ID=
  80. SYNO_DEVICE_NAME=
  81. SYNO_OTP_CODE=
  82. else
  83. _debug2 SYNO_USERNAME "$SYNO_USERNAME"
  84. _secure_debug2 SYNO_PASSWORD "$SYNO_PASSWORD"
  85. _debug2 SYNO_DEVICE_NAME "$SYNO_DEVICE_NAME"
  86. _secure_debug2 SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  87. fi
  88. if [ -z "$SYNO_USERNAME" ] || [ -z "$SYNO_PASSWORD" ]; then
  89. _err "You must set either SYNO_USE_TEMP_ADMIN, or set both SYNO_USERNAME and SYNO_PASSWORD."
  90. return 1
  91. fi
  92. # Optional scheme, hostname and port for Synology DSM
  93. _migratedeployconf SYNO_Scheme SYNO_SCHEME
  94. _migratedeployconf SYNO_Hostname SYNO_HOSTNAME
  95. _migratedeployconf SYNO_Port SYNO_PORT
  96. _getdeployconf SYNO_SCHEME
  97. _getdeployconf SYNO_HOSTNAME
  98. _getdeployconf SYNO_PORT
  99. # Default values for scheme, hostname and port
  100. # Defaulting to localhost and http, because it's localhost…
  101. [ -n "$SYNO_SCHEME" ] || SYNO_SCHEME="http"
  102. [ -n "$SYNO_HOSTNAME" ] || SYNO_HOSTNAME="localhost"
  103. [ -n "$SYNO_PORT" ] || SYNO_PORT="5000"
  104. _savedeployconf SYNO_SCHEME "$SYNO_SCHEME"
  105. _savedeployconf SYNO_HOSTNAME "$SYNO_HOSTNAME"
  106. _savedeployconf SYNO_PORT "$SYNO_PORT"
  107. _debug2 SYNO_SCHEME "$SYNO_SCHEME"
  108. _debug2 SYNO_HOSTNAME "$SYNO_HOSTNAME"
  109. _debug2 SYNO_PORT "$SYNO_PORT"
  110. # Get the certificate description, but don't save it until we verify it's real
  111. _migratedeployconf SYNO_Certificate SYNO_CERTIFICATE "base64"
  112. _getdeployconf SYNO_CERTIFICATE
  113. __check2cleardeployconfexp SYNO_CERTIFICATE
  114. _debug SYNO_CERTIFICATE "${SYNO_CERTIFICATE:-}"
  115. # shellcheck disable=SC1003 # We are not trying to escape a single quote
  116. if printf "%s" "$SYNO_CERTIFICATE" | grep '\\'; then
  117. _err "Do not use a backslash (\) in your certificate description"
  118. return 1
  119. fi
  120. _debug "Getting API version..."
  121. _base_url="$SYNO_SCHEME://$SYNO_HOSTNAME:$SYNO_PORT"
  122. _debug _base_url "$_base_url"
  123. response=$(_get "$_base_url/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth")
  124. api_path=$(echo "$response" | grep "SYNO.API.Auth" | sed -n 's/.*"path" *: *"\([^"]*\)".*/\1/p')
  125. api_version=$(echo "$response" | grep "SYNO.API.Auth" | sed -n 's/.*"maxVersion" *: *\([0-9]*\).*/\1/p')
  126. _debug3 response "$response"
  127. _debug3 api_path "$api_path"
  128. _debug3 api_version "$api_version"
  129. # Login, get the session ID and SynoToken from JSON
  130. _info "Logging into $SYNO_HOSTNAME:$SYNO_PORT..."
  131. encoded_username="$(printf "%s" "$SYNO_USERNAME" | _url_encode)"
  132. encoded_password="$(printf "%s" "$SYNO_PASSWORD" | _url_encode)"
  133. # ## START ## - DEPRECATED, for backward compatibility
  134. _getdeployconf SYNO_TOTP_SECRET
  135. if [ -n "$SYNO_TOTP_SECRET" ]; then
  136. _info "WARNING: Usage of SYNO_TOTP_SECRET is deprecated!"
  137. _info " See synology_dsm.sh script or ACME.sh Wiki page for details:"
  138. _info " https://github.com/acmesh-official/acme.sh/wiki/Synology-NAS-Guide"
  139. if ! _exists oathtool; then
  140. _err "oathtool could not be found, install oathtool to use SYNO_TOTP_SECRET"
  141. return 1
  142. fi
  143. DEPRECATED_otp_code="$(oathtool --base32 --totp "$SYNO_TOTP_SECRET" 2>/dev/null)"
  144. if [ -z "$SYNO_DEVICE_ID" ]; then
  145. _getdeployconf SYNO_DID
  146. [ -n "$SYNO_DID" ] || SYNO_DEVICE_ID="$SYNO_DID"
  147. fi
  148. if [ -n "$SYNO_DEVICE_ID" ]; then
  149. _H1="Cookie: did=$SYNO_DEVICE_ID"
  150. export _H1
  151. _debug3 H1 "${_H1}"
  152. fi
  153. response=$(_post "method=login&account=$encoded_username&passwd=$encoded_password&api=SYNO.API.Auth&version=$api_version&enable_syno_token=yes&otp_code=$DEPRECATED_otp_code&device_name=certrenewal&device_id=$SYNO_DEVICE_ID" "$_base_url/webapi/auth.cgi?enable_syno_token=yes")
  154. _debug3 response "$response"
  155. # ## END ## - DEPRECATED, for backward compatibility
  156. # If SYNO_DEVICE_ID or SYNO_OTP_CODE is set, we treat current account enabled 2FA-OTP.
  157. # Notice that if SYNO_USE_TEMP_ADMIN=1, both variables will be unset
  158. else
  159. if [ -n "$SYNO_DEVICE_ID" ] || [ -n "$SYNO_OTP_CODE" ]; then
  160. response='{"error":{"code":403}}'
  161. # Assume the current account disabled 2FA-OTP, try to log in right away.
  162. else
  163. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  164. _getdeployconf SYNO_LOCAL_HOSTNAME
  165. _debug SYNO_LOCAL_HOSTNAME "${SYNO_LOCAL_HOSTNAME:-}"
  166. if [ "$SYNO_LOCAL_HOSTNAME" != "1" ] && [ "$SYNO_LOCAL_HOSTNAME" == "$SYNO_HOSTNAME" ]; then
  167. if [ "$SYNO_HOSTNAME" != "localhost" ] && [ "$SYNO_HOSTNAME" != "127.0.0.1" ]; then
  168. _err "SYNO_USE_TEMP_ADMIN=1 Only support locally deployment, if you are sure that hostname $SYNO_HOSTNAME is targeting to your **current local machine**, execute 'export SYNO_LOCAL_HOSTNAME=1' then rerun."
  169. return 1
  170. fi
  171. fi
  172. _debug "Creating temp admin user in Synology DSM..."
  173. synouser --del "$SYNO_USERNAME" >/dev/null 2>/dev/null
  174. synouser --add "$SYNO_USERNAME" "$SYNO_PASSWORD" "" 0 "scruelt@hotmail.com" 0 >/dev/null
  175. if synogroup --help | grep -q '\-\-memberadd'; then
  176. synogroup --memberadd administrators "$SYNO_USERNAME" >/dev/null
  177. else
  178. # For supporting DSM 6.x which only has `--member` parameter.
  179. cur_admins=$(synogroup --get administrators | awk -F '[][]' '/Group Members/,0{if(NF>1)printf "%s ", $2}')
  180. _secure_debug3 admin_users "$cur_admins$SYNO_USERNAME"
  181. # shellcheck disable=SC2086
  182. synogroup --member administrators $cur_admins $SYNO_USERNAME >/dev/null
  183. fi
  184. # havig a workaround to temporary disable enforce 2FA-OTP
  185. otp_enforce_option=$(synogetkeyvalue /etc/synoinfo.conf otp_enforce_option)
  186. if [ -n "$otp_enforce_option" ] && [ "${otp_enforce_option:-"none"}" != "none" ]; then
  187. synosetkeyvalue /etc/synoinfo.conf otp_enforce_option none
  188. _info "Temporary disabled enforce 2FA-OTP to complete authentication."
  189. _info "previous_otp_enforce_option" "$otp_enforce_option"
  190. else
  191. otp_enforce_option=""
  192. fi
  193. fi
  194. response=$(_get "$_base_url/webapi/entry.cgi?api=SYNO.API.Auth&version=$api_version&method=login&format=sid&account=$encoded_username&passwd=$encoded_password&enable_syno_token=yes")
  195. if [ -n "$SYNO_USE_TEMP_ADMIN" ] && [ -n "$otp_enforce_option" ]; then
  196. synosetkeyvalue /etc/synoinfo.conf otp_enforce_option "$otp_enforce_option"
  197. _info "Restored previous enforce 2FA-OTP option."
  198. fi
  199. _debug3 response "$response"
  200. fi
  201. fi
  202. error_code=$(echo "$response" | grep '"error"' | grep -oP '(?<="code":)\d+')
  203. # Account has 2FA-OTP enabled, since error 403 reported.
  204. # https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/All/enu/Synology_DiskStation_Administration_CLI_Guide.pdf
  205. if [ "$error_code" == "403" ]; then
  206. if [ -z "$SYNO_DEVICE_NAME" ]; then
  207. printf "Enter device name or leave empty for default (CertRenewal): "
  208. read -r SYNO_DEVICE_NAME
  209. [ -n "$SYNO_DEVICE_NAME" ] || SYNO_DEVICE_NAME="CertRenewal"
  210. fi
  211. if [ -n "$SYNO_DEVICE_ID" ]; then
  212. # Omit OTP code with SYNO_DEVICE_ID.
  213. response=$(_get "$_base_url/webapi/$api_path?api=SYNO.API.Auth&version=$api_version&method=login&format=sid&account=$encoded_username&passwd=$encoded_password&enable_syno_token=yes&device_name=$SYNO_DEVICE_NAME&device_id=$SYNO_DEVICE_ID")
  214. _secure_debug3 response "$response"
  215. else
  216. # Require the OTP code if still unset.
  217. if [ -z "$SYNO_OTP_CODE" ]; then
  218. printf "Enter OTP code for user '%s': " "$SYNO_USERNAME"
  219. read -r SYNO_OTP_CODE
  220. fi
  221. _secure_debug SYNO_OTP_CODE "${SYNO_OTP_CODE:-}"
  222. if [ -z "$SYNO_OTP_CODE" ]; then
  223. response='{"error":{"code":404}}'
  224. else
  225. response=$(_get "$_base_url/webapi/$api_path?api=SYNO.API.Auth&version=$api_version&method=login&format=sid&account=$encoded_username&passwd=$encoded_password&enable_syno_token=yes&enable_device_token=yes&device_name=$SYNO_DEVICE_NAME&otp_code=$SYNO_OTP_CODE")
  226. _secure_debug3 response "$response"
  227. id_property='device_id'
  228. [ "${api_version}" -gt '6' ] || id_property='did'
  229. SYNO_DEVICE_ID=$(echo "$response" | grep "$id_property" | sed -n 's/.*"'$id_property'" *: *"\([^"]*\).*/\1/p')
  230. _secure_debug2 SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  231. fi
  232. fi
  233. error_code=$(echo "$response" | grep '"error"' | grep -oP '(?<="code":)\d+')
  234. fi
  235. if [ -n "$error_code" ]; then
  236. if [ "$error_code" == "403" ] && [ -n "$SYNO_DEVICE_ID" ]; then
  237. _cleardeployconf SYNO_DEVICE_ID
  238. _err "Failed to authenticate with SYNO_DEVICE_ID (may expired or invalid), please try again in a new terminal window."
  239. elif [ "$error_code" == "404" ]; then
  240. _err "Failed to authenticate with provided 2FA-OTP code, please try again in a new terminal window."
  241. elif [ "$error_code" == "406" ]; then
  242. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  243. _err "SYNO_USE_TEMP_ADMIN=1 is not supported if enforce auth with 2FA-OTP is enabled."
  244. else
  245. _err "Enforce auth with 2FA-OTP enabled, please configure the user to enable 2FA-OTP to continue."
  246. fi
  247. elif [ "$error_code" == "400" ] || [ "$error_code" == "401" ] || [ "$error_code" == "408" ] || [ "$error_code" == "409" ] || [ "$error_code" == "410" ]; then
  248. _err "Failed to authenticate with a non-existent or disabled account, or the account password is incorrect or has expired."
  249. else
  250. _err "Failed to authenticate with error: $error_code."
  251. fi
  252. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  253. return 1
  254. fi
  255. sid=$(echo "$response" | grep "sid" | sed -n 's/.*"sid" *: *"\([^"]*\).*/\1/p')
  256. token=$(echo "$response" | grep "synotoken" | sed -n 's/.*"synotoken" *: *"\([^"]*\).*/\1/p')
  257. _debug "Session ID" "$sid"
  258. _debug SynoToken "$token"
  259. if [ -z "$sid" ] || [ -z "$token" ]; then
  260. # Still can't get necessary info even got no errors, may Synology have API updated?
  261. _err "Unable to authenticate to $_base_url, you may report the full log to the community."
  262. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  263. return 1
  264. fi
  265. _H1="X-SYNO-TOKEN: $token"
  266. export _H1
  267. _debug2 H1 "${_H1}"
  268. # Now that we know the username and password are good, save them if not in temp admin mode.
  269. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  270. _cleardeployconf SYNO_USERNAME
  271. _cleardeployconf SYNO_PASSWORD
  272. _cleardeployconf SYNO_DEVICE_ID
  273. _cleardeployconf SYNO_DEVICE_NAME
  274. _savedeployconf SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  275. _savedeployconf SYNO_LOCAL_HOSTNAME "$SYNO_HOSTNAME"
  276. else
  277. _savedeployconf SYNO_USERNAME "$SYNO_USERNAME"
  278. _savedeployconf SYNO_PASSWORD "$SYNO_PASSWORD"
  279. _savedeployconf SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  280. _savedeployconf SYNO_DEVICE_NAME "$SYNO_DEVICE_NAME"
  281. fi
  282. _info "Getting certificates in Synology DSM..."
  283. response=$(_post "api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=$sid" "$_base_url/webapi/entry.cgi")
  284. _debug3 response "$response"
  285. escaped_certificate="$(printf "%s" "$SYNO_CERTIFICATE" | sed 's/\([].*^$[]\)/\\\1/g;s/"/\\\\"/g')"
  286. _debug escaped_certificate "$escaped_certificate"
  287. id=$(echo "$response" | sed -n "s/.*\"desc\":\"$escaped_certificate\",\"id\":\"\([^\"]*\).*/\1/p")
  288. _debug2 id "$id"
  289. error_code=$(echo "$response" | grep '"error"' | grep -oP '(?<="code":)\d+')
  290. if [ -n "$error_code" ]; then
  291. if [ "$error_code" -eq 105 ]; then
  292. _err "Current user is not administrator and does not have sufficient permission for deploying."
  293. else
  294. _err "Failed to fetch certificate info with error: $error_code, please try again or contact Synology to learn more."
  295. fi
  296. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  297. return 1
  298. fi
  299. _migratedeployconf SYNO_Create SYNO_CREATE
  300. _getdeployconf SYNO_CREATE
  301. _debug2 SYNO_CREATE "$SYNO_CREATE"
  302. if [ -z "$id" ] && [ -z "$SYNO_CREATE" ]; then
  303. _err "Unable to find certificate: $SYNO_CERTIFICATE and $SYNO_CREATE is not set."
  304. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  305. return 1
  306. fi
  307. # We've verified this certificate description is a thing, so save it
  308. _savedeployconf SYNO_CERTIFICATE "$SYNO_CERTIFICATE" "base64"
  309. _info "Generating form POST request..."
  310. nl="\0015\0012"
  311. delim="--------------------------$(_utc_date | tr -d -- '-: ')"
  312. content="--$delim${nl}Content-Disposition: form-data; name=\"key\"; filename=\"$(basename "$_ckey")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")\0012"
  313. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"cert\"; filename=\"$(basename "$_ccert")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ccert")\0012"
  314. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"inter_cert\"; filename=\"$(basename "$_cca")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_cca")\0012"
  315. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"id\"${nl}${nl}$id"
  316. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"desc\"${nl}${nl}${SYNO_CERTIFICATE}"
  317. if echo "$response" | sed -n "s/.*\"desc\":\"$escaped_certificate\",\([^{]*\).*/\1/p" | grep -- 'is_default":true' >/dev/null; then
  318. _debug2 default "This is the default certificate"
  319. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"as_default\"${nl}${nl}true"
  320. else
  321. _debug2 default "This is NOT the default certificate"
  322. fi
  323. content="$content${nl}--$delim--${nl}"
  324. content="$(printf "%b_" "$content")"
  325. content="${content%_}" # protect trailing \n
  326. _info "Upload certificate to the Synology DSM."
  327. response=$(_post "$content" "$_base_url/webapi/entry.cgi?api=SYNO.Core.Certificate&method=import&version=1&SynoToken=$token&_sid=$sid" "" "POST" "multipart/form-data; boundary=${delim}")
  328. _debug3 response "$response"
  329. if ! echo "$response" | grep '"error":' >/dev/null; then
  330. if echo "$response" | grep '"restart_httpd":true' >/dev/null; then
  331. _info "Restart HTTP services succeeded."
  332. else
  333. _info "Restart HTTP services failed."
  334. fi
  335. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  336. _logout
  337. return 0
  338. else
  339. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  340. _err "Unable to update certificate, got error response: $response."
  341. _logout
  342. return 1
  343. fi
  344. }
  345. #################### Private functions below ##################################
  346. _logout() {
  347. # Logout CERT user only to not occupy a permanent session, e.g. in DSM's "Connected Users" widget (based on previous variables)
  348. response=$(_get "$_base_url/webapi/$api_path?api=SYNO.API.Auth&version=$api_version&method=logout&_sid=$sid")
  349. _debug3 response "$response"
  350. }
  351. _temp_admin_cleanup() {
  352. flag=$1
  353. username=$2
  354. if [ -n "${flag}" ]; then
  355. _debug "Cleanuping temp admin info..."
  356. synouser --del "$username" >/dev/null
  357. fi
  358. }
  359. #_cleardeployconf key
  360. _cleardeployconf() {
  361. _cleardomainconf "SAVED_$1"
  362. }
  363. # key
  364. __check2cleardeployconfexp() {
  365. # Warning:
  366. _key="$1"
  367. _clear_key="CLEAR_$_key"
  368. # Clear saved settings if explicitly requested
  369. if [ -n "$(eval echo \$$_clear_key)" ]; then
  370. _debug2 "$_key: value cleared from config, exported value will be ignored."
  371. _cleardeployconf "$_key"
  372. eval $_key=
  373. export $_key=
  374. eval SAVED_$_key=
  375. export SAVED_$_key=
  376. fi
  377. }