-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-version
More file actions
executable file
·88 lines (69 loc) · 2.07 KB
/
new-version
File metadata and controls
executable file
·88 lines (69 loc) · 2.07 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
#!/bin/bash
VERBOSE=true # Set to true to enable verbose logging
# if no params are passed, display usage and exit
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <old-version> <new-version>"
exit 1
fi
# store current directory to return to it later
PWD=$(pwd)
# Full path of this script's directory, then append /html to it
BASE_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/html"
cd $BASE_PATH
dir1="$1"
dir2="$2"
# Check if dir1 exists under current directory
if [ ! -d "$dir1" ]; then
echo "Error: Directory '$dir1' does not exist under '$BASE_PATH'."
cd $PWD
exit 1
fi
# Check if dir2 does NOT exist under current directory
if [ -d "$dir2" ]; then
echo "Error: Directory '$dir2' already exists under '$BASE_PATH'."
cd $PWD
exit 1
fi
# make sure dir1 matches the pattern ^\d{2}\.\d{2}$, e.g. 24.10
if [[ ! "$dir1" =~ ^[0-9]{2}\.[0-9]{2}$ ]]; then
echo "Error: Param 1 should be in the format xx.xx, e.g. 24.10"
cd $PWD
exit 1
fi
# make sure dir2 matches the pattern ^\d{2}\.\d{2}$, e.g. 24.11
# and that it's greater than dir1
if [[ ! "$dir2" =~ ^[0-9]{2}\.[0-9]{2}$ ]]; then
echo "Error: Param 2 should be in the format xx.xx, e.g. 24.11"
cd $PWD
exit 1
fi
if [ "$dir2" \< "$dir1" ]; then
echo "Error: Param 2 should be greater than param 1"
cd $PWD
exit 1
fi
# Create dir2 under current directory
mkdir "$dir2"
# Iterate over the contents of dir1
for item in "$BASE_PATH/$dir1"/*; do
# if item is a symlink, resolve it
if [ -L "$item" ]; then
item=$(readlink -f "$item")
fi
# Remove the base path from the item's path
item=${item#$BASE_PATH/}
# create a symlink in dir2 pointing to the item
ln -s "../$item" "$dir2/$(basename $item)"
# Log copied files/links if VERBOSE is set to true
if [ "$VERBOSE" = "true" ]; then
echo "Copied: $item"
fi
done
# Update 'latest' symlink to point to dir2 (create if it doesn't exist)
ln -sfn "$dir2" "$BASE_PATH/latest"
if [ "$VERBOSE" = "true" ]; then
echo "Updated 'latest' symlink to point to $dir2"
fi
echo "New getting started guide $dir2 created successfully."
echo
cd $PWD