Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85b2d27
Showing
60 changed files
with
5,824 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /bin/sh | ||
|
||
autologin=1 | ||
for opt in "$@" ; do | ||
if [ "$opt" = "-l" -o "$opt" = "-n" ] ; then | ||
autologin=0 | ||
fi | ||
done | ||
|
||
if [ "$autologin" = "1" ] ; then | ||
exec /sbin/getty -n -l /sbin/casper-login $* | ||
else | ||
exec /sbin/getty $* | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#! /bin/sh | ||
|
||
USERNAME=root | ||
[ -f /etc/casper.conf ] && . /etc/casper.conf | ||
exec /bin/login -f $USERNAME | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /bin/sh | ||
set -e | ||
PATH=/usr/sbin:/usr/bin:/sbin:/bin | ||
|
||
root="$1" | ||
question="$2" | ||
value="$3" | ||
seen="$4" | ||
[ "$seen" ] || seen=true | ||
|
||
if ! (echo "SET $question $value"; echo "FSET $question seen $seen") | chroot "$1" debconf-communicate -fnoninteractive casper >/dev/null; then | ||
chroot "$1" debconf-communicate -fnoninteractive casper >/dev/null <<EOF | ||
REGISTER debian-installer/dummy $question | ||
SET $question $value | ||
FSET $question seen $seen | ||
EOF | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#! /bin/sh | ||
|
||
set -e | ||
export PATH=/usr/bin:/usr/sbin:/sbin:/bin | ||
|
||
frontend=noninteractive | ||
|
||
findcommandinroot() { | ||
ROOT="$1/" | ||
shift | ||
while [ "$#" -ge 1 ]; do | ||
P="$PATH" | ||
while [ "$P" ]; do | ||
D=${P%%:*} | ||
P=${P#*:} | ||
if [ "$D" = "$P" ]; then | ||
P= | ||
fi | ||
if [ -z "$D" ]; then | ||
D=. | ||
fi | ||
if [ -x "$ROOT$D/$1" ]; then | ||
echo "$D/$1" | ||
return 0 | ||
fi | ||
done | ||
shift | ||
done | ||
return 1 | ||
} | ||
|
||
runcommandinroot() { | ||
C=$(findcommandinroot "$1" "$2") | ||
ROOT="$1" | ||
shift | ||
shift | ||
[ -n "$C" ] && chroot "$ROOT" "$C" "$@" | ||
} | ||
|
||
root="$1" | ||
package="$2" | ||
|
||
version=$(runcommandinroot "$root" dpkg-query -W --showformat='${Version}' "$package" 2>/dev/null) || version="" | ||
|
||
if [ -z "$version" ]; then | ||
echo >&2 "$0: package '$package' is not installed" | ||
exit 0 | ||
fi | ||
|
||
runcommandinroot "$root" dpkg-reconfigure -fnoninteractive --no-reload "$package" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,299 @@ | ||
#! /bin/bash | ||
|
||
# casper-snapshot - utility to manage Debian Live systems snapshots | ||
# | ||
# This program mount a device (fallback to /tmpfs under /mnt/snapshot | ||
# and save the /cow (or a different dir) filesystem in it for reusing | ||
# in another casper session. Look at manpage for more info. | ||
# | ||
# Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com> | ||
# | ||
# 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, write to the Free Software | ||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
# | ||
# On Debian systems, the complete text of the GNU General Public License | ||
# can be found in /usr/share/common-licenses/GPL file. | ||
|
||
PROGRAM="`basename $0`" | ||
VERSION=0.0.1 | ||
|
||
|
||
# Source casper conf | ||
if [ -e /etc/casper.conf ]; then | ||
. /etc/casper.conf | ||
else | ||
USERNAME=$(cat /etc/passwd | grep "999" | cut -f1 -d ':') | ||
HOSTNAME=$(hostname) | ||
BUILD_SYSTEM="Debian" | ||
fi | ||
|
||
export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM | ||
|
||
# Source helper functions | ||
helpers="/usr/share/initramfs-tools/scripts/casper-helpers" | ||
if [ -e "${helpers}" ]; then | ||
. "${helpers}" | ||
else | ||
echo "Error: I cannot found helper functions \"${helpers}\"." | ||
exit 1 | ||
fi | ||
|
||
# Define LSB log_* functions. | ||
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. | ||
. /lib/lsb/init-functions | ||
|
||
MOUNTP="" | ||
COW="" | ||
DEV="" | ||
DEST="" | ||
TYPE="" | ||
DESKTOP_LINK="" | ||
|
||
Header () | ||
{ | ||
echo "${PROGRAM} - utility to do Debian Live snapshots" | ||
echo | ||
echo "Usage: ${PROGRAM} [-c|--cow DIRECTORY] [-d|--device DEVICE] [-o|--output FILE] [-t|--type TYPE]" | ||
echo "Usage: ${PROGRAM} [-r|--resync-string STRING]" | ||
echo "Usage: ${PROGRAM} [-h|--help]" | ||
echo "Usage: ${PROGRAM} [-u|--usage]" | ||
echo "Usage: ${PROGRAM} [-v|--version]" | ||
} | ||
|
||
Usage () | ||
{ | ||
MESSAGE=${1} | ||
Header | ||
echo | ||
echo "Try \"${PROGRAM} --help\" for more information." | ||
if [ ! -z "${MESSAGE}" ]; then | ||
echo -e "${MESSAGE}" | ||
exit 1 | ||
else | ||
exit 0 | ||
fi | ||
} | ||
|
||
Help () | ||
{ | ||
Header | ||
echo | ||
echo "Options:" | ||
echo " -c, --cow: specifies the copy on write directory (default: /cow)." | ||
echo " -d, --device: specifies the output snapshot device (default: none)." | ||
echo " -o, --output: specifies the output image file (default: $type dependent)." | ||
echo " -r, --resync-string: internally used to resync previous made snapshots." | ||
echo " -t, --type: specifies the snapshot type between \"squashfs\", \"ext2\" or \"cpio\".gz archive (default: cpio)" | ||
echo -e "\nLook at casper-snapshot(1) man page for more information." | ||
exit 0 | ||
} | ||
|
||
Version () | ||
{ | ||
echo "${PROGRAM}, version ${VERSION}" | ||
echo | ||
echo "Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>" | ||
echo | ||
echo "This program is free software; you can redistribute it and/or modify" | ||
echo "it under the terms of the GNU General Public License as published by" | ||
echo "the Free Software Foundation; either version 2 of the License, or" | ||
echo "(at your option) any later version." | ||
echo | ||
echo "This program is distributed in the hope that it will be useful," | ||
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of" | ||
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" | ||
echo "GNU General Public License for more details." | ||
echo | ||
echo "You should have received a copy of the GNU General Public License" | ||
echo "along with this program; if not, write to the Free Software" | ||
echo "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA" | ||
echo | ||
echo "On Debian systems, the complete text of the GNU General Public License" | ||
echo "can be found in /usr/share/common-licenses/GPL file." | ||
echo | ||
echo "Homepage: <http://live.debian.net/>" | ||
exit 0 | ||
} | ||
|
||
Do_snapshot () | ||
{ | ||
case "${TYPE}" in | ||
squashfs) | ||
echo "./tmp/exclude_list" > /tmp/exclude_list | ||
( cd "${COW}" && find . -name '*.wh.*' >> /tmp/exclude_list ) | ||
mksquashfs "${COW}" "${DEST}" -ef /tmp/exclude_list || exit 1 | ||
rm /tmp/exclude_list | ||
;; | ||
cpio) | ||
( cd "${COW}" && find . -path '*.wh.*' -prune -o -print0 | cpio --quiet -o0 -H newc | gzip -9c > "${DEST}" ) || exit 1 | ||
;; | ||
ext2) | ||
DU_DIM="`du -ks ${COW} | cut -f1`" | ||
REAL_DIM="`expr ${DU_DIM} + ${DU_DIM} / 20`" # Just 5% more to be sure, need something more sophistcated here... | ||
genext2fs --size-in-blocks=${REAL_DIM} --reserved-blocks=0 --root="${COW}" "${DEST}" || exit 1 | ||
;; | ||
*) | ||
echo "Internal error." | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
Is_same_mount () | ||
{ | ||
dir1="`Base_path $1`" | ||
dir2="`Base_path $2`" | ||
if [ "${dir1}" == "${dir2}" ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
Parse_args () | ||
{ | ||
# Parse command line | ||
ARGS="$1" | ||
ARGUMENTS="`getopt --longoptions cow:,device:,output,resync-string:,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:r:,h,u,v --shell sh -- ${ARGS}`" | ||
|
||
if [ "$?" != "0" ]; then | ||
echo "Terminating." >&2 | ||
exit 1 | ||
fi | ||
|
||
eval set -- "${ARGUMENTS}" | ||
|
||
while true; do | ||
case "$1" in | ||
-c|--cow) | ||
SNAP_COW="$2"; shift 2 ;; | ||
-d|--device) | ||
SNAP_DEV="$2"; shift 2 ;; | ||
-o|--output) | ||
SNAP_OUTPUT="$2"; shift 2 ;; | ||
-t|--type) | ||
SNAP_TYPE="$2"; shift 2 ;; | ||
-r|--resync-string) | ||
SNAP_RSTRING="$2"; break ;; | ||
-h|--help) | ||
Help; shift ;; | ||
-u|--usage) | ||
Usage ; shift ;; | ||
-v|--version) | ||
Version; shift ;; | ||
--) | ||
shift; break ;; | ||
*) | ||
echo "Internal error."; exit 1 ;; | ||
esac | ||
done | ||
} | ||
|
||
Mount_device () | ||
{ | ||
dev="$1" | ||
|
||
if [ ! -d "${MOUNTP}" ]; then | ||
mkdir -p "${MOUNTP}" | ||
fi | ||
|
||
if [ -z "${dev}" ]; then | ||
# create a temp | ||
mount -t tmpfs -o rw tmpfs "${MOUNTP}" | ||
if [ ! -L /home/$USERNAME/Desktop/casper-snapshot ]; then | ||
ln -s "${MOUNTP}" /home/$USERNAME/Desktop/casper-snapshot | ||
fi | ||
else | ||
if [ -b "${dev}" ] ; then | ||
try_mount "${dev}" "${MOUNTP}" rw | ||
fi | ||
fi | ||
} | ||
|
||
Defaults () | ||
{ | ||
MOUNTP="/mnt/casper-snapshot" | ||
COW="/cow" | ||
DEV="" | ||
DEST="${MOUNTP}/casper-sn.cpio.gz" | ||
TYPE="cpio" | ||
DESKTOP_LINK=/home/$USERNAME/Desktop/casper-snapshot | ||
|
||
if [ -n "${SNAP_RSTRING}" ]; then | ||
COW=$(echo "${SNAP_RSTRING}" | cut -f1 -d ':') | ||
DEV=$(echo "${SNAP_RSTRING}" | cut -f2 -d ':') | ||
DEST=$(echo "${SNAP_RSTRING}" | cut -f3 -d ':') | ||
|
||
case "${DEST}" in | ||
*.cpio.gz) | ||
TYPE="cpio" ;; | ||
*.squashfs) | ||
TYPE="squashfs" ;; | ||
"") | ||
TYPE="ext2" ;; | ||
*.ext2) | ||
TYPE="ext2" ;; | ||
*) | ||
Usage "Unregognized String" ;; | ||
esac | ||
else | ||
DEF_COW="/cow" | ||
# Bad options handling | ||
if [ -z "${SNAP_COW}" ]; then | ||
COW="${DEF_COW}" | ||
else | ||
COW="${SNAP_COW}" | ||
fi | ||
|
||
case "${SNAP_TYPE}" in | ||
"cpio"|"squashfs"|"ext2") | ||
TYPE="${SNAP_TYPE}" | ||
;; | ||
"") | ||
TYPE="cpio" ;; | ||
*) | ||
Usage "Error: unrecognized snapshot type" | ||
;; | ||
esac | ||
#if [ -d | ||
#if Is_same_mount | ||
fi | ||
|
||
# check vars | ||
if [ ! -d "${COW}" ]; then | ||
Usage "Error: ${COW} is not a directory" | ||
fi | ||
|
||
Mount_device $DEV | ||
|
||
} | ||
|
||
Clean () | ||
{ | ||
if [ -n "$DEV" ]; then | ||
umount "${MOUNTP}" | ||
rmdir "${MOUNTP}" | ||
rm | ||
fi | ||
} | ||
|
||
Main () | ||
{ | ||
Parse_args "$@" | ||
Defaults | ||
Do_snapshot | ||
Clean | ||
} | ||
|
||
Main "$@" |
Oops, something went wrong.