Quarks Gentoo Overlay
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.4KB

  1. #!/bin/sh
  2. #set -x
  3. # Default portage location
  4. PORTAGE="/usr/portage"
  5. # By default store SquashFS backing file under /mnt/portage
  6. SQFS_PORTAGE="/mnt/portage/portage.sqfs"
  7. # Store temporary overlayFS within portage tmpdir
  8. OVERLAY="$(portageq envvar PORTAGE_TMPDIR)/portage.overlayfs"
  9. OVERLAY_NAME=portage_overlay
  10. usage () {
  11. cat << EOF
  12. Usage: $0 [-p portage_tree] [-s squashfs_file]
  13. EOF
  14. exit 0
  15. }
  16. # mount squashed portage incl. writeable overlay
  17. mount_overlay () {
  18. # Make sure backing tree is mounted, try to mount otherwise
  19. mountpoint -q ${PORTAGE} || mount ${PORTAGE} && echo "Mounted ${PORTAGE}."
  20. # mount the overlay on top of existing live portage tree
  21. mkdir -p ${OVERLAY} ${OVERLAY}.work
  22. mount | grep -q ${OVERLAY_NAME} || mount -t overlay ${OVERLAY_NAME} \
  23. -olowerdir=${PORTAGE},upperdir=${OVERLAY},workdir=${OVERLAY}.work \
  24. ${PORTAGE} && echo "Mounted Overlay file system."
  25. }
  26. # umount overlay and clean up temp dirs
  27. umount_overlay () {
  28. mount | grep -q ${OVERLAY_NAME}
  29. if [ $? -eq 0 ]; then
  30. umount ${OVERLAY_NAME} && rm -rf ${OVERLAY} ${OVERLAY}.work
  31. echo "Overlay file system unmounted."
  32. fi
  33. }
  34. # umount current, replace and mount new
  35. replace_squashfs () {
  36. [ -f ${SQFS_PORTAGE}.new ] || \
  37. { echo "No new portage tree version found!"; exit 1; }
  38. mountpoint -q ${PORTAGE}
  39. if [ $? -eq 0 ]; then
  40. umount ${PORTAGE} && echo "Unmounted ${PORTAGE}."
  41. if [ $? -ne 0 ]; then
  42. echo "Could not unmount ${PORTAGE} !"
  43. echo "New portage snapshot is at ${SQFS_PORTAGE}.new"
  44. exit 1
  45. fi
  46. fi
  47. if [ -f ${SQFS_PORTAGE} ]; then
  48. mv ${SQFS_PORTAGE} ${SQFS_PORTAGE}.previous
  49. else
  50. echo "No current squashFS backing file ${SQFS_PORTAGE} found,\
  51. assuming initial setup."
  52. fi
  53. mv ${SQFS_PORTAGE}.new ${SQFS_PORTAGE} && \
  54. mount ${PORTAGE} && echo "Mounted new snapshot at ${PORTAGE}."
  55. }
  56. # Create new squashfs image
  57. create_squashfs () {
  58. echo 'Creating new SquashFS snapshot ...'
  59. mksquashfs ${PORTAGE} ${SQFS_PORTAGE}.new -comp xz -noappend \
  60. -no-progress 1>/dev/null && echo "SquashFS snapshot created at ${SQFS_PORTAGE}.new"
  61. }
  62. # Any custom changes to the portage tree
  63. customize () {
  64. echo "Applying local customizations ..."
  65. # Linphone
  66. perl -i -p -e 's/^(net-voip\/linphone|net-libs\/libeXosip|net-libs\/libosip)/# disabled by update_portage.sh - $1/;' ${PORTAGE}/profiles/package.mask
  67. }
  68. cleanup () {
  69. # In case still mounted
  70. umount_overlay
  71. # Remove potential left overs from mksquashfs
  72. rm -f ${SQFS_PORTAGE}.new
  73. # Make sure we have a working portage tree mounted
  74. mountpoint -q ${PORTAGE} || mount ${PORTAGE}
  75. exit 1
  76. }
  77. while getopts "p:s:" OPTIONS; do
  78. case $OPTIONS in
  79. p) PORTAGE=$OPTARG;;
  80. s) SQFS_PORTAGE=$OPTARG;;
  81. ?) usage;;
  82. esac
  83. done
  84. [ -d ${PORTAGE} ] || { echo "${PORTAGE} is not a directory!"; usage; }
  85. # make sure we clean up and have a working portage tree if interupted
  86. trap "cleanup" INT TERM
  87. mount_overlay
  88. # End early if there are no upstream changes
  89. # assume if rsync is run only once that no upstream changes available
  90. echo 'Syncing gentoo portage tree ...'
  91. RUNS=$(emaint sync -r gentoo 2>/dev/null | grep -c 'Number of files')
  92. [ $RUNS -eq 1 ] && { echo 'No upstream changes. Exiting.'; cleanup; }
  93. # Optional step to customize the tree, mostly to alter upstream use masks
  94. customize
  95. create_squashfs
  96. umount_overlay
  97. replace_squashfs