summaryrefslogtreecommitdiff
path: root/gen_kernel_patch
blob: 36c39ecdfc82cc20fba0e3c6d5114335d9b0164e (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
50
51
52
53
54
55
56
57
58
#!/bin/bash

cat_patch() {
  file=${startdir}/src/$(basename ${1})
  ftype=$(file -bizL "${file}")
  case "$ftype" in
    *application/x-gzip*)
      zcat ${file} ;;
    *application/x-bzip*)
      bzcat ${file} ;;
    *)
      cat ${file} ;;
  esac
}

get_file() {
  file=$(basename ${1})
  OPWD=${PWD}
  if [ "${file}" != "${1}" ]; then
    cd ${SRCDEST}
    [ ! -f ${file} ] && wget -c ${1}
    cd ${startdir}/src
    ln -s ${SRCDEST}/${file} .
  else
    cd ${startdir}/src
    ln -s ../patches/${file} .
  fi
  cd ${OPWD}
}

source /etc/makepkg.conf
source PATCHCFG

export SRCNAME

export startdir=${PWD}
mkdir ${startdir}/src
cd ${startdir}/src

get_file ${SRC}
bsdtar -xf $(basename ${SRC})
cp -a ${SRCORIG} ${SRCNAME}
cd ${SRCNAME}

pre_apply

for p in ${PATCHES[@]}; do
  patchname=$(echo ${p} | cut -d% -f1)
  patchstrip=$(echo ${p} | cut -d% -f2)
  get_file ${patchname}
  cat_patch ${patchname} | patch -Np${patchstrip} || exit 1
done

post_apply

cd ${startdir}/src
diff -Nur ${SRCORIG} ${SRCNAME} > $startdir/${PATCHNAME}
bzip2 --best $startdir/${PATCHNAME}