Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- linux_base=$1
- out_dir=$2
- if [ -z "$1" ]
- then linux_base="4.5"
- fi
- if [ -z "$2" ]
- then out_dir=$(readlink -f $0 | xargs -r0 dirname)
- fi
- ###
- D=/dev/null
- GH_user="sfjro"
- GH_repo="aufs4-standalone"
- GH_branch="aufs${linux_base}"
- GH_tarball="https://github.com/${GH_user}/${GH_repo}/archive/${GH_branch}.tar.gz"
- GH_tarball_topdir="${GH_repo}-${GH_branch}"
- aufs_reldate_src="include/uapi/linux/aufs_type.h"
- aufs_reldate_re="^[[:space:]]*#define[[:space:]]+AUFS_VERSION[[:space:]]+\"(${linux_base}-([^\"]+))\"[[:space:]]*\$"
- aufs_reldate_raw=""
- aufs_reldate=""
- aufs_tree="Documentation/ fs/ include/uapi/linux/aufs_type.h"
- rename_old="aufs4-common.patch aufs4-kbuild.patch aufs4-base.patch aufs4-mmap.patch aufs4-standalone.patch aufs4-loopback.patch vfs-ino.patch tmpfs-idr.patch"
- rename_new=" 0-common.patch 1-kbuild.patch 2-base.patch 3-mmap.patch 4-standalone.patch 5-loopback.patch 6-vfs-ino.patch 7-tmpfs-idr.patch"
- ###
- cleanup() {
- [ -n "${tmpdir_tarball}" ] && [ -d "${tmpdir_tarball}" ] && rm -rf "${tmpdir_tarball}"
- [ -n "${tmpdir_gitrepo}" ] && [ -d "${tmpdir_gitrepo}" ] && rm -rf "${tmpdir_gitrepo}"
- [ -n "${tmpfile_tarball}" ] && [ -f "${tmpfile_tarball}" ] && rm -f "${tmpfile_tarball}"
- }
- failfast() { cleanup; exit 1; }
- ### fetch tarball from GitHub
- tmpfile_tarball=$(mktemp)
- wget -q -O "${tmpfile_tarball}" "${GH_tarball}" <${D} >${D} 2>${D} || failfast
- ### extract tarball
- tmpdir_tarball=$(mktemp -d)
- tar -x -f "${tmpfile_tarball}" -C "${tmpdir_tarball}" <${D} >${D} 2>${D} || failfast
- rm -f "${tmpfile_tarball}"
- ### extract AuFS version info from header file and assign it to variable
- tarball_dir="${tmpdir_tarball}/${GH_tarball_topdir}"
- eval $(sed -nre "/${aufs_reldate_re}/{s##aufs_reldate_raw=\1\naufs_reldate=\2#;p}" < "${tarball_dir}/${aufs_reldate_src}")
- [ -z "${aufs_reldate_raw}" ] && failfast
- ### generate patch which adds common files (according to README)
- tmpdir_gitrepo=$(mktemp -d)
- cd "${tmpdir_gitrepo}"
- git init <${D} >${D} 2>${D}
- git commit --allow-empty -m "0" <${D} >${D} 2>${D}
- cd "${tarball_dir}"
- tar -cf - ${aufs_tree} | tar -xf - -C "${tmpdir_gitrepo}"
- cd "${tmpdir_gitrepo}"
- git add . <${D} >${D} 2>${D}
- common_patch="${tarball_dir}/aufs4-common.patch"
- : > "${common_patch}"
- echo "${GH_branch} common files patch" >> "${common_patch}"
- echo >> "${common_patch}"
- git diff HEAD <${D} 2>${D} >> "${common_patch}"
- cd "${tarball_dir}"
- rm -rf "${tmpdir_gitrepo}"
- ### move all files from tarball dir to destination dir
- k=$(echo "${rename_old}" | xargs -n1 | wc -l)
- rename_old=$(echo "${rename_old}" | sed -re "s#^ *([^ ].*[^ ]) *\$#\1#g" | tr -s " " "|")
- rename_new=$(echo "${rename_new}" | sed -re "s#^ *([^ ].*[^ ]) *\$#\1#g" | tr -s " " "|")
- i=0
- while [ ${i} -lt ${k} ]; do
- i=$((i+1))
- old_name=$(echo "${rename_old}" | cut -d"|" -f${i})
- new_name=$(echo "${rename_new}" | cut -d"|" -f${i})
- new_name="${out_dir}/${linux_base}-${aufs_reldate}-${new_name}"
- mv "${old_name}" "${new_name}"
- done
- cd "${out_dir}"
- cleanup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement