Last active
May 25, 2022 04:33
-
-
Save ExZyle/7c64573fc57e82d0e9ef1ebcf148290e to your computer and use it in GitHub Desktop.
Ansible container persistence helper for use with lesson 12, USYD CyberSecurity Bootcamp 2022
This file contains 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
#!/usr/bin/env bash | |
# | |
# Written by ExZyle <exzyle@protonmail.com> | |
# | |
# Save this script into your VM, make sure you make it executable (chmod a+x exzyle.sh) | |
# | |
# From the same directory you save this script, run the following to get | |
# some persistence out of your docker ansible container: | |
# | |
# docker run -it --rm -v `pwd`:/exzyle --entrypoint /exzyle/exzyle.sh cyberxsecurity/ansible | |
# | |
BACKUP_DIR=/exzyle/backups | |
BACKUP_FILE=$BACKUP_DIR/backup.tgz | |
echo " ______ _______ __ " | |
echo " (______) (_______) (__) ____ " | |
echo " (_)__ _ _ _(_) _ _ (_) (____)" | |
echo " (____) (_)_(_) _(_) (_) (_) (_)(_)_(_)" | |
echo " (_)____ (_) (_)____(_)_(_) (_)(__)__ " | |
echo " (______)(_) (_)(_______)(____)(___)(____)" | |
echo " __(_) " | |
echo " (___) " | |
echo -e "\nAnsible container persistence helper.\n" | |
echo -e "Written by ExZyle <exzyle@protonmail.com>" | |
echo -e "Use with lesson 12 with USYD CyberSecurity Bootcamp 2022.\n" | |
echo -e "Provided without warranty.\n" | |
echo "Checking if a backup already exists.." | |
if [ -f $BACKUP_FILE ]; then | |
echo "Restoring from backup file..." | |
tar -xvzpf $BACKUP_FILE -C / | |
# /etc/hosts backup separately since tar extraction fails to override /etc/hosts. | |
# Don't know why, don't care enough to investigate ;) | |
echo "Restoring /etc/hosts..." | |
cp $BACKUP_DIR/hosts /etc/hosts | |
else | |
echo -e "No backup file found.\n\nYour first time? A backup file will be created when you 'exit' this shell." | |
fi | |
echo | |
bash | |
if [ ! -d $BACKUP_DIR ]; then | |
echo "Could be your first backup, better make the directory..." | |
mkdir $BACKUP_DIR | |
fi | |
echo -e "\nCreating a backup..." | |
tar cvzpf $BACKUP_FILE /etc/ansible ~/.ssh | |
echo "Backing up /etc/hosts..." | |
cp /etc/hosts $BACKUP_DIR/hosts | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment