|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -uo pipefail |
| 3 | + |
| 4 | +# ============================================================================= |
| 5 | +# NAME : inhouse.sh |
| 6 | +# DESCRIPTION : Dynamically copy in-house tools from modules/extras into TOOLS_DIR |
| 7 | +# AUTHOR : Adam Compton |
| 8 | +# DATE CREATED: 2024-12-09 20:51:59 |
| 9 | +# ============================================================================= |
| 10 | +# EDIT HISTORY: |
| 11 | +# DATE | EDITED BY | DESCRIPTION OF CHANGE |
| 12 | +# ---------------------|--------------|---------------------------------------- |
| 13 | +# 2024-12-09 20:51:59 | Adam Compton | Initial creation. |
| 14 | +# ============================================================================= |
| 15 | + |
| 16 | +# Guard to prevent multiple sourcing |
| 17 | +if [[ -z "${INHOUSE_SH_LOADED:-}" ]]; then |
| 18 | + declare -g INHOUSE_SH_LOADED=true |
| 19 | + |
| 20 | + # Ensure environment variables exist |
| 21 | + if [[ -z "${SCRIPT_DIR:-}" || -z "${TOOLS_DIR:-}" ]]; then |
| 22 | + echo "[ERROR] SCRIPT_DIR and TOOLS_DIR must be defined before sourcing this script." |
| 23 | + return 1 2> /dev/null || exit 1 |
| 24 | + fi |
| 25 | + |
| 26 | + src_dir="${SCRIPT_DIR}/modules/extras" |
| 27 | + |
| 28 | + # Confirm source directory exists |
| 29 | + if [[ ! -d "${src_dir}" ]]; then |
| 30 | + fail "Source directory [${src_dir}] does not exist. Nothing to process." |
| 31 | + else |
| 32 | + shopt -s nullglob |
| 33 | + for dir in "${src_dir}"/*/; do |
| 34 | + dir="${dir%/}" |
| 35 | + name="$(basename -- "${dir}")" |
| 36 | + dest="${TOOLS_DIR%/}/${name}" |
| 37 | + |
| 38 | + # Skip if not a directory (defensive) |
| 39 | + [[ -d "${dir}" ]] || { |
| 40 | + warn "Skipping non-directory: ${dir}" |
| 41 | + continue |
| 42 | + } |
| 43 | + |
| 44 | + # Skip if destination already exists |
| 45 | + if [[ -e "${dest}" ]]; then |
| 46 | + warn "Destination already exists: ${dest}. Skipping ${name}." |
| 47 | + continue |
| 48 | + fi |
| 49 | + |
| 50 | + # Attempt copy |
| 51 | + if cp -r -- "${dir}" "${TOOLS_DIR}/"; then |
| 52 | + pass "Copied ${name} to ${TOOLS_DIR}/" |
| 53 | + else |
| 54 | + fail "Failed to copy ${name} to ${TOOLS_DIR}/" |
| 55 | + continue |
| 56 | + fi |
| 57 | + |
| 58 | + # Special case for impacket |
| 59 | + if [[ "${name,,}" == "impacket" ]]; then |
| 60 | + if declare -F Install_Impacket > /dev/null 2>&1; then |
| 61 | + pass "Detected impacket; running Install_Impacket()..." |
| 62 | + if Install_Impacket; then |
| 63 | + pass "Install_Impacket completed successfully for ${dest}." |
| 64 | + else |
| 65 | + fail "Install_Impacket returned non-zero for ${dest}." |
| 66 | + fi |
| 67 | + else |
| 68 | + warn "Copied impacket to ${dest}, but Install_Impacket() is not defined." |
| 69 | + fi |
| 70 | + fi |
| 71 | + done |
| 72 | + shopt -u nullglob |
| 73 | + fi |
| 74 | +fi |
0 commit comments