1
0
linux/debian/bin/new-release

154 lines
3.5 KiB
Plaintext
Raw Normal View History

2024-10-29 05:12:06 +03:00
#!/bin/sh
set -ef
prj_dir=$(readlink -f "$(dirname "$0")/../..")
cd "${prj_dir}"
[ -s debian/changelog ]
dpkg-parsechangelog --show-field Source | grep -Eq '^linux'
ch_ver=$(dpkg-parsechangelog --show-field Version)
ch_dist=$(dpkg-parsechangelog --show-field Distribution)
do_idle() {
nice -n +40 chrt -i 0 ionice -c 3 "$@"
}
v=$1
if [ -z "$v" ] ; then
v=$(echo "${ch_ver}" | sed -E 's/^\d+://;s/-[^-]+$//')
fi
IFS=. read -r major minor __patch <<-EOF
$v
EOF
[ -n "${minor}" ]
ver_path="v${major}.${minor}"
[ "${minor}" = 0 ] || ver_path="v${major}.x"
tarball_new="linux_${v}.orig.tar"
tarball_new_comp="${tarball_new}.xz"
do_compress() { do_idle xz -1vv "$1" ; }
while ! [ -s "../${tarball_new_comp}" ] ; do
tarball_path_web="pub/linux/kernel/${ver_path}"
tarball_path_git="pub/scm/linux/kernel/git/stable/linux.git/snapshot"
tarball_orig="linux-${v}.tar.xz"
tarball_fallback="linux-${v}.tar.gz"
src_dir="linux-${v}"
d=$(mktemp -d)
cd "$d/"
tarball_ok=0
while [ ${tarball_ok} = 0 ] ; do
[ -s "${prj_dir}/../${tarball_orig}" ] || break
tar xf "${prj_dir}/../${tarball_orig}" || break
tarball_ok=1 ; break
done
if [ "${tarball_ok}" = 0 ] ; then
rm -rf "${src_dir}"
do_download() { do_idle aria2c -c -V -j 8 -x 4 -s 16 "$@" ; }
# aria_opts_pxy='--connect-timeout=5 --retry-wait=5 --timeout=30'
aria_opts_web='--connect-timeout=15 --retry-wait=15 --timeout=240'
set +e
while : ; do
do_download ${aria_opts_web} \
"https://cdn.kernel.org/${tarball_path_web}/${tarball_orig}" \
"https://kernel.org/${tarball_path_web}/${tarball_orig}" \
&& break
do_download ${aria_opts_web} \
"https://cdn.kernel.org/${tarball_path_web}/${tarball_fallback}" \
"https://kernel.org/${tarball_path_web}/${tarball_fallback}" \
"https://git.kernel.org/${tarball_path_git}/${tarball_fallback}" \
&& break
true ; break
done
set -e
while [ "${tarball_ok}" = 0 ] ; do
rm -rf "${src_dir}"
[ -s "${tarball_orig}" ] || break
tar xf "${tarball_orig}" || break
cp -nv "${tarball_orig}" "${prj_dir}/../${tarball_orig}"
tarball_ok=1 ; break
done
while [ "${tarball_ok}" = 0 ] ; do
rm -rf "${src_dir}"
[ -s "${tarball_fallback}" ] || break
tar xf "${tarball_fallback}" || break
tarball_ok=1 ; break
done
rm -f "${tarball_orig}" "${tarball_fallback}"
fi
[ "${tarball_ok}" = 1 ] || {
cd "/"
rm -rfv "$d"
exit 1
}
list_excluded() {
local file field
file="${prj_dir}/debian/copyright"
field='Files-Excluded'
[ -s "${file}" ]
sed -E -n \
-e "/^${field}:/,/^\S/{s/^${field}://;p;}" \
< "${file}" \
| sed -E \
-e '$!{/^.+$/H;d;};x;s/(\s|\n)+/ /g;s/^ //;'
}
files_exclude=$(list_excluded)
for i in ${files_exclude} ; do
case "$i" in
*\** | *\?* )
find "${src_dir}/" -path "${src_dir}/$i" -exec rm -rfv {} +
;;
* )
rm -rfv "${src_dir}/$i"
;;
esac
done
tar_opts='--blocking-factor=1 --numeric-owner --owner=0 --group=0 --no-xattrs --no-selinux --no-acls'
find "${src_dir}/" ! -type d -printf '%p\0' | sort -zuV \
| tar ${tar_opts} --null -T - -cf "${tarball_new}"
do_compress "${tarball_new}"
cp -v "${tarball_new_comp}" "${prj_dir}/../"
cd "${prj_dir}/"
rm -rf "$d/"
done
if [ -z "$2" ] ; then
pkg_ver="${v}-1"
if [ "${pkg_ver}" != "${ch_ver}" ] ; then
dch -D "${ch_dist}" -v "${pkg_ver}" \
'New upstream stable update:' \
"https://www.kernel.org/pub/linux/kernel/${ver_path}/ChangeLog-${v}"
fi
else
pkg_ver="${v}-$2"
shift 2
dch -D "${ch_dist}" -v "${pkg_ver}" "${@:-write reason here}"
fi