-
Notifications
You must be signed in to change notification settings - Fork 0
/
reapack
executable file
·120 lines (98 loc) · 3.51 KB
/
reapack
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
# Improved Error Handling Function
exit_with_error() {
echo "Error: $1"
exit 1
}
# Set working directory to the location of the script
cd "$(dirname "$0")" || exit_with_error "Failed to change directory to script location."
# Define global variables
main_dir_path="$PWD"
parent_dir_path=$(dirname "$PWD")
# Function to check if a directory is a Git repository
is_git_repo() {
git -C "$1" rev-parse 2>/dev/null
}
# Function to check if a git repo is clean
is_repo_clean() {
test -z "$(git status --porcelain)"
}
# Function to prompt for user confirmation
prompt_user() {
while true; do
read -n 1 -p "$1 (y/N): " response
echo ""
case "$response" in
[yY]) return 0 ;;
[nN]) return 1 ;;
*) echo "Please enter y or n." ;;
esac
done
}
# Function to get current git branch
get_current_branch() {
git rev-parse --abbrev-ref HEAD
}
# Function to handle git operations
handle_git_operations() {
cd "$1" || exit_with_error "Failed to change directory to $1."
if ! is_git_repo "$1"; then
exit_with_error "$1 is not a git repository."
fi
local current_branch=$(get_current_branch)
local current_dir_name=$(basename "$(pwd)")
if ! is_repo_clean; then
if prompt_user "$current_dir_name repository has uncommitted changes. Do you want to commit them?"; then
git add .
git commit -m "Committing changes from script" || exit_with_error "Failed to commit changes in $current_dir_name."
else
if prompt_user "Do you want to continue without committing the changes in $current_dir_name?"; then
echo "Continuing without committing changes."
else
echo "Exiting."
exit 1
fi
fi
fi
if $2; then # second argument to true to commit only
return
fi
if prompt_user "Do you want to push the changes in $current_dir_name on branch $current_branch?"; then
git push origin "$current_branch" || exit_with_error "Failed to push changes in $current_dir_name."
echo "Changes pushed successfully."
else
echo "Changes not pushed. Exiting."
exit 1
fi
}
# Commit and push changes if needed
handle_git_operations "$PWD" true
# Run reapack-index and check if it succeeds
reapack-index "$(pwd)" || exit_with_error "reapack-index command failed."
# Remove old index-min.xml
rm -f index-min.xml
# Run reapack-index again but on index-min.xml
reapack-index "$(pwd)" --output ./index-min.xml || exit_with_error "reapack-index command failed."
# Push index.xml
handle_git_operations "$PWD" false
# Debug check: Ask the user if they want to continue
if ! prompt_user "Do you want to submit the index to nvk.tools and reapleton.com?"; then
echo "Exiting as per user's request."
exit 1
fi
# Handle git operations for nvk.tools and Reapleton
for repo in nvk.tools-website/static; do
repo_path="$parent_dir_path/$repo"
if ! handle_git_operations "$repo_path" false; then
break
fi
# Copy and commit index.xml
if cp "$main_dir_path/index-min.xml" "$repo_path/index.xml"; then
cd "$repo_path" || exit_with_error "Failed to change directory to $repo_path."
git add index.xml
git commit -m "Update index.xml" || exit_with_error "Failed to commit index.xml in $repo."
git push origin "$(get_current_branch)" || exit_with_error "Failed to push changes in $repo."
else
exit_with_error "Error copying to $repo."
fi
done