#!/bin/sh # # Copyright (c) 2007 Canonical LTD # # Author: Oliver Grawert # # 2007, Scott Balneaves # Warren Togami # 2008, Vagrant Cascadian # 2010, Gideon Romm # 2012, Alkis Georgopoulos # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, you can find it on the World Wide # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301, USA. # usage() { cat </dev/null && ionice=ionice || unset ionice if ! $nice $ionice mksquashfs "$cowroot" "$imgdir/$name.img.tmp" \ -no-recovery -noappend -wildcards ${EXCLUDE_FILE:+-ef "$EXCLUDE_FILE"} \ ${EXCLUDE:+-e "$EXCLUDE"} ${NO_COMPRESS:+-noF -noD -noI -no-exports} \ ${COMPRESSION:+-comp $COMPRESSION} then rm -f "$imgdir/$name.img.tmp" die "mksquashfs failed to build the LTSP image, exiting" fi if [ -f "$imgdir/$name.img" ] && [ "$NO_BACKUP" != true ]; then mv "$imgdir/$name.img" "$imgdir/$name.img.old" fi mv "$imgdir/$name.img.tmp" "$imgdir/$name.img" fi PREFER_NBD_IMAGE="$REVERT" ltsp-update-kernels ${BASE:+-b "$BASE"} "$name" if [ "$cowroot" != "$chroot" ] && [ "$REVERT" != true ]; then trap_cleanup fi } # Distro specific functions lock_package_management() { warn "Your distro doesn't support package management locking, continuing without locking..." } unlock_package_management() { if [ -n "$lockpid" ]; then kill "$lockpid" || true unset lockpid fi } # Set an optional MODULES_BASE, so help2man can be called from build env MODULES_BASE=${MODULES_BASE:-/usr/share/ltsp} # This also sources vendor functions and .conf file settings . ${MODULES_BASE}/ltsp-server-functions if ! args=$(getopt -n "$0" -o "b:ce:fhmnr" \ -l "base:,cleanup,exclude:,compression:,config-nbd,help,no-compress,no-backup,revert,version" -- "$@") then exit 1 fi eval "set -- $args" while true ; do case "$1" in -b|--base) shift; BASE=$1 ;; -c|--cleanup) CLEANUP=true ;; --compression) shift; COMPRESSION="$1" ;; -e|--exclude) shift; EXCLUDE=$1 ;; -f|--config-nbd) CONFIG_NBD=true ;; -h|--help) usage; exit 0 ;; -m|--no-compress) NO_COMPRESS=true ;; -n|--no-backup) NO_BACKUP=true ;; -r|--revert) REVERT=true ;; --version) ltsp_version; exit 0 ;; --) shift ; break ;; *) die "$0: Internal error!" ;; esac shift done require_root BASE=${BASE:-/opt/ltsp} # Remove trailing /, if present BASE=${BASE%/} if [ -z "$CONFIG_NBD" ]; then if [ -d /etc/nbd-server/conf.d ] && [ -n "$(find /etc/nbd-server/conf.d/ -type f -name 'ltsp_*.conf' ! -name ltsp_swap.conf)" ] then CONFIG_NBD=true fi if [ -z "$CONFIG_NBD" ]; then if grep -qsr ^/opt/ltsp /etc/exports /etc/exports.d/; then die "Your system seems to be using NFS to serve LTSP chroots. If you're absolutely certain you want to switch to NBD, run: $0 --config-nbd $*" fi fi fi # Chroots can be specified in the command line. If not, update all of them. if [ $# -eq 0 ]; then set -- $(list_chroots nfs) fi test $# -gt 0 || die "No chroots found in $BASE" for chroot in "$@"; do generate_image "$chroot" done ltsp-config --quiet nbd-server