Last active
June 25, 2025 16:05
-
-
Save nikolaskhodov/93d23c8081309ea6381b64941bdc65a1 to your computer and use it in GitHub Desktop.
encrypt.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # brew install s3cmd@2.3.0 | |
| USERNAME=nikolas | |
| set -e | |
| CreateArchive () { | |
| # generate encryption key | |
| KEY=$(openssl rand -base64 32) | |
| sudo -u ${USERNAME} /bin/bash <<EOT | |
| set -e | |
| # jump to the root dir | |
| rm -rf ~/EE | |
| mkdir ~/EE | |
| cd ~/EE | |
| # make ~/EE/UE.zip | |
| osascript -e 'display notification "Build a zip archive..."' | |
| zip -0 -r ./UE ~/UE | |
| # create a bundle and encrypt | |
| osascript -e 'display notification "Encrypt the zip archive..."' | |
| openssl enc -aes-256-cbc -salt -md sha512 -in ./UE.zip -out ./UE.crypt -pass pass:$KEY | |
| # Split and remove leftovers | |
| osascript -e 'display notification "Split the zip archive..."' | |
| split -b 2000m UE.crypt | |
| rm ./UE.zip | |
| rm UE.crypt | |
| echo $KEY | gpg --recipient i@valt.me --encrypt > passwd.txt.gpg | |
| EOT | |
| } | |
| UploadTo () { | |
| FROM_DIR=$1 | |
| TO_URL=$2 | |
| ACCESS_KEY=$3 | |
| SECRET_KEY=$4 | |
| HOST=$5 | |
| sudo -u ${USERNAME} /bin/sh <<EOT | |
| s3cmd --no-check-md5 --verbose --access_key=${ACCESS_KEY} --secret_key=${SECRET_KEY} --host=${HOST} --host-bucket='%s(bucket).'${HOST} put --recursive ${FROM_DIR} ${TO_URL} | |
| EOT | |
| } | |
| CreateArchive | |
| # UploadTo ${LOCAL_FOLDER} s3://${BUCKET}/${REMOTE_FOLDER}/ ${ACCESS_KEY} ${SECRET_KEY} ${HOST} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment