-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakepkg.sh
More file actions
182 lines (153 loc) · 6.38 KB
/
Copy pathmakepkg.sh
File metadata and controls
182 lines (153 loc) · 6.38 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
tmpdir="/tmp/tmp.$((RANDOM * 19318203981230))"
par2tmpdir="/tmp/tmp.par2.$((RANDOM * 19318203981230))"
plugin=$(basename "$DIR")
base_version=$(date +"%Y.%m.%d")
packages_dir="$DIR/packages"
# Find an available version suffix
version=$base_version
archive="par2protect-$version-x86_64"
if [ -f "$packages_dir/$archive.txz" ] || [ -f "$packages_dir/$archive.md5" ]; then
# Start with "a" as the first suffix
char_code=97 # ASCII code for 'a'
while true; do
suffix=$(printf "\\$(printf '%03o' $char_code)")
archive="par2protect-$base_version$suffix-x86_64"
if [ ! -f "$packages_dir/$archive.txz" ] && [ ! -f "$packages_dir/$archive.md5" ]; then
break
fi
char_code=$((char_code + 1))
# Just in case we go beyond 'z'
if [ $char_code -gt 122 ]; then
echo "Error: Too many versions for today, please clean up packages directory."
exit 1
fi
done
fi
echo "Creating package $archive..."
# Create temporary and packages directories
mkdir -p "$tmpdir"
mkdir -p "$packages_dir"
# Get the latest par2cmdline-turbo version information
echo "Checking for latest par2cmdline-turbo..."
PAR2_LATEST_URL=$(curl -s https://api.github.com/repos/animetosho/par2cmdline-turbo/releases/latest | grep "browser_download_url.*linux.*amd64" | cut -d '"' -f 4)
PAR2_VERSION=$(echo "$PAR2_LATEST_URL" | grep -oP 'v\d+\.\d+\.\d+' | head -1)
PAR2_ARCHIVE="par2cmdline-turbo-${PAR2_VERSION}-x86_64"
if [ -z "$PAR2_LATEST_URL" ]; then
echo "Error: Could not determine latest par2cmdline-turbo URL."
exit 1
fi
# Check if we already have this version packaged
PAR2_NEEDS_PACKAGING=true
if [ -f "$packages_dir/$PAR2_ARCHIVE.txz" ] && [ -f "$packages_dir/$PAR2_ARCHIVE.md5" ]; then
echo "par2cmdline-turbo $PAR2_VERSION is already packaged."
PAR2_NEEDS_PACKAGING=false
else
echo "New version of par2cmdline-turbo detected: $PAR2_VERSION"
# Check if any older versions exist
EXISTING_PAR2_PACKAGES=$(find "$packages_dir" -name "par2cmdline-turbo-*.txz" | wc -l)
if [ "$EXISTING_PAR2_PACKAGES" -gt 0 ]; then
echo "Replacing older par2cmdline-turbo package(s)."
# Optionally, remove old packages here if needed
fi
fi
# Download and package par2cmdline-turbo if needed
if [ "$PAR2_NEEDS_PACKAGING" = true ]; then
mkdir -p "$par2tmpdir"
echo "Downloading par2cmdline-turbo $PAR2_VERSION..."
# Download to temporary file first
temp_download="$par2tmpdir/par2cmdline-turbo.tmp"
wget -q -O "$temp_download" "$PAR2_LATEST_URL"
if [ $? -ne 0 ]; then
echo "Error: Failed to download par2cmdline-turbo."
rm -rf "$par2tmpdir"
exit 1
fi
# Detect file type using file command
file_type=$(file -b "$temp_download")
echo "Extracting par2cmdline-turbo..."
# Extract based on detected file type
if echo "$file_type" | grep -q "XZ compressed"; then
# Handle XZ compressed file
mv "$temp_download" "$par2tmpdir/par2cmdline-turbo.xz"
xz -d "$par2tmpdir/par2cmdline-turbo.xz"
extracted_file="$par2tmpdir/par2cmdline-turbo"
elif echo "$file_type" | grep -q "Zip archive"; then
# Handle ZIP file
mv "$temp_download" "$par2tmpdir/par2cmdline-turbo.zip"
cd "$par2tmpdir" || exit 1
unzip -q "par2cmdline-turbo.zip"
# Find the extracted executable (might have different names)
extracted_file=$(find "$par2tmpdir" -type f -executable -name "*par2*" | head -1)
# If no executable found, look for common names
if [ -z "$extracted_file" ]; then
for name in par2cmdline-turbo par2 par2cmdline; do
if [ -f "$par2tmpdir/$name" ]; then
extracted_file="$par2tmpdir/$name"
break
fi
done
fi
# Clean up zip file
rm -f "$par2tmpdir/par2cmdline-turbo.zip"
else
echo "Error: Unsupported file type: $file_type"
echo "Expected XZ compressed or ZIP archive."
rm -rf "$par2tmpdir"
exit 1
fi
# Check if extraction was successful
if [ -z "$extracted_file" ] || [ ! -f "$extracted_file" ]; then
echo "Error: Failed to extract par2cmdline-turbo."
rm -rf "$par2tmpdir"
exit 1
fi
# Create par2cmdline-turbo package
mkdir -p "$par2tmpdir/usr/local/bin"
mv "$extracted_file" "$par2tmpdir/usr/local/bin/par2"
chmod +x "$par2tmpdir/usr/local/bin/par2"
# Package par2cmdline-turbo
cd "$par2tmpdir" || exit 1
tar -cJf "$packages_dir/$PAR2_ARCHIVE.txz" .
cd "$packages_dir" || exit 1
md5sum "$PAR2_ARCHIVE.txz" > "$PAR2_ARCHIVE.md5"
echo "par2cmdline-turbo package created: packages/$PAR2_ARCHIVE.txz"
# Cleanup par2 temp directory
rm -rf "$par2tmpdir"
else
echo "Using existing par2cmdline-turbo package."
fi
# Now create the main plugin package
cd "$DIR/source" || exit 1
# Copy all files (now relative to source/)
cp --parents $(find . -type f ! -iname "makepkg" ! -iname ".*") "$tmpdir/"
# Create package
cd "$tmpdir" || exit 1
tar -cJf "$packages_dir/$archive.txz" .
# Create MD5 file
cd "$packages_dir" || exit 1
md5sum "$archive.txz" > "$archive.md5"
# Cleanup
rm -rf "$tmpdir"
# Update the PLG file with the par2cmdline-turbo version
PLG_FILE="$DIR/par2protect.plg"
if [ -f "$PLG_FILE" ]; then
# Get current version in PLG file
CURRENT_PLG_VERSION=$(grep -oP '<!ENTITY par2VER "v\d+\.\d+\.\d+">' "$PLG_FILE" | grep -oP 'v\d+\.\d+\.\d+')
if [ "$CURRENT_PLG_VERSION" != "$PAR2_VERSION" ]; then
# Create a backup of the original plg file
cp "$PLG_FILE" "$PLG_FILE.bak"
# Update the par2 version in the plg file
sed -i "s/<!ENTITY par2VER \"v[0-9]\+\.[0-9]\+\.[0-9]\+\">/<!ENTITY par2VER \"$PAR2_VERSION\">/g" "$PLG_FILE"
echo "PLG file updated with par2cmdline-turbo version: $PAR2_VERSION (was $CURRENT_PLG_VERSION)"
else
echo "PLG file already contains the correct par2cmdline-turbo version: $PAR2_VERSION"
fi
else
echo "Warning: PLG file not found at $PLG_FILE"
fi
echo "Package created: packages/$archive.txz"
echo "MD5 file created: packages/$archive.md5"
echo "par2cmdline-turbo package: packages/$PAR2_ARCHIVE.txz"
echo "par2cmdline-turbo MD5: packages/$PAR2_ARCHIVE.md5"