From 6e040073a6789ac4bdf7a8d3b329ebc51a1ad19b Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Mon, 17 Apr 2023 11:10:55 -0600 Subject: [PATCH] qcrypt, drive --- update.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 update.sh diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..2729070 --- /dev/null +++ b/update.sh @@ -0,0 +1,78 @@ +#! /bin/bash + +set -e + +gpg="gpg" +target="all" + +if [[ "$#" -gt 1 ]]; then + target="$2" +fi + +tarred="${target%.*}-$(date +%Y-%m-%d-%H-%M).tar" + +function recursive_clean() { + d="$1" + echo "Removing pycache $(find "$d" -maxdepth 6 -name "__pycache__")" + rm -fr $(find "$d" -maxdepth 6 -name "__pycache__") + execs=$(find "$d" -maxdepth 6 -exec file {} \; | grep -i mach.o | awk '{print $1}') + for i in ${execs[@]}; do + i="${i%:*}" + echo "Removing executables $i" + rm "$i" + done + execs=$(find "$d" -maxdepth 6 -exec file {} \; | grep -i elf | awk '{print $1}') + for i in ${execs[@]}; do + i="${i%:*}" + echo "Removing executables $i" + rm "$i" + done +} +recursive_clean "$target" + +function qcrypt() { + # if ends with encrypted, decrypt and expand $target.tar + if [[ "$#" -gt 0 ]]; then + if [ "${1: -3}" == "gpg" ]; then + echo "IN QCRYPT" + if [ "$(ls ./$target 2> /dev/null)" != "" ]; then + echo "Moving $target to $target-old" + rm -rf ./$target-old + mv ./$target ./$target-old + fi + echo "Decrypting $*..." + $gpg -d $* > $pulltarget.tar + echo "Expanding ./$pulltarget.tar" + tar -xf ./$pulltarget.tar + fi + # else encrypt #and commit + else + echo "Encrypting $target" + + echo tar -czf ./$tarred ./$target + tar -czf ./$tarred ./$target + + $gpg --encrypt -r breel@qualtrics.com -u lapoba16@wfu.edu $tarred + fi +} + +if [[ "$#" -lt 1 ]]; then + echo "USAGE: bash ./update pull/push" + exit 0 +fi + +if [ "$1" == "pull" ]; then + echo "PULL" + pulltarget="$(drive ls | grep "$target-" | sort | tail -n 1)" + pulltarget="${pulltarget%.tar.gpg}" + pulltarget="$(basename $pulltarget)" + $GOPATH/bin/drive pull -depth 1 ./$pulltarget.tar.gpg + qcrypt ./$pulltarget.tar.gpg +fi +if [ "$1" == "push" ]; then + echo "PUSH" + qcrypt + $GOPATH/bin/drive push -depth 1 ./$tarred.gpg +fi + +