-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqbupdate.sh
61 lines (49 loc) · 1.68 KB
/
qbupdate.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
#!/bin/bash
printf "Input resources folder: "
read resourceFolder
# Validate input folder path
if [[ ! -d "$resourceFolder" ]]; then
printf "\nInvalid folder path\n"
exit 1
fi
handleResource() {
local resourcePath="$1"
local name
name="$(basename "$resourcePath")"
printf "Handling resource: %s\n" "$name"
# Check if the GitHub repository exists
local responseCode
responseCode=$(curl -s -o /dev/null -w "%{http_code}" "https://api.github.com/repos/qbcore-framework/${name}")
if [[ "$responseCode" -eq 404 ]]; then
printf "Could not find qbcore resource named %s\n" "$name"
printf "\n"
return
fi
# Navigate to the resource directory
cd "$resourcePath" || {
printf "Failed to navigate to %s\n" "$resourcePath"
return
}
# Initialize Git if not already done
if [[ ! -d ".git" ]]; then
printf "Initializing Git for %s\n" "$name"
git clone --no-checkout "https://github.com/qbcore-framework/${name}" tempGit || {
printf "Git clone failed for %s\n" "$name"
return
}
mv tempGit/.git ./.git
rm -rf tempGit
else
printf "Git already initialized for %s\n" "$name"
fi
# Fetch and pull updates
printf "Fetching and pulling latest updates for %s\n" "$name"
git fetch || printf "Failed to fetch for %s\n" "$name"
git pull || printf "Failed to pull for %s\n" "$name"
printf "\n"
}
# Export the function for use in 'find -exec'
export -f handleResource
# Find and process all matching resource directories
find "$resourceFolder" -type d -name "*qb-*" -exec bash -c 'handleResource "$0"' {} \;
printf "Processing complete.\n"