-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·81 lines (72 loc) · 1.99 KB
/
deploy.sh
File metadata and controls
executable file
·81 lines (72 loc) · 1.99 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
#!/bin/bash
#
# Deploy LocalhostIndex to parent Sites folder
#
# Usage:
# ./deploy.sh Deploy index.php only
# ./deploy.sh --full Deploy index.php + favicon
# ./deploy.sh --backup Save previous as index_old_1.php, index_old_2.php, etc.
# ./deploy.sh --full --backup Both options
#
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TARGET_DIR="$(dirname "$SCRIPT_DIR")"
# Parse arguments
FULL=false
BACKUP=false
for arg in "$@"; do
case $arg in
--full)
FULL=true
;;
--backup)
BACKUP=true
;;
--help|-h)
echo "Usage: ./deploy.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --full Also copy favicon.png"
echo " --backup Save previous index.php as index_old_N.php"
echo " --help Show this help"
exit 0
;;
*)
echo "Unknown option: $arg"
echo "Use --help for usage"
exit 1
;;
esac
done
# Check source exists
if [ ! -f "$SCRIPT_DIR/index.php" ]; then
echo "Error: Source file not found: $SCRIPT_DIR/index.php"
exit 1
fi
# Backup existing index.php if --backup and file exists
if [ "$BACKUP" = true ] && [ -f "$TARGET_DIR/index.php" ]; then
# Find next available _old_N number
N=1
while [ -f "$TARGET_DIR/index_old_${N}.php" ]; do
((N++))
done
cp "$TARGET_DIR/index.php" "$TARGET_DIR/index_old_${N}.php"
echo "Backup: index.php -> index_old_${N}.php"
fi
# Deploy index.php
cp "$SCRIPT_DIR/index.php" "$TARGET_DIR/index.php"
if [ $? -eq 0 ]; then
echo "Deployed: index.php"
else
echo "Error: Failed to deploy index.php"
exit 1
fi
# Deploy favicon if --full
if [ "$FULL" = true ]; then
if [ -f "$SCRIPT_DIR/favicon.png" ]; then
cp "$SCRIPT_DIR/favicon.png" "$TARGET_DIR/favicon.png"
echo "Deployed: favicon.png"
else
echo "Warning: favicon.png not found, skipped"
fi
fi
echo "Done!"