Fix sync script
This commit is contained in:
2 files changed
+153
-15
No files matched your search
+27
-15
@@ -12,7 +12,8 @@
|
||||
# - Mehrere Modi für verschiedene Szenarien
|
||||
################################################################################
|
||||
|
||||
set -euo pipefail
|
||||
# Note: Removed 'set -euo pipefail' as it breaks while-read loops with subshells
|
||||
# We handle errors explicitly instead
|
||||
|
||||
# Farben
|
||||
RED='\033[0;31m'
|
||||
@@ -40,23 +41,30 @@ AUTO_BACKUP=true
|
||||
################################################################################
|
||||
|
||||
log() {
|
||||
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*" | tee -a "$LOG_FILE"
|
||||
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*"
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $*" >&2 | tee -a "$LOG_FILE"
|
||||
echo -e "${RED}[ERROR]${NC} $*" >&2
|
||||
echo "[ERROR] $*" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[OK]${NC} $*" | tee -a "$LOG_FILE"
|
||||
echo -e "${GREEN}[OK]${NC} $*"
|
||||
echo "[OK] $*" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $*" | tee -a "$LOG_FILE"
|
||||
echo -e "${YELLOW}[WARN]${NC} $*"
|
||||
echo "[WARN] $*" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
verbose() {
|
||||
[[ "$VERBOSE" == true ]] && echo -e "${BLUE}[DEBUG]${NC} $*" | tee -a "$LOG_FILE"
|
||||
if [[ "$VERBOSE" == true ]]; then
|
||||
echo -e "${BLUE}[DEBUG]${NC} $*"
|
||||
echo "[DEBUG] $*" >> "$LOG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -68,10 +76,10 @@ get_checksum() {
|
||||
if [[ -f "$file" ]]; then
|
||||
if command -v md5 &> /dev/null; then
|
||||
# macOS
|
||||
md5 -q "$file"
|
||||
md5 -q "$file" 2>/dev/null
|
||||
elif command -v md5sum &> /dev/null; then
|
||||
# Linux
|
||||
md5sum "$file" | awk '{print $1}'
|
||||
md5sum "$file" 2>/dev/null | awk '{print $1}'
|
||||
else
|
||||
error "Weder md5 noch md5sum verfügbar"
|
||||
return 1
|
||||
@@ -141,22 +149,26 @@ mode_status() {
|
||||
local identical=0
|
||||
local modified=0
|
||||
local repo_only=0
|
||||
local repo_file
|
||||
local basename_file
|
||||
local home_file
|
||||
local status
|
||||
|
||||
while IFS= read -r file; do
|
||||
local repo_file="$REPO_DIR/$file"
|
||||
local basename=$(basename "$file")
|
||||
local home_file="$HOME_DIR/$basename"
|
||||
repo_file="$REPO_DIR/$file"
|
||||
basename_file=$(basename "$file")
|
||||
home_file="$HOME_DIR/$basename_file"
|
||||
|
||||
check_file_status "$repo_file" "$home_file"
|
||||
local status=$?
|
||||
status=$?
|
||||
|
||||
case $status in
|
||||
0)
|
||||
verbose "✓ identisch: $basename"
|
||||
verbose "✓ identisch: $basename_file"
|
||||
((identical++))
|
||||
;;
|
||||
3)
|
||||
warn "≠ geändert im Home: $basename"
|
||||
warn "≠ geändert im Home: $basename_file"
|
||||
if [[ "$VERBOSE" == true ]]; then
|
||||
echo " Repo: $(get_checksum "$repo_file")"
|
||||
echo " Home: $(get_checksum "$home_file")"
|
||||
@@ -164,7 +176,7 @@ mode_status() {
|
||||
((modified++))
|
||||
;;
|
||||
4)
|
||||
warn "✗ nur im Repo: $basename (nicht im Home)"
|
||||
warn "✗ nur im Repo: $basename_file (nicht im Home)"
|
||||
((repo_only++))
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in new issue
Block a user