Skip to content

Instantly share code, notes, and snippets.

@boltronics
Created July 17, 2018 02:12
Show Gist options
  • Save boltronics/ff19256083ce5d370584c3c0826ef7e7 to your computer and use it in GitHub Desktop.
Save boltronics/ff19256083ce5d370584c3c0826ef7e7 to your computer and use it in GitHub Desktop.
Hacky script to build Salt packages for Debian with pbuilder and repo.saltstack.com packaging data
#!/bin/bash -e
# The tag name (or branch) of whatever you want to package.
declare -r tag="${1-v2017.7.5}"
declare -r pbuilder_target="${2-stretch}"
declare -r git_dir=./salt
# This makes no sense to me. Why are these different?
declare -r salt_upstream_version="${tag:1}"
declare -r pkg_upstream_version="${tag:1}+ds"
declare -r sitepoint_revision="sp1"
# Nothing below this point should normally require touching unless
# adding support for new distributions, compression formats or
# repository structure.
declare -r changelog_root='http://metadata.ftp-master.debian.org/changelogs/main/s/salt'
declare -r salt_repo='http://repo.saltstack.com/apt'
declare -r major_minor_ver="$(echo ${tag} | tr -d 'v' | cut -d '.' -f 1-2)"
declare -i download_changelog=1
declare distro
declare pbuilder_target_num
case "${pbuilder_target}" in
"jessie" )
distro=debian
pbuilder_target_num=8
;;
"stretch" )
distro=debian
pbuilder_target_num=9
;;
"trusty" )
distro=ubuntu
pbuilder_target_num=14.04
;;
"xenial" )
distro=ubuntu
pbuilder_target_num=16.04
;;
esac
declare -r repo_base_url="${salt_repo}/${distro}/${pbuilder_target_num}/amd64/${major_minor_ver}"
if [ -d "${salt_upstream_version}" ]
then
echo "Error: Output directory '${salt_upstream_version}' already exists."
exit 1
fi
declare changelog_file
declare compression_type
declare compression_ext
if wget --spider \
"${repo_base_url}/salt_${pkg_upstream_version}-1.debian.tar.xz" \
2>/dev/null ||
[ -f "salt_${pkg_upstream_version}-1.debian.tar.xz" ]
then
compression_ext=.xz
tar_compression_arg=J
if [ -f "salt_${pkg_upstream_version}-1.debian.tar.xz" ]
then
download_changelog=0
mkdir -p ${salt_upstream_version}
cp -f "salt_${pkg_upstream_version}-1.debian.tar.xz" \
"${salt_upstream_version}/salt_${pkg_upstream_version}-1.debian.tar.xz"
fi
elif wget --spider \
"${repo_base_url}/salt_${pkg_upstream_version}-1.debian.tar.gz" \
2>/dev/null
then
compression_ext=.gz
tar_compression_arg=z
elif wget --spider \
"${repo_base_url}/salt_${pkg_upstream_version}-1.debian.tar" \
2>/dev/null
then
compression_ext=''
tar_compression_arg=''
else
echo "Failed to locate salt_${pkg_upstream_version}-1.debian.tar." 1>&2
exit 1
fi
if [ ! -d "${git_dir}" ]
then
git clone https://github.com/saltstack/salt.git "${git_dir}"
fi
cd ${git_dir}
git fetch
git checkout ${tag}
git clean -fdx
git reset --hard
# Generates a modified tarball. For details see:
# https://github.com/saltstack/salt/issues/36360
python setup.py sdist
mkdir -p ../${salt_upstream_version}
# Note the use of '-' instead of a '+'. This is unconventional but
# required due to a well-known bug in S3.
mv dist/salt-${salt_upstream_version}.tar.gz \
../${salt_upstream_version}/salt_${pkg_upstream_version}.orig.tar.gz
cd ../${salt_upstream_version}/
# Fetch, verify and extract the debian packaging files.
if [ ${download_changelog} -eq 1 ]
then
wget "${repo_base_url}/salt_${pkg_upstream_version}-1.debian.tar${compression_ext}"
wget "${repo_base_url}/salt_${pkg_upstream_version}-1.dsc"
# Checksum verification
gpg --verify salt_${pkg_upstream_version}-1.dsc
grep -A2 '^Checksums-Sha256:' salt_${pkg_upstream_version}-1.dsc |
grep '.debian.tar' |
sed 's/\s*\([^[:space:]]*\).*[[:space:]]\([^[:space:]]*\)$/\1 \2/' |
sha256sum -c -
fi
tar zxf salt_${pkg_upstream_version}.orig.tar.gz
cd salt-${salt_upstream_version}
tar ${tar_compression_arg}xf \
../salt_${pkg_upstream_version}-1.debian.tar${compression_ext}
# Fetch the changelog for the most recent Salt package in Debian
# (which is almost certainly not up to date). Unfortunately, the Salt
# repos do not provide a changelog file.
changelog_file="$(w3m -dump "${changelog_root}/" |
grep -E '^\[TXT\]\s+.*salt_.*(ds|dfsg1)-[0-9]+_changelog\s+.*' |
sort -V | tail -n 1 | sed 's/^\[TXT\]\s\+\([^\ ]*\).*/\1/')"
# Update the local changelog.
echo >> debian/changelog
wget -q -O - "${changelog_root}/${changelog_file}" \
>> debian/changelog
debchange -v ${pkg_upstream_version}-${sitepoint_revision} -D stable \
'New upstream release.'
# Use a clean pbuilder environment. I know these aren't the typical
# branch names, but there is no practical difference.
DIST=${pbuilder_target} pdebuild
echo "Look under /var/cache/pbuilder for build results."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment