-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwomm.sh
100 lines (86 loc) · 3.47 KB
/
womm.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
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
#!/bin/bash
# Configurable paths
CODE_DIR="/Users/jonatanjansson/Code"
SITES_DIR="/Users/jonatanjansson/Sites/Latest Local ProductSite/ProductSite.com/app/public"
# Check if whiptail is installed
if ! command -v whiptail &> /dev/null; then
echo "Error: 'whiptail' is not installed. Please install it to proceed."
exit 1
fi
# Display menu
CHOICE=$(whiptail --title "Work On My Machine" --menu "Choose an option" 15 60 3 \
"1" "Download Dev" \
"2" "Update Local" \
"3" "Sync Latest From Local" 3>&1 1>&2 2>&3)
# Check if the user canceled the menu
if [ $? -ne 0 ]; then
echo "Operation canceled by user."
exit 1
fi
case $CHOICE in
1)
# Download Dev
DATE_SUFFIX=$(date +"%d%m%y")
NEW_FOLDER="$CODE_DIR/ProductSiteDev$DATE_SUFFIX"
echo "Creating folder: $NEW_FOLDER"
if mkdir -p "$NEW_FOLDER"; then
echo "Successfully created directory."
else
echo "Error: Failed to create directory $NEW_FOLDER"
exit 1
fi
echo "Cloning repository into $NEW_FOLDER"
if git clone [email protected]:thirdparty/wp-ProductSite.com.git "$NEW_FOLDER/wp-ProductSite.com"; then
echo "Repository cloned successfully."
else
echo "Error: Git clone failed."
exit 1
fi
;;
2)
# Update Local
PUBLIC_DIR="$SITES_DIR"
TEMP_DIR=$(mktemp -d)
echo "Backing up wp-config.php and .sql files to temporary directory: $TEMP_DIR"
cp "$PUBLIC_DIR/wp-config.php" "$TEMP_DIR/" || { echo "Error: Failed to copy wp-config.php"; exit 1; }
cp "$PUBLIC_DIR"/*.sql "$TEMP_DIR/" 2>/dev/null
echo "Locating the latest ProductSiteDev directory..."
LATEST_DEV=$(ls -d "$CODE_DIR"/ProductSiteDev* 2>/dev/null | sort | tail -n 1)
if [ -z "$LATEST_DEV" ]; then
echo "Error: No ProductSiteDev directories found in $CODE_DIR"
exit 1
else
echo "Latest development directory found: $LATEST_DEV"
fi
echo "Updating local files..."
rsync -av --delete "$LATEST_DEV/wp-ProductSite.com/" "$PUBLIC_DIR/" || { echo "Error: Failed to sync files."; exit 1; }
echo "Restoring wp-config.php and .sql files..."
cp "$TEMP_DIR/wp-config.php" "$PUBLIC_DIR/" || { echo "Error: Failed to restore wp-config.php"; exit 1; }
cp "$TEMP_DIR"/*.sql "$PUBLIC_DIR/" 2>/dev/null
echo "Removing object-cache.php from wp-content directory..."
rm -f "$PUBLIC_DIR/wp-content/object-cache.php"
echo "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
echo "Local update completed successfully."
;;
3)
# Sync Latest From Local
PUBLIC_DIR="$SITES_DIR"
echo "Locating the latest ProductSiteDev directory..."
LATEST_DEV=$(ls -d "$CODE_DIR"/ProductSiteDev* 2>/dev/null | sort | tail -n 1)
if [ -z "$LATEST_DEV" ]; then
echo "Error: No ProductSiteDev directories found in $CODE_DIR"
exit 1
else
echo "Latest development directory found: $LATEST_DEV"
fi
DEV_DIR="$LATEST_DEV/wp-ProductSite.com"
echo "Syncing newer files from Local to Dev directory..."
rsync -av --update "$PUBLIC_DIR/" "$DEV_DIR/" --exclude 'wp-config.php' --exclude '*.sql' || { echo "Error: Failed to sync files."; exit 1; }
echo "Sync completed successfully."
;;
*)
echo "Invalid option selected."
exit 1
;;
esac