| 1 | #! /bin/bash |
| 2 | # The functions used to mount and unmount the filesystems for lvmbuilder |
| 3 | # lvmbuilder -- Debian package builder using LVM |
| 4 | # Copyright (C) 2007 Kapil Hari Paranjape |
| 5 | # based on: |
| 6 | # pbuilder -- personal Debian package builder |
| 7 | # Copyright (C) 2001-2006 Junichi Uekawa |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; either version 2 of the License, or |
| 12 | # (at your option) any later version. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this program; if not, write to the Free Software |
| 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | |
| 23 | # lvmbuilder by Kapil Hari Paranjape <[email protected]> 2007 Aug 15 |
| 24 | # pbuilder by Junichi Uekawa <[email protected]> 2001 Aug 25 |
| 25 | |
| 26 | set -e |
| 27 | |
| 28 | function clean_basedev(){ |
| 29 | echo -n "This will wipe out $BASEDEV. Proceed?[y/N]" |
| 30 | read ans |
| 31 | if [ "$ans" != "y" -a "$ans" != "Y" ] |
| 32 | then |
| 33 | exit 0 |
| 34 | fi |
| 35 | echo "Making new file system at $BASEDEV." |
| 36 | mke2fs $BASEDEV |
| 37 | } |
| 38 | |
| 39 | function unmount_basedev(){ |
| 40 | umount $BASEDEV |
| 41 | e2fsck -f -v $BASEDEV |
| 42 | } |
| 43 | |
| 44 | function setup_workplace(){ |
| 45 | # Size computations |
| 46 | BASESIZE=$(blockdev --getsize $BASEDEV) |
| 47 | COWSIZE=$(blockdev --getsize $COWDEV) |
| 48 | TOTAL=$[ $COWSIZE + $BASESIZE ] |
| 49 | |
| 50 | # Load the necessary modules |
| 51 | modprobe dm_zero dm_mirror dm_snapshot dm_mod |
| 52 | |
| 53 | ## Create the total base device |
| 54 | # It consists of the base device extended by zeroes. |
| 55 | # The length of the zeroes is the size of the cow. |
| 56 | ( echo 0 $BASESIZE linear $BASEDEV 0 ; \ |
| 57 | echo $BASESIZE $COWSIZE zero ) | \ |
| 58 | dmsetup create $TOTALNAME |
| 59 | |
| 60 | ## Create the work device |
| 61 | # It is the snapshot device with the all writes |
| 62 | # going to the cow device. The file-system is resized |
| 63 | # to the maximum extent possible. |
| 64 | echo 0 $TOTAL snapshot $TOTALDEV $COWDEV n 16 | \ |
| 65 | dmsetup create $WORKNAME |
| 66 | |
| 67 | [ -b $WORKDEV ] && resize2fs $WORKDEV |
| 68 | mount $WORKDEV $BUILDPLACE |
| 69 | } |
| 70 | |
| 71 | function takedown_workplace(){ |
| 72 | umount /dev/mapper/lvmbuilder-work |
| 73 | dmsetup remove lvmbuilder-work |
| 74 | dmsetup remove lvmbuilder-total |
| 75 | } |
| 76 | |
| 77 | function showhelp(){ |
| 78 | cat <<EOF |
| 79 | lvmbuilder - Debian package builder using pbuilder and lvm |
| 80 | Copyright 2007 Kapil Hari Paranjape |
| 81 | Based on: |
| 82 | pbuilder - a personal builder |
| 83 | Copyright 2001-2006 Junichi Uekawa |
| 84 | Distributed under GNU Public License version 2 or later |
| 85 | |
| 86 | lvmbuilder [operation] [lvmbuilder-options] |
| 87 | |
| 88 | command lines: |
| 89 | lvmbuilder create [--basedev base-device-path] [--distribution sarge|etch|sid|experimental] |
| 90 | Creates a base distribution on an ext2 filesystem on the base block device |
| 91 | |
| 92 | lvmbuilder update [--basedev base-device-path] [--distribution sarge|etch|sid|experimental] |
| 93 | Updates a base distribution on an ext2 filesystem on the base block device |
| 94 | |
| 95 | lvmbuilder build [--basedev base-device-path] [--cowdev cow-device-path] pkgsrc.dsc |
| 96 | Builds using the base distribution with all writes going to cow block device. |
| 97 | Requires a .dsc filename |
| 98 | |
| 99 | lvmbuilder clean [--basedev base-device-path] |
| 100 | Creates a fresh ext2fs file system on the base block device. |
| 101 | |
| 102 | lvmbuilder login |
| 103 | lvmbuilder execute -- [command] [command-options] |
| 104 | Logs in to the build environment and execute command. |
| 105 | |
| 106 | lvmbuilder dumpconfig |
| 107 | Dumps configuration information to stdout for debugging. |
| 108 | |
| 109 | lvmbuilder-options: |
| 110 | --basedev [base device location] |
| 111 | --cowdev [cow device location] |
| 112 | --buildplace [location of build] |
| 113 | --mirror [mirror location] |
| 114 | --othermirror [other mirror location in apt deb-line format, delimited with | signs] |
| 115 | --http-proxy [proxy] |
| 116 | --distribution [distribution(sarge|sid|etch|experimental)] |
| 117 | --buildresult [location-to-copy-build-result] |
| 118 | --aptcache [location of retrieved package files] |
| 119 | --removepackages [packages-to-remove on pbuilder create] |
| 120 | --extrapackages [packages-to-add on pbuilder create] |
| 121 | --configfile [configuration file to load] |
| 122 | --debemail [mail address] |
| 123 | --debbuildopts [dpkg-buildpackage options] |
| 124 | --logfile [filename to output log] |
| 125 | --pkgname-logfile |
| 126 | --aptconfdir [overriding apt config dir] |
| 127 | --timeout [timeout time] |
| 128 | --override-config |
| 129 | --binary-arch |
| 130 | --debug |
| 131 | --autocleanaptcache |
| 132 | --debootstrapopts [debootstrap options] |
| 133 | --debootstrap [debootstrap|cdebootstrap] |
| 134 | |
| 135 | EOF |
| 136 | exit 1 |
| 137 | } |
| 138 |