diff options
author | Giusto <giusto@Macbook-M1-Max.local> | 2024-07-25 09:33:12 +0800 |
---|---|---|
committer | Giusto <giusto@Macbook-M1-Max.local> | 2024-07-25 09:33:12 +0800 |
commit | 421f0b1693d668a2d450b909db18eeb67328db7a (patch) | |
tree | f5ee27157b6d8c40eeacd8820b7275e9d5b999bd /data_decrypt.sh |
create a directory to contain only script that fill my own needs
Diffstat (limited to 'data_decrypt.sh')
-rwxr-xr-x | data_decrypt.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/data_decrypt.sh b/data_decrypt.sh new file mode 100755 index 0000000..6d5b477 --- /dev/null +++ b/data_decrypt.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env sh + +###################################################################### +# @author : Garhve (garhve@gmail.com) +# @file : decrypt +# @created : Wednesday Jan 10, 2024 01:09:07 CST +# +# @description : decrypt files that encrypt by gpg +###################################################################### + +for file in $@ +do + # get suffix + suffix=$(echo "$file" | rev | cut -d '.' -f1 | rev) + # get no suffix name + f_no_suffix="${file%.*}" + + # check either name is ending with gpg or a* + if [ $suffix = "gpg" ]; then + # if end with gpg, decrypt directly + gpg --output "${f_no_suffix}" --decrypt "$file" + + tar zxvf "${f_no_suffix}" && rm $f_no_suffix + else + # else join the parts before decrypt + cat ${f_no_suffix}.* > "$f_no_suffix" + + # get name without gpg suffix + f_no_gpg="${f_no_suffix%.*}" + gpg --output "${f_no_gpg}" --decrypt "$f_no_suffix" + + tar zxvf "$f_no_gpg" && rm $f_no_gpg $f_no_suffix + fi +done |