-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.sh
66 lines (53 loc) · 2.05 KB
/
config.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
#!/bin/bash
# config.sh - Configuration file for WebDev Backup Tool
# Get the script's directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Default source directories - define as array
DEFAULT_SOURCE_DIRS=()
# Check for ~/webdev directory and add it if exists
if [ -d "$HOME/webdev" ]; then
DEFAULT_SOURCE_DIRS+=("$HOME/webdev")
fi
# Check for ~/inform6 directory and add it if exists
if [ -d "$HOME/inform6" ]; then
DEFAULT_SOURCE_DIRS+=("$HOME/inform6")
fi
# If no default directories found, try to use parent directory of script
if [ ${#DEFAULT_SOURCE_DIRS[@]} -eq 0 ]; then
# Try to use parent directory of script location
parent_dir="$(dirname "$SCRIPT_DIR")"
if [ -d "$parent_dir" ] && [ -r "$parent_dir" ]; then
DEFAULT_SOURCE_DIRS+=("$parent_dir")
else
# Fallback to script directory itself
DEFAULT_SOURCE_DIRS+=("$SCRIPT_DIR")
fi
fi
# For backward compatibility - first directory is the default
DEFAULT_SOURCE_DIR="${DEFAULT_SOURCE_DIRS[0]}"
# Default backup destination - pick a reliable location
DEFAULT_BACKUP_DIR="/mnt/d/backups"
if [ ! -d "$DEFAULT_BACKUP_DIR" ] || [ ! -w "$DEFAULT_BACKUP_DIR" ]; then
# Fallback to script directory if default isn't accessible
DEFAULT_BACKUP_DIR="$SCRIPT_DIR/backups"
# Create it if it doesn't exist
[ ! -d "$DEFAULT_BACKUP_DIR" ] && mkdir -p "$DEFAULT_BACKUP_DIR"
fi
# Default cloud provider
DEFAULT_CLOUD_PROVIDER="do"
# Log and test directories
LOGS_DIR="$SCRIPT_DIR/logs"
TEST_DIR="$SCRIPT_DIR/test"
mkdir -p "$LOGS_DIR" "$TEST_DIR"
# Date format for backup directories and logs
DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
DATE=$(date +$DATE_FORMAT)
# Backup naming convention
BACKUP_PREFIX="webdev_backup"
# Log files
BACKUP_HISTORY_LOG="$LOGS_DIR/backup_history.log"
TEST_HISTORY_LOG="$TEST_DIR/test_history.log"
# Export variables for use in other scripts
export SCRIPT_DIR DEFAULT_SOURCE_DIRS DEFAULT_SOURCE_DIR DEFAULT_BACKUP_DIR DEFAULT_CLOUD_PROVIDER
export LOGS_DIR TEST_DIR DATE_FORMAT DATE BACKUP_PREFIX
export BACKUP_HISTORY_LOG TEST_HISTORY_LOG