forked from e-m-b-a/embark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-DB.sh
executable file
·70 lines (57 loc) · 1.76 KB
/
import-DB.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# EMBArk - The firmware security scanning environment
#
# Copyright 2020-2024 Siemens Energy AG
#
# EMBArk comes with ABSOLUTELY NO WARRANTY.
#
# EMBArk is licensed under MIT
#
# Author(s): Benedikt Kuehne
# Description: Automates import of db file for quick transfer between systems and general usability
export WSL=0
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export ORANGE='\033[0;33m'
export BLUE='\033[0;34m'
export BOLD='\033[1m'
export NC='\033[0m' # no color
import_helper()
{
local HELPERS=()
local HELPER_COUNT=0
local HELPER_FILE=""
local HELP_DIR='helper'
mapfile -d '' HELPERS < <(find "${HELP_DIR}" -iname "helper_embark_*.sh" -print0 2> /dev/null)
for HELPER_FILE in "${HELPERS[@]}" ; do
if ( file "${HELPER_FILE}" | grep -q "shell script" ) && ! [[ "${HELPER_FILE}" =~ \ |\' ]] ; then
# https://github.com/koalaman/shellcheck/wiki/SC1090
# shellcheck source=/dev/null
source "${HELPER_FILE}"
(( HELPER_COUNT+=1 ))
fi
done
echo -e "\\n""==> ""${GREEN}""Imported ""${HELPER_COUNT}"" necessary files""${NC}\\n"
}
ALT_BACKUP_FILE="${1:-}"
export BACKUP_FILE=""
if [[ -n "${ALT_BACKUP_FILE}" ]]; then
if ! [[ -f "${ALT_BACKUP_FILE}" ]]; then
echo -e "\\n${RED}""Error with input for BACKUP FILE!""${NC}\\n"
exit 1
fi
BACKUP_FILE="${ALT_BACKUP_FILE}"
else
BACKUP_FILE="$(find . -type f -iname "full-backup-*.tar" | sort -n | tail -n 1)"
fi
cd "$(dirname "${0}")" || exit 1
if ! [[ ${EUID} -eq 0 ]] ; then
echo -e "\\n${RED}""Run script with root permissions!""${NC}\\n"
exit 1
fi
echo "USER is ${SUDO_USER:-${USER}}"
import_helper
tar -xf "${BACKUP_FILE}"
rsync -a --progress ./.embark_db_backup/ ./embark_db/
rm -rf ./.embark_db_backup/
echo -e "\\n""==> ""${GREEN}""Import successful""${NC}"