Created
June 16, 2018 23:51
-
-
Save xioustic/f488da63304043c504f58ac86c424e93 to your computer and use it in GitHub Desktop.
self encrypted bash script
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
# gets the line number in this script of the "PAYLOAD:" line | |
echoPayloadLinenum() { | |
echo $(grep --text --line-number '^PAYLOAD:$' $0 | cut -d ':' -f 1) | |
} | |
# prints only the payload | |
echoPayload() { | |
local payload_linenum=$(echoPayloadLinenum) | |
local crypted_linenum=$((payload_linenum + 1)) | |
tail -n +$crypted_linenum $0 | |
} | |
# prints this script without the payload | |
echoSelf() { | |
payload_linenum=$(echoPayloadLinenum) | |
head -n $payload_linenum $0 | |
} | |
# echoes the decrypted payload after user types in password | |
echoDecryptedPayload() { | |
PAYLOAD=$(echoPayload) | |
echo "$PAYLOAD" | gpg -d | |
} | |
# executes the decrypted payload after user types in password | |
runDecryptedPayload() { | |
SCRIPT=$(echoDecryptedPayload) | |
echo "$SCRIPT" | sh - | |
} | |
if [[ $* == *--encrypt* ]]; then | |
echo "encrypting new payload" | |
# clear payload | |
echo "$(echoSelf)" > $0 | |
gpg -c -a >> $0 | |
exit 0 | |
else | |
runDecryptedPayload | |
exit 0 | |
fi | |
PAYLOAD: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment