Added tests.sh script, Makefile and updated documentation
This commit is contained in:
parent
8eb13e481c
commit
f98a7e2269
15
Makefile
Normal file
15
Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
all:
|
||||
install
|
||||
|
||||
install:
|
||||
mkdir -p /usr/local/share/man/man1
|
||||
cp -R backup.sh /usr/local/bin/backup.sh
|
||||
cp -R backup.source.bk /usr/local/etc/backup_sources.bk
|
||||
cp -R backup.sh.1 /usr/local/share/man/man1/backup.sh.1
|
||||
chmod 755 /usr/local/bin/backup.sh
|
||||
chmod 644 /usr/local/etc/backup_sources.bk
|
||||
|
||||
uninstall:
|
||||
rm -rf /usr/local/bin/backup.sh
|
||||
rm -ff /usr/local/etc/backup_sources.bk
|
||||
rm -rf /usr/local/share/man/man1/backup.sh.1
|
16
README.md
16
README.md
@ -11,7 +11,8 @@ Alternatively, you can install the script, the default sources file and the man
|
||||
$> sudo make install
|
||||
```
|
||||
This will copy `backup.sh` into `/usr/local/bin/backup.sh`, `backup_sources.bk` into `/usr/local/etc/backup_sources.bk` and
|
||||
`backup.sh.1` into `/usr/local/share/man/man1`.
|
||||
`backup.sh.1` into `/usr/local/share/man/man1`. To uninstall the program along with the sample _sources file_ and the manual page,
|
||||
you can issue `sudo make uninstall`.
|
||||
|
||||
At this point you still need to install the following dependencies:
|
||||
- `rsync`
|
||||
@ -164,6 +165,17 @@ function;
|
||||
- `-salt`: **enable salting**: this option tells openssl to add a random salt to the key derivation process in order to
|
||||
avoid rainbow table based attacks.
|
||||
|
||||
|
||||
## Unit tests
|
||||
`backup.sh` provides some unit tests inside the `tests.sh` script. This script generates some dummy files inside the following
|
||||
directories:
|
||||
- /var/log
|
||||
- /var/www
|
||||
- /etc/nginx
|
||||
- /etc/ssh
|
||||
|
||||
For this reason, this script should **NOT** be used in non-testing environments. To run all tests, issue the following command:
|
||||
```sh
|
||||
$> sudo ./tests.sh I_HAVE_READ_THE_HELPER
|
||||
```
|
||||
|
||||
## License
|
||||
|
89
tests.sh
Executable file
89
tests.sh
Executable file
@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
# Unit tests for backup.sh
|
||||
# This tool is NOT intended to be used outside
|
||||
# of a testing environment, please use at your own risk.
|
||||
# By Marco Cetica 2023 (<email@marcocetica.com>)
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
helper() {
|
||||
cat <<EOF
|
||||
backup.sh unit testing suite.
|
||||
Do **NOT** use this tool outside of a testing environment.
|
||||
|
||||
This tool creates a lot of dummy files to emulate a real production
|
||||
environment. Any file inside the following directories will be overwritten:
|
||||
- /var/log
|
||||
- /var/www
|
||||
- /etc/nginx
|
||||
- /etc/ssh
|
||||
|
||||
Please, use at your own risk.
|
||||
To acknowledge that, run again this tool with 'I_HAVE_READ_THE_HELPER' as a parameter.
|
||||
EOF
|
||||
}
|
||||
|
||||
create_files() {
|
||||
mkdir -p /etc/{ssh,nginx}
|
||||
mkdir -p /var/{www,log}
|
||||
|
||||
touch /etc/ssh/{ssh_config,sshd_config,moduli,ssh_host_dsa_key}
|
||||
touch /etc/nginx/{nginx.conf,fastcgi.conf,mime.types}
|
||||
touch /var/www/{index.html,style.css,logic.js}
|
||||
touch /var/log/{access.log,error.log,lastlog,messages}
|
||||
|
||||
for file in ssh_config sshd_config moduli ssh_host_dsa_key ; do
|
||||
head -c 1M </dev/random > /etc/ssh/$file
|
||||
done
|
||||
|
||||
for file in index.html style.css logic.js ; do
|
||||
head -c 1M </dev/random > /var/www/$file
|
||||
done
|
||||
|
||||
for file in nginx.conf fastcgi.conf mime.types ; do
|
||||
head -c 1M </dev/random > /etc/nginx/$file
|
||||
done
|
||||
|
||||
for file in access.log error.log lastlog messages ; do
|
||||
head -c 1M </dev/random > /var/log/$file
|
||||
done
|
||||
}
|
||||
|
||||
execute_backup() {
|
||||
./backup.sh -b backup_sources.bk "$PWD" badpw
|
||||
}
|
||||
|
||||
extract_backup() {
|
||||
./backup.sh -e "$PWD"/backup-*-*.tar.gz.enc badpw
|
||||
}
|
||||
|
||||
test_backup() {
|
||||
for dir in "$PWD/backup.sh.tmp/"backup-*-* ; do
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo "Can't find '$dir' backup!"
|
||||
exit 1
|
||||
else
|
||||
echo "Found '$dir'"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
helper
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$1" = "I_HAVE_READ_THE_HELPER" ]; then
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "Run this tool as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
create_files
|
||||
execute_backup
|
||||
extract_backup
|
||||
test_backup
|
||||
fi
|
Loading…
Reference in New Issue
Block a user