-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.sh
More file actions
235 lines (213 loc) · 9.24 KB
/
config.sh
File metadata and controls
235 lines (213 loc) · 9.24 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# config.sh - Configuration file for WebDev Backup Tool
#
# ==================================================================================
# SINGLE SOURCE OF TRUTH - Edit the section below to customize your backup.
# Works on both macOS and Linux.
#
# REQUIRED: You must set at least one SOURCE directory and one DESTINATION
# directory. The app will not run until both are configured.
# ==================================================================================
# ==================================================================================
# USER CONFIGURATION - EDIT THESE SETTINGS
# ==================================================================================
#
# SOURCE DIRECTORIES (what to back up)
# ------------------------------------
# Required: Add at least one directory. The app will not start without it.
#
# ---------------
# macOS examples:
# ---------------
# $HOME = internal boot disk. /Volumes/VolumeName = external drive (no $HOME).
# Many devs keep the OS on the internal disk and store code/data on externals.
#
# Internal disk (home directory):
# DEFAULT_SOURCE_DIRS=("$HOME/Developer")
# DEFAULT_SOURCE_DIRS=("$HOME/Developer" "$HOME/Documents/Projects")
# DEFAULT_SOURCE_DIRS=("$HOME")
#
# External volume (use your volume name as shown in Finder):
# DEFAULT_SOURCE_DIRS=("/Volumes/MySSD/Developer")
# DEFAULT_SOURCE_DIRS=("/Volumes/Code/projects" "/Volumes/Code/repos")
# Mix of internal + external:
# DEFAULT_SOURCE_DIRS=("$HOME/Developer" "/Volumes/MySSD/Projects")
#
# ---------------
# Linux examples:
# ---------------
# $HOME or /home/username = typically boot/internal disk. /mnt/... = mounted
# drive (external, second disk, WSL2, or network). Many devs keep OS on the
# main disk and store code/data on a separate drive or mount.
#
# Internal disk (home directory):
# DEFAULT_SOURCE_DIRS=("/home/username/projects")
# DEFAULT_SOURCE_DIRS=("$HOME/projects" "$HOME/repos" "$HOME/code")
# DEFAULT_SOURCE_DIRS=("$HOME")
#
# Mounted drive (use your actual mount point under /mnt/ or /media/):
# DEFAULT_SOURCE_DIRS=("/mnt/data/projects")
# DEFAULT_SOURCE_DIRS=("/mnt/ssd/developer" "/mnt/ssd/repos")
# Mix of internal + mounted:
# DEFAULT_SOURCE_DIRS=("$HOME/projects" "/mnt/data/legacy-code")
#
# --- WSL2 (Windows Subsystem for Linux) ---
# In WSL2, Windows drives are under /mnt/<letter>/ (e.g. C: = /mnt/c).
# External USB drives: Windows assigns a drive letter (e.g. E:); use
# /mnt/e/ in WSL2. There is no /media/ auto-mount for USB like native
# Linux—always use /mnt/<letter>/. Drive letters can change if you
# plug in devices in a different order. Access to /mnt/ is slower than
# the Linux filesystem; keep sources on $HOME when possible, use /mnt/
# for backup destination if you want backups on a Windows-visible drive.
# DEFAULT_SOURCE_DIRS=("/mnt/d/Projects")
# DEFAULT_SOURCE_DIRS=("$HOME/projects" "/mnt/d/legacy")
#
# Configure at least one source (replace with your own paths):
#
DEFAULT_SOURCE_DIRS=("/Volumes/satechi/webdev")
#
# DESTINATION DIRECTORY (where to store backups)
# ----------------------------------------------
# Required: Set a path. The app will not start without it.
#
# ---------------
# macOS examples:
# ---------------
# $HOME = internal disk. /Volumes/VolumeName = external (no $HOME).
# Storing backups on an external is recommended to save space on the boot disk.
#
# Internal disk:
# DEFAULT_BACKUP_DIR="$HOME/backups"
#
# External volume (use the exact name shown in Finder under /Volumes/):
# DEFAULT_BACKUP_DIR="/Volumes/MyExternalDrive/backups"
# DEFAULT_BACKUP_DIR="/Volumes/Backup/backups"
# DEFAULT_BACKUP_DIR="/Volumes/MySSD/backups"
# Internal "Macintosh HD" (not recommended; use external if possible):
# DEFAULT_BACKUP_DIR="/Volumes/Macintosh HD/Backups"
#
# ---------------
# Linux examples:
# ---------------
# $HOME or /home/username = internal disk. /mnt/... = mounted drive (no $HOME).
# Storing backups on a separate drive or mount is recommended when possible.
#
# Internal disk:
# DEFAULT_BACKUP_DIR="$HOME/backups"
# DEFAULT_BACKUP_DIR="/home/username/backups"
#
# Mounted drive (native Linux; use your mount point under /mnt/ or /media/):
# DEFAULT_BACKUP_DIR="/mnt/backup/backups"
# DEFAULT_BACKUP_DIR="/mnt/external/backups"
# DEFAULT_BACKUP_DIR="/media/username/ExternalDrive/backups"
#
# --- WSL2: backing up to an external or Windows drive ---
# Use /mnt/<letter>/ only. Windows assigns letters (C:, D:, E: = /mnt/c,
# /mnt/d, /mnt/e). External USB = whatever letter Windows gives it (e.g.
# E: → /mnt/e/backups). Ensure the drive is visible in Windows Explorer
# first; then use that letter under /mnt/. No /media/ in WSL2.
# DEFAULT_BACKUP_DIR="/mnt/e/backups"
# DEFAULT_BACKUP_DIR="/mnt/d/Backups"
#
# Configure your destination (replace with your own path):
#
DEFAULT_BACKUP_DIR="/volumes/macssd/backups"
#
# Cloud storage provider (reserved for a later iteration)
# Leave blank for now. Cloud backup will be supported in a future release.
#
DEFAULT_CLOUD_PROVIDER=""
#
# BACKUP VERIFICATION (recommended: on)
# --------------------------------------
# After each archive is created, the backup can be verified for integrity.
# "true" = verification on by default (recommended).
# "false" = verification off by default (faster; use for quick backups if desired).
#
# When running interactively (including Quick Backup), you are always asked
# whether to enable or disable verification; this setting is the default
# for that prompt (e.g. [Y/n] when true, [y/N] when false).
#
DEFAULT_VERIFY_BACKUP=true
# ==================================================================================
# END OF USER CONFIGURATION
# ==================================================================================
#
# Do not change anything below unless you know what you are doing.
#
# ==================================================================================
# ==================================================================================
# INTERNAL CONFIGURATION - DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING
# ==================================================================================
# Version and paths (required by scripts)
VERSION="1.7.0"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FIRST_RUN_MARKER="$SCRIPT_DIR/.configured"
# Backup naming and date format
BACKUP_PREFIX="webdev_backup"
DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
# When running the test suite, always use test defaults (CI and local runs)
# This overrides user config so tests pass regardless of committed paths
if [ -n "${RUNNING_TESTS:-}" ]; then
DEFAULT_SOURCE_DIRS=("$SCRIPT_DIR/test")
DEFAULT_BACKUP_DIR="$SCRIPT_DIR/test/backup_out"
fi
# ----------------------------------------------------------------------------------
# Validation: require at least one source and one destination (manual config required)
# ----------------------------------------------------------------------------------
_config_file="${SCRIPT_DIR}/config.sh"
if [ ${#DEFAULT_SOURCE_DIRS[@]} -eq 0 ]; then
echo ""
echo "ERROR: No source directory configured."
echo ""
echo " You must set at least one SOURCE in:"
echo " ${_config_file}"
echo ""
echo " Edit DEFAULT_SOURCE_DIRS=() and add your folder(s). Examples:"
echo " macOS: DEFAULT_SOURCE_DIRS=(\"\$HOME/Developer\")"
echo " Linux: DEFAULT_SOURCE_DIRS=(\"/home/username/projects\")"
echo ""
exit 1
fi
if [ -z "$DEFAULT_BACKUP_DIR" ]; then
echo ""
echo "ERROR: No destination directory configured."
echo ""
echo " You must set DESTINATION in:"
echo " ${_config_file}"
echo ""
echo " Edit DEFAULT_BACKUP_DIR=\"\" and set a path. Examples:"
echo " macOS: DEFAULT_BACKUP_DIR=\"\$HOME/backups\""
echo " Linux: DEFAULT_BACKUP_DIR=\"\$HOME/backups\""
echo ""
exit 1
fi
# Derived defaults (only reached when config is valid)
DEFAULT_SOURCE_DIR="${DEFAULT_SOURCE_DIRS[0]}"
# Ensure backup directory exists and is writable
if [ ! -d "$DEFAULT_BACKUP_DIR" ]; then
if ! mkdir -p "$DEFAULT_BACKUP_DIR" 2>/dev/null; then
echo ""
echo "ERROR: Could not create backup directory: $DEFAULT_BACKUP_DIR"
echo " Check permissions or choose a different path in: ${_config_file}"
echo ""
exit 1
fi
elif [ ! -w "$DEFAULT_BACKUP_DIR" ]; then
echo ""
echo "ERROR: Backup directory is not writable: $DEFAULT_BACKUP_DIR"
echo " Fix permissions or choose a different path in: ${_config_file}"
echo ""
exit 1
fi
# Runtime paths and exports
DATE=$(date +$DATE_FORMAT)
LOGS_DIR="$SCRIPT_DIR/logs"
TEST_DIR="$SCRIPT_DIR/test"
mkdir -p "$LOGS_DIR" "$TEST_DIR"
BACKUP_HISTORY_LOG="$LOGS_DIR/backup_history.log"
TEST_HISTORY_LOG="$TEST_DIR/test_history.log"
BACKUP_DIR="$DEFAULT_BACKUP_DIR"
export SCRIPT_DIR DEFAULT_SOURCE_DIRS DEFAULT_SOURCE_DIR DEFAULT_BACKUP_DIR BACKUP_DIR DEFAULT_CLOUD_PROVIDER DEFAULT_VERIFY_BACKUP
export LOGS_DIR TEST_DIR DATE_FORMAT DATE BACKUP_PREFIX
export BACKUP_HISTORY_LOG TEST_HISTORY_LOG VERSION FIRST_RUN_MARKER