summaryrefslogtreecommitdiff
path: root/update-kernel-config
blob: 5012979fbd10d70ad1937101b110ca094cb9917b (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
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
#!/bin/bash

if [ $# -ne 2 ]; then
  >&2 echo 'usage: update-kernel-config [repository] [kernel-name]'
  exit 2
fi

git_repo_path='/usr/src/archlinux32/packages/'
upstream_git_path='/usr/src/archlinux/packages'
vagrant_path=$(
  readlink -f ~/"virtual-boxes/archlinux32-test"
)

old_revision=$(
  sed -n '
    s/^# upstream git\( revision\)\?: *//
    T
    p
  ' "${git_repo_path}/$1/$2/PKGBUILD"
)

if [ -z "${old_revision}" ]; then
  >&2 echo 'Cannot determine old upstream git revision.'
  >&2 echo '"# upstream git revision: ..." line is missing.'
  exit 1
fi

config_names=$(
  git -C "${git_repo_path}/$1/$2" archive HEAD -- | \
    tar -t | \
    grep '^config\($\|\.\)'
)

diff=$(
  git -C "${upstream_git_path}/$2/repos/$1-x86_64" diff "${old_revision}" HEAD -- config | \
    grep '^[+-].' | \
    grep -v '^+++\|^---'
)

if [ -z "${diff}" ]; then
  >&2 echo 'nothing changed.'
  exit 1
fi

for config_name in ${config_names}; do
  {
    grep -vxF "$(
      printf '%s\n' "${diff}" | \
        sed -n '
          s/^-//
          T
          p
        '
    )" "${git_repo_path}/$1/$2/${config_name}"
    printf '%s\n' "${diff}" | \
      sed -n '
        s/^+//
        T
        p
      '
  } | \
    sponge "${git_repo_path}/$1/$2/${config_name}"
done

sed -i '
  1 s/^#.*$/# upstream git revision: '"$(
    git -C "${upstream_git_path}" rev-parse HEAD
  )"'/
  s/'"$(
    git -C "${upstream_git_path}/$2/repos/$1-x86_64" archive "${old_revision}" -- config | \
      tar -Ox | \
      sha256sum | \
      awk '{print $1}'
  )"'/'"$(
    git -C "${upstream_git_path}/$2/repos/$1-x86_64" archive HEAD -- config | \
      tar -Ox | \
      sha256sum | \
      awk '{print $1}'
  )"'/g
  ' "${git_repo_path}/$1/$2/PKGBUILD"

if ssh -o ConnectTimeout=1 arch32-test true; then
  vm_is_running=true
else
  vm_is_running=false
fi

if ! ${vm_is_running}; then
  cd "${vagrant_path}"
  vagrant up
fi

{
  git -C "${upstream_git_path}/$2/repos/$1-x86_64" archive HEAD --
  for config_name in ${config_names}; do
    tar -c -C "${git_repo_path}/$1/$2" "${config_name}"
  done
} | \
  ssh arch32-test '
    rm -rf --one-file-system "'"$2"'"
    mkdir "'"$2"'"
    tar -xiC "'"$2"'"
  '
ssh arch32-test '
  cd "'"$2"'"
  cat >> PKGBUILD
  sed -i '"'"'
    '"$(
      for config_name in ${config_names}; do
        printf 's/'
        git -C "${git_repo_path}/$1/$2" archive HEAD -- "${config_name}" | \
          tar -Ox | \
          sha256sum | \
          awk '{print $1}' | \
          tr -d '\n'
        printf '/SKIP/g\n'
      done
    )"'
    /^arch=[^#]*any/!{
      /^arch=(/s/(/(i486 i686 pentium3 /
    }
    /make oldconfig/ s/^\s*#//
    s/^}$/return 1\n\0/
  '"'"' PKGBUILD
' < \
  "${git_repo_path}/$1/$2/PKGBUILD"
ssh arch32-test '
  cd "'"$2"'"
  eval "$(grep '"'"'^_srcname='"'"' PKGBUILD)"
  for config_name in '"${config_names}"'; do
    rm -rf --one-file-system src pkg
    if [ "${config_name}" = "config" ]; then
      makepkg -fcrs --asdeps --noconfirm
    else
      CARCH=${config_name#config.} makepkg -fcrs --asdeps --noconfirm
    fi
    mv src/${_srcname}/.config ${config_name}
  done
'
for config_name in ${config_names}; do
  scp "arch32-test:$2/${config_name}" "${git_repo_path}/$1/$2/"
done
ssh arch32-test '
  rm -rf --one-file-system "'"$2"'"
'
sed -i "$(
  for config_name in ${config_names}; do
    printf 's/'
    git -C "${git_repo_path}/$1/$2" archive HEAD -- "${config_name}" | \
      tar -Ox | \
      sha256sum | \
      awk '{print $1}' | \
      tr -d '\n'
    printf '/'
    sha256sum "${git_repo_path}/$1/$2/${config_name}" | \
      awk '{print $1}' | \
      tr -d '\n'
    printf '/g\n'
  done
)" "${git_repo_path}/$1/$2/PKGBUILD"
git -C "${git_repo_path}/$1/$2" commit PKGBUILD ${config_names} -m "$1/$2: new version => new config => new checksum"
if ! ${vm_is_running}; then
  ssh arch32-test 'sudo poweroff'
  err=$?
  if [ ${err} -eq 255 ]; then
    err=0
  fi
  exit ${err}
fi