Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect gnu sed on any system #72

Merged
merged 1 commit into from
Jan 22, 2021
Merged

detect gnu sed on any system #72

merged 1 commit into from
Jan 22, 2021

Conversation

jkroepke
Copy link
Owner

@jkroepke jkroepke commented Jan 22, 2021

Fixes #71

@github-actions
Copy link
Contributor

sh-checker report

shellcheck output
No errors or shellcheck is disabled

The files above have some shellcheck issues

shfmt output
--- scripts/drivers/_custom.sh.orig
+++ scripts/drivers/_custom.sh
@@ -1,92 +1,92 @@
 #!/usr/bin/env shv
 
 # MacOS syntax is different for in-place
 # https://unix.stackexchange.com/a/92907/433641
 case $(sed --help 2>&1) in
-    *GNU*) _sed_i() { sed -i "$@"; };;
-    *) _sed_i() { sed -i '' "$@"; };;
+*GNU*) _sed_i() { sed -i "$@"; } ;;
+*) _sed_i() { sed -i '' "$@"; } ;;
 esac
 
 _regex_escape() {
     # This is a function because dealing with quotes is a pain.
     # http://stackoverflow.com/a/2705678/120999
     sed -e 's/[]\/()$*.^|[]/\\&/g'
 }
 
 _custom_driver_is_yaml() {
     false
 }
 
 _custom_driver_get_secret() {
     echo "Please override function '_custom_driver_get_secret' in your driver!" >&2
     exit 1
 }
 
 driver_is_file_encrypted() {
     input="${1}"
 
     grep -q -e "${_DRIVER_REGEX}" "${input}"
 }
 
 driver_encrypt_file() {
     echo "Encrypting files is not supported!"
     exit 1
 }
 
 driver_decrypt_file() {
     type="${1}"
     input="${2}"
     # if omit then output to stdout
     output="${3:-}"
 
     output_yaml="$(mktemp)"
     output_yaml_anchors="$(mktemp)"
 
     # Strip yaml separator
     sed -e '/^---$/d' "${input}" >"${output_yaml}"
 
     # Grab all patterns, deduplicate and pass it to loop
     # https://github.com/koalaman/shellcheck/wiki/SC2013
     if ! grep -o -e "${_DRIVER_REGEX}" "${input}" | sort | uniq | while IFS= read -r EXPRESSION; do
         # remove prefix
         _SECRET="${EXPRESSION#* }"
 
         if ! SECRET=$(_custom_driver_get_secret "${type}" "${_SECRET}"); then
             exit 1
         fi
 
         # generate yaml anchor name
         YAML_ANCHOR=$(printf 'helm-secret-%s' "${_SECRET}" | tr '#$/' '_')
 
         # Replace vault expression with yaml anchor
         EXPRESSION="$(echo "${EXPRESSION}" | _regex_escape)"
         _sed_i "s/${EXPRESSION}/*${YAML_ANCHOR}/g" "${output_yaml}"
 
         if _custom_driver_is_yaml "${type}" "${_SECRET}"; then
             {
                 printf '.%s: &%s\n' "${YAML_ANCHOR}" "${YAML_ANCHOR}"
                 printf '%s\n\n' "${SECRET}" | sed -e 's/^/  /g'
             } >>"${output_yaml_anchors}"
         else
             {
                 printf '.%s: &%s ' "${YAML_ANCHOR}" "${YAML_ANCHOR}"
                 printf '%s\n\n' "${SECRET}"
             } >>"${output_yaml_anchors}"
         fi
     done; then
         # pass exit from pipe/sub shell to main shell
         exit 1
     fi
 
     if [ "${output}" = "" ]; then
         cat "${output_yaml_anchors}" "${output_yaml}"
     else
         cat "${output_yaml_anchors}" "${output_yaml}" >"${output}"
     fi
 }
 
 driver_edit_file() {
     echo "Editing files is not supported!"
     exit 1
 }
 

The files above have some formatting problems, you can use shfmt -w to fix them

To get the full details about this job

@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #72 (67fa1a0) into master (02a510c) will not change coverage.
The diff coverage is 66.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #72   +/-   ##
=======================================
  Coverage   89.06%   89.06%           
=======================================
  Files          18       18           
  Lines         503      503           
=======================================
  Hits          448      448           
  Misses         55       55           
Impacted Files Coverage Δ
scripts/drivers/_custom.sh 69.23% <66.66%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02a510c...67fa1a0. Read the comment docs.

@jkroepke jkroepke force-pushed the detect-gnu-sed branch 3 times, most recently from 73fc6bd to 954f740 Compare January 22, 2021 18:05
Repository owner deleted a comment from github-actions bot Jan 22, 2021
Repository owner deleted a comment from github-actions bot Jan 22, 2021
@jkroepke jkroepke merged commit 9d57821 into master Jan 22, 2021
@jkroepke jkroepke deleted the detect-gnu-sed branch January 22, 2021 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GNU sed on OSX
1 participant