Newer
Older
Digital_Repository / OARiNZ / DIY / LiveCD / Makefile
nstanger on 5 Jul 2007 7 KB - Fixed sed command lines.
  1. #!/usr/bin/make -f
  2.  
  3.  
  4. SHELL=/bin/sh
  5.  
  6.  
  7. # Version and filename info.
  8. VERSION=3.0
  9. INSTANT_EPRINTS=Instant_EPrints_$(VERSION)_i386
  10. UBUNTU=Ubuntu_6.10_i386
  11.  
  12. # Directories.
  13. LIVECD=livecd
  14. OLD_SQUASH=old-squashfs
  15. NEW_SQUASH=new-squashfs
  16.  
  17. # Miscellaneous files.
  18. REMOVE_FILES=$(NEW_SQUASH)/etc/resolv.conf $(NEW_SQUASH)/etc/apt/apt.conf \
  19. $(NEW_SQUASH)/Makefile.chroot $(NEW_SQUASH)/usr/sbin/policy-rc.d
  20.  
  21. # Commands locations.
  22. ECHO=/bin/echo
  23. SUDO=/usr/bin/sudo
  24. RM=/bin/rm
  25. CP=/bin/cp
  26. MOUNT=/bin/mount
  27. UMOUNT=/bin/umount
  28. MKDIR=/bin/mkdir
  29. SED=/bin/sed
  30. DD=/bin/dd
  31. CHMOD=/bin/chmod
  32.  
  33.  
  34. .PHONY: filesystem squashfs iso cleanup
  35.  
  36.  
  37. # Build ISO image.
  38.  
  39. iso: $(INSTANT_EPRINTS).iso
  40.  
  41. $(INSTANT_EPRINTS).iso: $(LIVECD)/casper/filesystem.squashfs
  42. @$(ECHO)
  43. @$(ECHO) "=== BUILDING ISO IMAGE ==="
  44.  
  45. @# Update live CD MD5 hash. We do a /bin/sh -c to run the find command
  46. @# so that we can use output redirection. Otherwise we'll get permission
  47. @# errors.
  48. @$(ECHO)
  49. @$(ECHO) "=== Updating live CD MD5 hash (takes about 1.5 minutes)."
  50. $(SUDO) $(RM) -f $(LIVECD)/md5sum.txt
  51. @$(ECHO) "find . -type f -print0 | xargs -0 md5sum > md5sum.txt"
  52. @cd $(LIVECD) && $(SUDO) /bin/sh -c \
  53. '/usr/bin/find . -type f -print0 | xargs -0 md5sum > md5sum.txt'
  54.  
  55. @# Create live CD ISO.
  56. @$(ECHO)
  57. @$(ECHO) "=== Building final ISO image (takes about 40 seconds)."
  58. $(SUDO) /usr/bin/mkisofs \
  59. -o $@ \
  60. -b isolinux/isolinux.bin \
  61. -c isolinux/boot.cat \
  62. -no-emul-boot \
  63. -boot-load-size 4 \
  64. -boot-info-table \
  65. -r \
  66. -V "Instant EPrints 3.0 i386" \
  67. -cache-inodes \
  68. -J \
  69. -input-charset iso8859-1 \
  70. -allow-leading-dots \
  71. $(LIVECD)
  72.  
  73. @$(ECHO)
  74. @$(ECHO) "=== Done!"
  75.  
  76.  
  77. # Build the new squashfs for the ISO.
  78.  
  79. squashfs: $(LIVECD)/casper/filesystem.squashfs
  80.  
  81. $(LIVECD)/casper/filesystem.squashfs: $(INSTANT_EPRINTS)_work.ext2
  82. @$(ECHO)
  83. @$(ECHO) "=== BUILDING NEW SQUASHFS ==="
  84.  
  85. @# Mount squashfs source filesystem and set up work environment.
  86. @$(ECHO)
  87. @$(ECHO) "=== Initialising."
  88. @$(SUDO) $(MOUNT) -o loop $< $(NEW_SQUASH)
  89. $(SUDO) $(MOUNT) -t proc --bind /proc $(NEW_SQUASH)/proc
  90. $(SUDO) $(CP) -p /etc/resolv.conf $(NEW_SQUASH)/etc
  91. @# Reconfigure the panel icons by means of pre-built gconf defaults.
  92. @# I did it this way because I couldn't figure out how to do it on
  93. @# the fly with gconftool (if that's even possible).
  94. $(SUDO) $(CP) -p gconf-tree.xml \
  95. $(NEW_SQUASH)/etc/gconf/gconf.xml.defaults/%gconf-tree.xml
  96.  
  97. @# Copy in cached .deb files to save on downloads and set up apt
  98. @# sources, etc. An appropriate sources.list can be generated
  99. @# using the utility at http://www.ubuntu-nl.org/source-o-matic/.
  100. @$(ECHO)
  101. @$(ECHO) "=== Setting up apt (takes about 10 seconds)."
  102. $(SUDO) $(CP) -a apt-cache/. $(NEW_SQUASH)/var/cache/apt/archives
  103. @# HACK: I've been having problems with the update servers. Since it
  104. @# takes so long to get back to this point in the process, I've
  105. @# cheated and pre-generated the various index files. Just drop 'em
  106. @# in! They should be safe to leave there afterwards.
  107. $(SUDO) $(CP) -a apt-lists/. $(NEW_SQUASH)/var/lib/apt/lists
  108. $(SUDO) $(CP) -p /etc/apt/apt.conf $(NEW_SQUASH)/etc/apt
  109. $(SUDO) $(CP) sources.list $(NEW_SQUASH)/etc/apt
  110. @# The following stops the daemons from attempting to restart, which
  111. @# will fail miserably in a chroot environment. Make sure to set the
  112. @# permissions correctly, just in case they've been eaten by CVS or
  113. @# something.
  114. $(SUDO) $(CP) policy-rc.d $(NEW_SQUASH)/usr/sbin
  115. $(SUDO) $(CHMOD) 755 $(NEW_SQUASH)/usr/sbin/policy-rc.d
  116. @# Finally, preseed the debconf database so that we don't get asked
  117. @# any annoying configuration questions during installs.
  118. $(SUDO) $(CP) -a debconf-db/. $(NEW_SQUASH)/var/cache/debconf
  119.  
  120. @# Chroot to the squashfs source filesystem and reconfigure
  121. @# installed packages. Note that we need to stop Webmin for the
  122. @# duration, otherwise installing Webmin in the chroot fails ("port
  123. @# 10000 is already in use").
  124. @$(ECHO)
  125. @$(ECHO) "=== Reconfiguring installed packages (takes about 2.5 minutes)."
  126. @-$(SUDO) /etc/init.d/webmin stop
  127. @$(SUDO) $(CP) Makefile.chroot $(NEW_SQUASH)
  128. @$(SUDO) chroot $(NEW_SQUASH) /usr/bin/env HOME=/root LC_ALL=C \
  129. DEBIAN_FRONTEND=noninteractive make -f Makefile.chroot
  130. @-$(SUDO) /etc/init.d/webmin start
  131.  
  132. @# Clean up.
  133. @$(ECHO)
  134. @$(ECHO) "=== Cleaning up."
  135. $(SUDO) $(UMOUNT) $(NEW_SQUASH)/proc
  136. $(SUDO) $(RM) -f $(REMOVE_FILES)
  137. $(SUDO) $(RM) -rf $(NEW_SQUASH)/tmp/*
  138.  
  139. @# Update manifest and disk name.
  140. @$(ECHO)
  141. @$(ECHO) "=== Updating manifest and disk name."
  142. $(SED) -i -e 's/DISKNAME .*/DISKNAME Instant EPrints 3.0 - i386/' \
  143. $(LIVECD)/README.diskdefines
  144. $(SUDO) chroot $(NEW_SQUASH) \
  145. dpkg-query -W --showformat='$(Package) $(Version)\n' \
  146. > $(LIVECD)/casper/filesystem.manifest
  147. $(SUDO) $(CP) $(LIVECD)/casper/filesystem.manifest \
  148. $(LIVECD)/casper/filesystem.manifest-desktop
  149. $(SED) -i -e '/ubiquity/d' $(LIVECD)/casper/filesystem.manifest-desktop
  150.  
  151. @# Clear free space on the squashfs source filesystem.
  152. @$(ECHO)
  153. @$(ECHO) "=== Clearing free space on new squashfs."
  154. -$(SUDO) $(DD) if=/dev/zero of=$(NEW_SQUASH)/dummyfile
  155. $(SUDO) $(RM) $(NEW_SQUASH)/dummyfile
  156.  
  157. @# Regenerate the live CD squashfs.
  158. @$(ECHO)
  159. @$(ECHO) "=== Building new squashfs (takes about 10 minutes)."
  160. $(SUDO) $(RM) -f $@
  161. $(SUDO) mksquashfs $(NEW_SQUASH) $@
  162.  
  163. @# Unmount the squashfs source filesystem.
  164. @$(SUDO) $(UMOUNT) $(NEW_SQUASH)
  165.  
  166. @$(ECHO)
  167. @$(ECHO) "=== Done!"
  168.  
  169. $(INSTANT_EPRINTS)_work.ext2: $(INSTANT_EPRINTS).ext2
  170. @$(ECHO)
  171. @$(ECHO) "=== Making working copy of original filesystem (takes about 2.5 minutes)."
  172. $(SUDO) $(CP) $< $@
  173.  
  174.  
  175. # Build source filesystem.
  176.  
  177. filesystem: $(INSTANT_EPRINTS).ext2
  178.  
  179. $(INSTANT_EPRINTS).ext2: $(UBUNTU).iso
  180. @$(ECHO)
  181. @$(ECHO) "=== BUILDING SOURCE FILESYSTEM ==="
  182.  
  183. @# Make a copy of the original ISO.
  184. @$(ECHO)
  185. @$(ECHO) "=== Copying original ISO (takes about 30 seconds)."
  186. @$(SUDO) $(MOUNT) -t iso9660 -o loop $< /cdrom
  187. @$(MKDIR) -p $(LIVECD)
  188. $(SUDO) $(RM) -rf $(LIVECD)/*
  189. $(CP) -a /cdrom/. $(LIVECD)
  190. $(CHMOD) -R u+w $(LIVECD)
  191. @$(SUDO) $(UMOUNT) /cdrom
  192.  
  193. @# Remove unnecessary Windows cruft.
  194. @$(ECHO)
  195. @$(ECHO) "=== Removing "`/usr/bin/du -smh $(LIVECD)/programs | /usr/bin/cut -d'M' -f1`"MiB of unnecessary Windows crud."
  196. $(RM) -rf $(LIVECD)/programs
  197.  
  198. @# Mount original compressed filesystem.
  199. @$(MKDIR) -p $(OLD_SQUASH)
  200. @$(SUDO) $(MOUNT) -t squashfs -o loop,ro \
  201. $(LIVECD)/casper/filesystem.squashfs $(OLD_SQUASH)
  202.  
  203. @# Create image for new compressed filesystem. Add on an extra 500MiB
  204. @# to allow for the temporary files that we're going to copy in (mostly
  205. @# cached .deb files.
  206. @$(ECHO)
  207. @$(ECHO) "=== Creating new 2.5 GiB blank file system (takes about 1.5 minutes)."
  208. $(SUDO) $(DD) if=/dev/zero \
  209. of=$@ bs=1M count=2500
  210. $(SUDO) mke2fs -F -q $@
  211.  
  212. @# Mount new compressed filesystem.
  213. @$(MKDIR) -p $(NEW_SQUASH)
  214. @$(SUDO) $(MOUNT) -o loop $@ $(NEW_SQUASH)
  215.  
  216. @# Copy the old compressed filesystem.
  217. @$(ECHO)
  218. @$(ECHO) "=== Copying original compressed filesystem (takes about 2.5 minutes)."
  219. $(SUDO) $(CP) -a $(OLD_SQUASH)/. $(NEW_SQUASH)
  220.  
  221. @# Unmount all compressed filesystems.
  222. @$(SUDO) $(UMOUNT) $(OLD_SQUASH)
  223. @$(SUDO) $(UMOUNT) $(NEW_SQUASH)
  224. @$(ECHO)
  225. @$(ECHO) "=== Done!"
  226.  
  227.  
  228. # Unmount everything that might be mounted. Useful if the make dies partway
  229. # through.
  230.  
  231. cleanup:
  232. @$(ECHO)
  233. @$(ECHO) "=== Cleaning up mounted items."
  234. -$(SUDO) $(UMOUNT) $(NEW_SQUASH)/proc
  235. -$(SUDO) $(UMOUNT) $(NEW_SQUASH)
  236. -$(SUDO) $(UMOUNT) $(OLD_SQUASH)
  237. -$(SUDO) $(UMOUNT) /cdrom