Advertisement
rockdrilla

aufs-genpatch.sh

May 13th, 2016
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.08 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. linux_base=$1
  4. out_dir=$2
  5.  
  6. if [ -z "$1" ]
  7. then linux_base="4.5"
  8. fi
  9.  
  10. if [ -z "$2" ]
  11. then out_dir=$(readlink -f $0 | xargs -r0 dirname)
  12. fi
  13.  
  14. ###
  15.  
  16. D=/dev/null
  17.  
  18. GH_user="sfjro"
  19. GH_repo="aufs4-standalone"
  20. GH_branch="aufs${linux_base}"
  21. GH_tarball="https://github.com/${GH_user}/${GH_repo}/archive/${GH_branch}.tar.gz"
  22. GH_tarball_topdir="${GH_repo}-${GH_branch}"
  23.  
  24. aufs_reldate_src="include/uapi/linux/aufs_type.h"
  25. aufs_reldate_re="^[[:space:]]*#define[[:space:]]+AUFS_VERSION[[:space:]]+\"(${linux_base}-([^\"]+))\"[[:space:]]*\$"
  26. aufs_reldate_raw=""
  27. aufs_reldate=""
  28.  
  29. aufs_tree="Documentation/ fs/ include/uapi/linux/aufs_type.h"
  30.  
  31. 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"
  32. 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"
  33.  
  34. ###
  35.  
  36. cleanup() {
  37. [ -n "${tmpdir_tarball}" ]  && [ -d "${tmpdir_tarball}" ]  && rm -rf "${tmpdir_tarball}"
  38. [ -n "${tmpdir_gitrepo}" ]  && [ -d "${tmpdir_gitrepo}" ]  && rm -rf "${tmpdir_gitrepo}"
  39.  
  40. [ -n "${tmpfile_tarball}" ] && [ -f "${tmpfile_tarball}" ] && rm  -f "${tmpfile_tarball}"
  41. }
  42. failfast() { cleanup; exit 1; }
  43.  
  44. ### fetch tarball from GitHub
  45.  
  46. tmpfile_tarball=$(mktemp)
  47. wget -q -O "${tmpfile_tarball}" "${GH_tarball}" <${D} >${D} 2>${D} || failfast
  48.  
  49. ### extract tarball
  50.  
  51. tmpdir_tarball=$(mktemp -d)
  52. tar -x -f "${tmpfile_tarball}" -C "${tmpdir_tarball}" <${D} >${D} 2>${D} || failfast
  53. rm -f "${tmpfile_tarball}"
  54.  
  55. ### extract AuFS version info from header file and assign it to variable
  56.  
  57. tarball_dir="${tmpdir_tarball}/${GH_tarball_topdir}"
  58.  
  59. eval $(sed -nre "/${aufs_reldate_re}/{s##aufs_reldate_raw=\1\naufs_reldate=\2#;p}" < "${tarball_dir}/${aufs_reldate_src}")
  60.  
  61. [ -z "${aufs_reldate_raw}" ] && failfast
  62.  
  63. ### generate patch which adds common files (according to README)
  64.  
  65. tmpdir_gitrepo=$(mktemp -d)
  66.  
  67. cd "${tmpdir_gitrepo}"
  68. git init <${D} >${D} 2>${D}
  69. git commit --allow-empty -m "0" <${D} >${D} 2>${D}
  70.  
  71. cd "${tarball_dir}"
  72. tar -cf - ${aufs_tree} | tar -xf - -C "${tmpdir_gitrepo}"
  73.  
  74. cd "${tmpdir_gitrepo}"
  75. git add . <${D} >${D} 2>${D}
  76.  
  77. common_patch="${tarball_dir}/aufs4-common.patch"
  78. : > "${common_patch}"
  79. echo "${GH_branch} common files patch" >> "${common_patch}"
  80. echo >> "${common_patch}"
  81. git diff HEAD <${D} 2>${D} >> "${common_patch}"
  82.  
  83. cd "${tarball_dir}"
  84. rm -rf "${tmpdir_gitrepo}"
  85.  
  86. ### move all files from tarball dir to destination dir
  87.  
  88. k=$(echo "${rename_old}" | xargs -n1 | wc -l)
  89.  
  90. rename_old=$(echo "${rename_old}" | sed -re "s#^ *([^ ].*[^ ]) *\$#\1#g" | tr -s " " "|")
  91. rename_new=$(echo "${rename_new}" | sed -re "s#^ *([^ ].*[^ ]) *\$#\1#g" | tr -s " " "|")
  92.  
  93. i=0
  94. while [ ${i} -lt ${k} ]; do
  95.     i=$((i+1))
  96.  
  97.     old_name=$(echo "${rename_old}" | cut -d"|" -f${i})
  98.     new_name=$(echo "${rename_new}" | cut -d"|" -f${i})
  99.     new_name="${out_dir}/${linux_base}-${aufs_reldate}-${new_name}"
  100.  
  101.     mv "${old_name}" "${new_name}"
  102. done
  103.  
  104. cd "${out_dir}"
  105.  
  106. cleanup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement