summarylogtreecommitdiffstats
path: root/export-loong64-patches
blob: 0fcf5815b7aa26ba3b55bab2dd00f016b474b0ff (plain)
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
#!/bin/bash

if [[ "$1" == "--help" || "$1" == "-h" ]]; then
  echo "Usage: export-loong64-patches [package-path] [destination-directory]"
  exit 0
fi

if [[ $# -gt 2 ]]; then
  echo "Error: Too many arguments."
  exit 1
fi

PATCH_DIR="loong64-patches"
if [[ $# -eq 2 ]]; then
  cd "$1" || exit
  PATCH_DIR="$2"
elif [[ $# -eq 1 ]]; then
  PATCH_DIR="$1"
fi

mkdir -p "$PATCH_DIR"

original_pkgrel=$(grep '^pkgrel=' "PKGBUILD")
if [[ $original_pkgrel =~ pkgrel=([0-9]+)\.([0-9]+) ]]; then
    echo "Ignore to export change of pkgrel to patch."
    num1=${BASH_REMATCH[1]}
    sed -i "s/pkgrel=[0-9]\+\.[0-9]\+/pkgrel=$num1/" "PKGBUILD"
fi

echo "Exporting: loong.patch..."
git diff > "$PATCH_DIR/loong.patch"

sed -i "s/pkgrel=[0-9]\+/$original_pkgrel/" "PKGBUILD"

sources=$(. PKGBUILD && echo "${source[@]}")

untracked_files=$(git ls-files --others --exclude-standard)

for file in $sources; do
  if [ -f "$file" ]; then
    for untracked_file in $untracked_files; do
      if [ "$file" == "$untracked_file" ]; then
        echo "Copying: $file..."
        cp "$file" "$PATCH_DIR"
        break
      fi
    done
  fi
done