-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·47 lines (38 loc) · 1.09 KB
/
Copy pathinstall
File metadata and controls
executable file
·47 lines (38 loc) · 1.09 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
#!/bin/bash
set -e
# Get XDG config directory
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
TARGET_DIR="$XDG_CONFIG_HOME/cmdbridge"
SOURCE_DIR="$(cd "$(dirname "$0")/configs" && pwd)"
# Check if source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Cannot find configs directory"
exit 1
fi
# Backup existing configuration
backup_existing() {
local counter=1
local backup_dir
while true; do
backup_dir="${TARGET_DIR}_${counter}"
if [ ! -d "$backup_dir" ]; then
if [ -d "$TARGET_DIR" ]; then
echo "Backing up existing configuration to: $backup_dir"
cp -r "$TARGET_DIR" "$backup_dir"
fi
break
fi
((counter++))
done
}
# Create target directory
mkdir -p "$(dirname "$TARGET_DIR")"
# Perform backup and installation
if [ -d "$TARGET_DIR" ]; then
backup_existing
echo "Removing old configuration: $TARGET_DIR"
rm -rf "$TARGET_DIR"
fi
echo "Installing new configuration to: $TARGET_DIR"
cp -r "$SOURCE_DIR" "$TARGET_DIR"
echo "Installation completed!"