Major infrastructure changes, part 2.
* Moved helpers, common and triggers dirs into xbps-src, where
they belong.
* Renamed the templates dir to srcpkgs, it was so redundant before.
* Make it possible to add subpkgs with no restriction in names, for
example udev now has a subpkgs called "libgudev". Previously
subpkgs were named "${sourcepkg}-${pkgname}".
* xbps-src: changed to look for template files in current directory.
That means that most arguments from the targets have been removed.
* xbps-src: added a reinstall target, to remove + install.
* xbps-src: do not overwrite binpkgs by default, skip them.
And more that I forgot because it's a mega-commit that I've been
working for some days already...
--HG--
extra : convert_revision : 0f466878584d1e6895d2a234f07ea1b2d1e61b3e
This commit is contained in:
613
srcpkgs/xbps-casper/files/scripts/casper
Normal file
613
srcpkgs/xbps-casper/files/scripts/casper
Normal file
@@ -0,0 +1,613 @@
|
||||
#!/bin/sh
|
||||
|
||||
# set -e
|
||||
|
||||
export PATH=/usr/bin:/usr/sbin:/bin:/sbin
|
||||
|
||||
mountpoint=/cdrom
|
||||
LIVE_MEDIA_PATH=casper
|
||||
|
||||
root_persistence="casper-rw"
|
||||
home_persistence="home-rw"
|
||||
root_snapshot_label="casper-sn"
|
||||
home_snapshot_label="home-sn"
|
||||
|
||||
USERNAME=casper
|
||||
USERFULLNAME="Live session user"
|
||||
HOST=live
|
||||
BUILD_SYSTEM=Custom
|
||||
|
||||
mkdir -p $mountpoint
|
||||
|
||||
[ -f /etc/casper.conf ] && . /etc/casper.conf
|
||||
export USERNAME USERFULLNAME HOST BUILD_SYSTEM
|
||||
|
||||
. /scripts/casper-helpers
|
||||
|
||||
if [ ! -f /casper.vars ]; then
|
||||
touch /casper.vars
|
||||
fi
|
||||
|
||||
parse_cmdline() {
|
||||
for x in $(cat /proc/cmdline); do
|
||||
case $x in
|
||||
toram)
|
||||
export TORAM='Yes' ;;
|
||||
showmounts|show-cow)
|
||||
export SHOWMOUNTS='Yes' ;;
|
||||
persistent)
|
||||
export PERSISTENT="Yes" ;;
|
||||
nopersistent)
|
||||
export PERSISTENT="" ;;
|
||||
union=*)
|
||||
export UNIONFS="${x#union=}";;
|
||||
ip*)
|
||||
STATICIP=${x#ip=}
|
||||
if [ "${STATICIP}" = "" ]; then
|
||||
STATICIP="frommedia"
|
||||
fi
|
||||
export STATICIP ;;
|
||||
ignore_uuid)
|
||||
IGNORE_UUID="Yes" ;;
|
||||
live-media-path=*)
|
||||
LIVE_MEDIA_PATH="${x#live-media-path=}"
|
||||
export LIVE_MEDIA_PATH
|
||||
echo "export LIVE_MEDIA_PATH=\"$LIVE_MEDIA_PATH\"" \
|
||||
>> /etc/casper.conf ;;
|
||||
esac
|
||||
done
|
||||
if [ "${UNIONFS}" = "" ]; then
|
||||
export UNIONFS="unionfs"
|
||||
fi
|
||||
}
|
||||
|
||||
is_casper_path() {
|
||||
path=$1
|
||||
if [ -d "$path/$LIVE_MEDIA_PATH" ]; then
|
||||
if [ "$(echo $path/$LIVE_MEDIA_PATH/*.squashfs)" != \
|
||||
"$path/$LIVE_MEDIA_PATH/*.squashfs" ] ||
|
||||
[ "$(echo $path/$LIVE_MEDIA_PATH/*.ext2)" != \
|
||||
"$path/$LIVE_MEDIA_PATH/*.ext2" ] ||
|
||||
[ "$(echo $path/$LIVE_MEDIA_PATH/*.dir)" != \
|
||||
"$path/$LIVE_MEDIA_PATH/*.dir" ]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
matches_uuid() {
|
||||
if [ "$IGNORE_UUID" ] || [ ! -e /conf/uuid.conf ]; then
|
||||
return 0
|
||||
fi
|
||||
path="$1"
|
||||
uuid="$(cat /conf/uuid.conf)"
|
||||
for try_uuid_file in "$path/.disk/casper-uuid"*; do
|
||||
[ -e "$try_uuid_file" ] || continue
|
||||
try_uuid="$(cat "$try_uuid_file")"
|
||||
if [ "$uuid" = "$try_uuid" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
get_backing_device() {
|
||||
case "$1" in
|
||||
*.squashfs|*.ext2)
|
||||
echo $(setup_loop "$1" "loop" "/sys/block/loop*")
|
||||
;;
|
||||
*.dir)
|
||||
echo "directory"
|
||||
;;
|
||||
*)
|
||||
panic "Unrecognized casper filesystem: $1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
match_files_in_dir() {
|
||||
# Does any files match pattern $1 ?
|
||||
|
||||
local pattern="$1"
|
||||
if [ "$(echo $pattern)" != "$pattern" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
mount_images_in_directory() {
|
||||
directory="$1"
|
||||
rootmnt="$2"
|
||||
if match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.squashfs" ||
|
||||
match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.ext2" ||
|
||||
match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.dir"; then
|
||||
setup_unionfs "$directory/$LIVE_MEDIA_PATH" "$rootmnt"
|
||||
else
|
||||
:
|
||||
fi
|
||||
}
|
||||
|
||||
is_nice_device() {
|
||||
sysfs_path="${1#/sys}"
|
||||
if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb)|platform-mmc|platform-mxsdhci)"; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
copy_live_to() {
|
||||
copyfrom="${1}"
|
||||
copytodev="${2}"
|
||||
copyto="${copyfrom}_swap"
|
||||
|
||||
size=$(fs_size "" ${copyfrom} "used")
|
||||
|
||||
if [ "${copytodev}" = "ram" ]; then
|
||||
# copying to ram:
|
||||
freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
|
||||
mount_options="-o size=${size}k"
|
||||
free_string="memory"
|
||||
fstype="tmpfs"
|
||||
dev="/dev/shm"
|
||||
else
|
||||
# it should be a writable block device
|
||||
if [ -b "${copytodev}" ]; then
|
||||
dev="${copytodev}"
|
||||
free_string="space"
|
||||
fstype=$(get_fstype "${dev}")
|
||||
freespace=$(fs_size "${dev}")
|
||||
else
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_warning_msg "${copytodev} is not a block device."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ "${freespace}" -lt "${size}" ] ; then
|
||||
[ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# begin copying..
|
||||
mkdir "${copyto}"
|
||||
echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
|
||||
mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
|
||||
# "cp -a" from busybox also copies hidden files
|
||||
cp -a ${copyfrom}/* ${copyto}
|
||||
umount ${copyfrom}
|
||||
mount -r -o move ${copyto} ${copyfrom}
|
||||
rmdir ${copyto}
|
||||
return 0
|
||||
}
|
||||
|
||||
do_netmount() {
|
||||
rc=1
|
||||
|
||||
modprobe "${MP_QUIET}" af_packet # For DHCP
|
||||
|
||||
/sbin/udevadm trigger
|
||||
/sbin/udevadm settle
|
||||
|
||||
ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
|
||||
|
||||
if [ "${NFSROOT}" = "auto" ]; then
|
||||
NFSROOT=${ROOTSERVER}:${ROOTPATH}
|
||||
fi
|
||||
|
||||
[ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
|
||||
|
||||
if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
|
||||
rc=0
|
||||
elif do_nfsmount ; then
|
||||
NETBOOT="nfs"
|
||||
export NETBOOT
|
||||
rc=0
|
||||
fi
|
||||
|
||||
[ "$quiet" != "y" ] && log_end_msg
|
||||
return ${rc}
|
||||
}
|
||||
|
||||
do_nfsmount() {
|
||||
rc=1
|
||||
modprobe "${MP_QUIET}" nfs
|
||||
if [ -z "${NFSOPTS}" ]; then
|
||||
NFSOPTS=""
|
||||
fi
|
||||
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
|
||||
# FIXME: This while loop is an ugly HACK round an nfs bug
|
||||
i=0
|
||||
while [ "$i" -lt 60 ]; do
|
||||
nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" \
|
||||
"${mountpoint}" && rc=0 && break
|
||||
sleep 1
|
||||
i="$(($i + 1))"
|
||||
done
|
||||
return ${rc}
|
||||
}
|
||||
|
||||
do_cifsmount() {
|
||||
rc=1
|
||||
if [ -x "/sbin/mount.cifs" ]; then
|
||||
if [ -z "${NFSOPTS}" ]; then
|
||||
CIFSOPTS="-ouser=root,password="
|
||||
else
|
||||
CIFSOPTS="${NFSOPTS}"
|
||||
fi
|
||||
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
|
||||
modprobe "${MP_QUIET}" cifs
|
||||
|
||||
if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
|
||||
rc=0
|
||||
fi
|
||||
fi
|
||||
return ${rc}
|
||||
}
|
||||
|
||||
do_snap_copy ()
|
||||
{
|
||||
fromdev="${1}"
|
||||
todir="${2}"
|
||||
snap_type="${3}"
|
||||
|
||||
size=$(fs_size "${fromdev}" "" "used")
|
||||
|
||||
if [ -b "${fromdev}" ]; then
|
||||
# look for free mem
|
||||
if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
|
||||
todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
|
||||
freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
|
||||
else
|
||||
freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
|
||||
fi
|
||||
|
||||
tomount="/mnt/tmpsnap"
|
||||
if [ ! -d "${tomount}" ] ; then
|
||||
mkdir -p "${tomount}"
|
||||
fi
|
||||
|
||||
fstype=$(get_fstype "${fromdev}")
|
||||
if [ -n "${fstype}" ]; then
|
||||
# Copying stuff...
|
||||
mount -t "${fstype}" -o ro,noatime "${fromdev}" "${tomount}"
|
||||
cp -a "${tomount}"/* ${todir}
|
||||
umount "${tomount}"
|
||||
else
|
||||
log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
|
||||
fi
|
||||
|
||||
rmdir "${tomount}"
|
||||
if echo ${fromdev} | grep -qs loop; then
|
||||
losetup -d "${fromdev}"
|
||||
fi
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_warning_msg "Unable to find the snapshot ${snap_type} medium"
|
||||
fi
|
||||
}
|
||||
|
||||
try_snap ()
|
||||
{
|
||||
# Look for $snap_label.* in block devices and copy the contents to $snap_mount
|
||||
# and remember the device and filename for resync on exit in casper.init
|
||||
|
||||
snap_label="${1}"
|
||||
snap_mount="${2}"
|
||||
snap_type="${3}"
|
||||
|
||||
snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
|
||||
if [ ! -z "${snapdata}" ]; then
|
||||
snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
|
||||
snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
|
||||
snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
|
||||
if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
|
||||
# squashfs or ext2 snapshot
|
||||
dev=$(get_backing_device "${snapback}/${snapfile}")
|
||||
if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
|
||||
log_warning_msg "Impossible to include the ${snapfile} Snapshot"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
# cpio.gz snapshot
|
||||
# Unfortunately klibc's cpio is incompatible with the rest of
|
||||
# the world; everything else requires -u -d, while klibc doesn't
|
||||
# implement them. Try to detect whether it's in use.
|
||||
cpiopath="$(which cpio)" || true
|
||||
if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"; then
|
||||
cpioargs=
|
||||
else
|
||||
cpioargs='-u -d'
|
||||
fi
|
||||
if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i $cpioargs 2>/dev/null) ; then
|
||||
log_warning_msg "Impossible to include the ${snapfile} Snapshot"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
umount "${snapback}"
|
||||
else
|
||||
dev=$(find_cow_device "${snap_label}")
|
||||
if [ -b ${dev} ]; then
|
||||
if echo "${dev}" | grep -qs loop; then
|
||||
# strange things happens, user confused?
|
||||
snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
|
||||
snapfile=$(basename ${snaploop})
|
||||
snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
|
||||
else
|
||||
snapdev="${dev}"
|
||||
fi
|
||||
if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
|
||||
log_warning_msg "Impossible to include the ${snap_label} Snapshot"
|
||||
return 1
|
||||
else
|
||||
if [ -n "${snapfile}" ]; then
|
||||
# it was a loop device, user confused
|
||||
umount ${snapdev}
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_warning_msg "Impossible to include the ${snap_label} Snapshot"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_unionfs() {
|
||||
image_directory="$1"
|
||||
rootmnt="$2"
|
||||
|
||||
case ${UNIONFS} in
|
||||
aufs|unionfs)
|
||||
modprobe "${MP_QUIET}" -b ${UNIONFS} || true
|
||||
;;
|
||||
esac
|
||||
|
||||
# run-init can't deal with images in a subdir, but we're going to
|
||||
# move all of these away before it runs anyway. No, we're not,
|
||||
# put them in / since move-mounting them into / breaks mono and
|
||||
# some other apps.
|
||||
|
||||
croot="/"
|
||||
|
||||
# Let's just mount the read-only file systems first
|
||||
rofsstring=""
|
||||
rofslist=""
|
||||
if [ "${NETBOOT}" = "nfs" ] ; then
|
||||
roopt="nfsro" # work around a bug in nfs-unionfs locking
|
||||
elif [ "${UNIONFS}" = "aufs" ]; then
|
||||
roopt="rr"
|
||||
else
|
||||
roopt="ro"
|
||||
fi
|
||||
|
||||
mkdir -p "${croot}"
|
||||
for image_type in "ext2" "squashfs" "dir" ; do
|
||||
for image in "${image_directory}"/*."${image_type}"; do
|
||||
imagename=$(basename "${image}")
|
||||
if [ -d "${image}" ]; then
|
||||
# it is a plain directory: do nothing
|
||||
rofsstring="${image}=${roopt}:${rofsstring}"
|
||||
rofslist="${image} ${rofslist}"
|
||||
elif [ -f "${image}" ]; then
|
||||
backdev=$(get_backing_device "$image")
|
||||
fstype=$(get_fstype "${backdev}")
|
||||
if [ "${fstype}" = "unknown" ]; then
|
||||
panic "Unknown file system type on ${backdev} (${image})"
|
||||
fi
|
||||
mkdir -p "${croot}/${imagename}"
|
||||
mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
rofsstring=${rofsstring%:}
|
||||
|
||||
mkdir -p /cow
|
||||
cowdevice="tmpfs"
|
||||
cow_fstype="tmpfs"
|
||||
cow_mountopt="rw,noatime,mode=755"
|
||||
|
||||
# Looking for "${root_persistence}" device or file
|
||||
if [ -n "${PERSISTENT}" ]; then
|
||||
cowprobe=$(find_cow_device "${root_persistence}")
|
||||
if [ -b "${cowprobe}" ]; then
|
||||
cowdevice=${cowprobe}
|
||||
cow_fstype=$(get_fstype "${cowprobe}")
|
||||
cow_mountopt="rw,noatime"
|
||||
else
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_warning_msg "Unable to find the persistent medium"
|
||||
fi
|
||||
fi
|
||||
|
||||
mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} \
|
||||
/cow || panic "Can not mount $cowdevice on /cow"
|
||||
mount -t ${UNIONFS} -o noatime,dirs=/cow=rw:$rofsstring \
|
||||
${UNIONFS} "$rootmnt" || panic "${UNIONFS} mount failed"
|
||||
|
||||
# Adding other custom mounts
|
||||
if [ -n "${PERSISTENT}" ]; then
|
||||
# directly mount /home
|
||||
# FIXME: add a custom mounts configurable system
|
||||
homecow=$(find_cow_device "${home_persistence}" )
|
||||
if [ -b "${homecow}" ]; then
|
||||
mount -t $(get_fstype "${homecow}") -o rw,noatime \
|
||||
"${homecow}" "${rootmnt}/home"
|
||||
# Used to proper calculate free space in do_snap_copy()
|
||||
export HOMEMOUNTED=1
|
||||
else
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_warning_msg "Unable to find the persistent home medium"
|
||||
fi
|
||||
# Look for other snapshots to copy in
|
||||
try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
|
||||
try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
|
||||
fi
|
||||
|
||||
if [ -n "${SHOWMOUNTS}" ]; then
|
||||
for d in ${rofslist}; do
|
||||
mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
|
||||
case d in
|
||||
*.dir)
|
||||
# do nothing
|
||||
;;
|
||||
*)
|
||||
mount -o move "${d}" \
|
||||
"${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# shows cow fs on /cow for use by casper-snapshot
|
||||
mkdir -p "${rootmnt}/cow"
|
||||
mount -o bind /cow "${rootmnt}/cow"
|
||||
fi
|
||||
|
||||
# XXX: hardcode the image name for now (xtraeme).
|
||||
# move the first mount.
|
||||
mkdir -p "${rootmnt}/rofs"
|
||||
mount -o move /filesystem.squashfs "${rootmnt}/rofs"
|
||||
}
|
||||
|
||||
check_dev ()
|
||||
{
|
||||
sysdev="${1}"
|
||||
devname="${2}"
|
||||
skip_uuid_check="${3}"
|
||||
if [ -z "${devname}" ]; then
|
||||
devname=$(sys2dev "${sysdev}")
|
||||
fi
|
||||
|
||||
if [ -d "${devname}" ]; then
|
||||
mount -o bind "${devname}" $mountpoint || continue
|
||||
if is_casper_path $mountpoint; then
|
||||
echo $mountpoint
|
||||
return 0
|
||||
else
|
||||
umount $mountpoint
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${LIVEMEDIA_OFFSET}" ]; then
|
||||
loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}")
|
||||
devname="${loopdevname}"
|
||||
fi
|
||||
|
||||
fstype=$(get_fstype "${devname}")
|
||||
if is_supported_fs ${fstype}; then
|
||||
mount -t ${fstype} -o ro,noatime "${devname}" $mountpoint || continue
|
||||
if is_casper_path $mountpoint && \
|
||||
([ "$skip_uuid_check" ] || matches_uuid $mountpoint); then
|
||||
echo $mountpoint
|
||||
return 0
|
||||
else
|
||||
umount $mountpoint
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${LIVEMEDIA_OFFSET}" ]; then
|
||||
losetup -d "${loopdevname}"
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
find_livefs() {
|
||||
timeout="${1}"
|
||||
# first look at the one specified in the command line
|
||||
if [ ! -z "${LIVEMEDIA}" ]; then
|
||||
if check_dev "null" "${LIVEMEDIA}" "skip_uuid_check"; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
# don't start autodetection before timeout has expired
|
||||
if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
|
||||
if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
# or do the scan of block devices
|
||||
for sysblock in \
|
||||
$(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|fd)"); do
|
||||
devname=$(sys2dev "${sysblock}")
|
||||
fstype=$(get_fstype "${devname}")
|
||||
if /lib/udev/cdrom_id ${devname} > /dev/null; then
|
||||
if check_dev "null" "${devname}" ; then
|
||||
return 0
|
||||
fi
|
||||
elif is_nice_device "${sysblock}" ; then
|
||||
for dev in $(subdevices "${sysblock}"); do
|
||||
if check_dev "${dev}" ; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
elif [ "${fstype}" = "squashfs" -o \
|
||||
"${fstype}" = "ext4" -o \
|
||||
"${fstype}" = "ext3" -o \
|
||||
"${fstype}" = "ext2" ]; then
|
||||
# This is an ugly hack situation, the block device has
|
||||
# an image directly on it. It's hopefully
|
||||
# casper, so take it and run with it.
|
||||
ln -s "${devname}" "${devname}.${fstype}"
|
||||
echo "${devname}.${fstype}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
mountroot() {
|
||||
parse_cmdline
|
||||
wait_for_udev 10
|
||||
|
||||
maybe_break casper-premount
|
||||
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
|
||||
run_scripts /scripts/casper-premount
|
||||
[ "$quiet" != "y" ] && log_end_msg
|
||||
|
||||
if [ ! -z "${NETBOOT}" ]; then
|
||||
if do_netmount ; then
|
||||
livefs_root="${mountpoint}"
|
||||
else
|
||||
panic "Unable to find a live file system on the network"
|
||||
fi
|
||||
else
|
||||
# Scan local devices for the image
|
||||
i=0
|
||||
while [ "$i" -lt 60 ]; do
|
||||
livefs_root=$(find_livefs $i)
|
||||
if [ "${livefs_root}" ]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
i="$(($i + 1))"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "${livefs_root}" ]; then
|
||||
panic "Unable to find a medium containing a live file system"
|
||||
fi
|
||||
|
||||
if [ "${TORAM}" ]; then
|
||||
live_dest="ram"
|
||||
elif [ "${TODISK}" ]; then
|
||||
live_dest="${TODISK}"
|
||||
fi
|
||||
if [ "${live_dest}" ]; then
|
||||
[ "$quiet" != "y" ] && \
|
||||
log_begin_msg "Copying live_media to ${live_dest}"
|
||||
copy_live_to "${livefs_root}" "${live_dest}"
|
||||
[ "$quiet" != "y" ] && log_end_msg
|
||||
fi
|
||||
|
||||
mount_images_in_directory "${livefs_root}" "${rootmnt}"
|
||||
|
||||
maybe_break casper-bottom
|
||||
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
|
||||
run_scripts /scripts/casper-bottom
|
||||
[ "$quiet" != "y" ] && log_end_msg
|
||||
}
|
||||
27
srcpkgs/xbps-casper/files/scripts/casper-bottom/05mountpoints
Executable file
27
srcpkgs/xbps-casper/files/scripts/casper-bottom/05mountpoints
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up /cdrom mountpoint"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
# Move to the new root filesystem so that programs there can get at it.
|
||||
mkdir -p /root/cdrom
|
||||
mount -n -o move /cdrom /root/cdrom
|
||||
|
||||
log_end_msg
|
||||
30
srcpkgs/xbps-casper/files/scripts/casper-bottom/10adduser
Executable file
30
srcpkgs/xbps-casper/files/scripts/casper-bottom/10adduser
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up live session user '$USERNAME'"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
# U6aMy0wojraho is just a blank password
|
||||
chroot ${rootmnt} useradd -c "$USERFULLNAME" -m $USERNAME \
|
||||
-G audio -p U6aMy0wojraho
|
||||
if [ -f ${rootmnt}/etc/sudoers ]; then
|
||||
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${rootmnt}/etc/sudoers
|
||||
fi
|
||||
|
||||
log_end_msg
|
||||
43
srcpkgs/xbps-casper/files/scripts/casper-bottom/11keymap
Executable file
43
srcpkgs/xbps-casper/files/scripts/casper-bottom/11keymap
Executable file
@@ -0,0 +1,43 @@
|
||||
#! /bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up system keymap"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
# commandline
|
||||
for x in $(cat /proc/cmdline); do
|
||||
case $x in
|
||||
keymap=*)
|
||||
keymap=${x#keymap=}
|
||||
set_keymap="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${set_keymap}" ]; then
|
||||
sed -i -e "s|qwerty/us|qwerty/${keymap}|" \
|
||||
"${rootmnt}/etc/conf.d/keymaps"
|
||||
fi
|
||||
|
||||
if [ -f "${rootmnt}/etc/hal/fdi/policy/10-keymap.fdi" ]; then
|
||||
sed -i -e "s|>us<|>${keymap}<|" \
|
||||
${rootmnt}/etc/hal/fdi/policy/10-keymap.fdi
|
||||
fi
|
||||
|
||||
log_end_msg
|
||||
29
srcpkgs/xbps-casper/files/scripts/casper-bottom/12fstab
Executable file
29
srcpkgs/xbps-casper/files/scripts/casper-bottom/12fstab
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up /etc/fstab"
|
||||
FSTAB=${rootmnt}/etc/fstab
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
cat > $FSTAB <<EOF
|
||||
${UNIONFS} / ${UNIONFS} rw 0 0
|
||||
tmpfs /tmp tmpfs nosuid,nodev 0 0
|
||||
EOF
|
||||
|
||||
log_end_msg
|
||||
47
srcpkgs/xbps-casper/files/scripts/casper-bottom/13swap
Executable file
47
srcpkgs/xbps-casper/files/scripts/casper-bottom/13swap
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up swap"
|
||||
FSTAB=${rootmnt}/etc/fstab
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
devices=""
|
||||
for device in /dev/[hs]d[a-z][0-9]*; do
|
||||
if ! [ -b "$device" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
/sbin/blkid -o udev -p ${device%%[0-9]*} | \
|
||||
grep -q "^ID_FS_USAGE=raid" && continue
|
||||
|
||||
magic=$(/bin/dd if="$device" bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null) || continue
|
||||
|
||||
if [ "$magic" = "SWAPSPACE2" -o "$magic" = "SWAP-SPACE" ]; then
|
||||
# log "Found $device"
|
||||
devices="$devices $device"
|
||||
fi
|
||||
done
|
||||
|
||||
for device in $devices; do
|
||||
cat >> $FSTAB <<EOF
|
||||
$device swap swap defaults 0 0
|
||||
EOF
|
||||
done
|
||||
|
||||
log_end_msg
|
||||
37
srcpkgs/xbps-casper/files/scripts/casper-bottom/14locales
Executable file
37
srcpkgs/xbps-casper/files/scripts/casper-bottom/14locales
Executable file
@@ -0,0 +1,37 @@
|
||||
#! /bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up system locale"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
# commandline
|
||||
for x in $(cat /proc/cmdline); do
|
||||
case $x in
|
||||
locale=*)
|
||||
locale=${x#locale=}
|
||||
set_locale="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${set_locale}" ]; then
|
||||
echo "system_locale=\"$locale\"" > ${rootmnt}/etc/conf.d/locale
|
||||
fi
|
||||
|
||||
log_end_msg
|
||||
25
srcpkgs/xbps-casper/files/scripts/casper-bottom/15autologin
Executable file
25
srcpkgs/xbps-casper/files/scripts/casper-bottom/15autologin
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up automatic login"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
if [ -f "${rootmnt}/etc/inittab" ]; then
|
||||
sed -i -e "s|agetty|casper-getty|g" "${rootmnt}/etc/inittab"
|
||||
fi
|
||||
log_end_msg
|
||||
38
srcpkgs/xbps-casper/files/scripts/casper-bottom/18hostname
Executable file
38
srcpkgs/xbps-casper/files/scripts/casper-bottom/18hostname
Executable file
@@ -0,0 +1,38 @@
|
||||
#! /bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up hostname"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
echo "hostname=$HOST" > "${rootmnt}/etc/conf.d/hostname"
|
||||
cat > /root/etc/hosts <<EOF
|
||||
127.0.0.1 localhost
|
||||
127.0.1.1 $HOST
|
||||
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
ff02::3 ip6-allhosts
|
||||
|
||||
EOF
|
||||
|
||||
log_end_msg
|
||||
46
srcpkgs/xbps-casper/files/scripts/casper-bottom/30policykit
Executable file
46
srcpkgs/xbps-casper/files/scripts/casper-bottom/30policykit
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ=""
|
||||
DESCRIPTION="Setting up PolicyKit actions for user '${USERNAME}'"
|
||||
|
||||
. /scripts/casper-functions
|
||||
|
||||
prereqs()
|
||||
{
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
# get pre-requisites
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
conf_file=${rootmnt}/etc/PolicyKit/PolicyKit.conf
|
||||
if [ ! -f ${conf_file} ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log_begin_msg "$DESCRIPTION"
|
||||
|
||||
rm -f ${conf_file}
|
||||
cat >> ${conf_file} <<_EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
|
||||
|
||||
<!DOCTYPE pkconfig PUBLIC "-//freedesktop//DTD PolicyKit Configuration 1.0//EN"
|
||||
"http://hal.freedesktop.org/releases/PolicyKit/1.0/config.dtd">
|
||||
|
||||
<!-- See the manual page PolicyKit.conf(5) for file format -->
|
||||
|
||||
<config version="0.1">
|
||||
<match action="org.freedesktop.hal.*">
|
||||
<match user="${USERNAME}">
|
||||
<return result="yes"/>
|
||||
</match>
|
||||
</match>
|
||||
</config>
|
||||
_EOF
|
||||
|
||||
log_end_msg
|
||||
12
srcpkgs/xbps-casper/files/scripts/casper-functions
Normal file
12
srcpkgs/xbps-casper/files/scripts/casper-functions
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
. /scripts/functions
|
||||
|
||||
# Print a message and wait for enter
|
||||
log_wait_msg()
|
||||
{
|
||||
if [ -x /sbin/usplash_write ]; then
|
||||
/sbin/usplash_write "INPUTENTER $@"
|
||||
read nunya < /dev/.initramfs/usplash_outfifo
|
||||
fi
|
||||
_log_msg "Waiting: $@ ..."
|
||||
}
|
||||
231
srcpkgs/xbps-casper/files/scripts/casper-helpers
Normal file
231
srcpkgs/xbps-casper/files/scripts/casper-helpers
Normal file
@@ -0,0 +1,231 @@
|
||||
## Casper helper functions, used by casper on boot and by casper-snapshot
|
||||
|
||||
MP_QUIET="-q"
|
||||
|
||||
if [ ! -x "/bin/fstype" ]; then
|
||||
# klibc not in path -> not in initramfs
|
||||
export PATH="${PATH}:/usr/lib/klibc/bin"
|
||||
fi
|
||||
|
||||
sys2dev() {
|
||||
sysdev=${1#/sys}
|
||||
echo "/dev/$(/sbin/udevadm info -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
|
||||
}
|
||||
|
||||
subdevices() {
|
||||
sysblock=$1
|
||||
r=""
|
||||
for dev in "${sysblock}" "${sysblock}"/*; do
|
||||
if [ -e "${dev}/dev" ]; then
|
||||
r="${r} ${dev}"
|
||||
fi
|
||||
done
|
||||
echo ${r}
|
||||
}
|
||||
|
||||
is_supported_fs () {
|
||||
# FIXME: do something better like the scan of supported filesystems
|
||||
fstype="${1}"
|
||||
case ${fstype} in
|
||||
vfat|iso9660|udf|ext2|ext3|ext4|ntfs)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
get_fstype() {
|
||||
local FSTYPE
|
||||
local FSSIZE
|
||||
eval $(fstype < $1)
|
||||
if [ "$FSTYPE" != "unknown" ]; then
|
||||
echo $FSTYPE
|
||||
return 0
|
||||
fi
|
||||
/sbin/blkid -s TYPE -o value $1 2>/dev/null
|
||||
}
|
||||
|
||||
where_is_mounted() {
|
||||
device=$1
|
||||
if grep -q "^$device " /proc/mounts; then
|
||||
mountpoint="$(grep "^$device " /proc/mounts | awk '{print $2; exit}')"
|
||||
grep "^$device " /proc/mounts | read d mountpoint rest
|
||||
echo $mountpoint
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
lastline() {
|
||||
while read lines ; do
|
||||
line=${lines}
|
||||
done
|
||||
echo "${line}"
|
||||
}
|
||||
|
||||
base_path ()
|
||||
{
|
||||
testpath="${1}"
|
||||
mounts="$(awk '{print $2}' /proc/mounts)"
|
||||
testpath="$(busybox realpath ${testpath})"
|
||||
|
||||
while true ; do
|
||||
if echo "${mounts}" | grep -qs "^${testpath}" ; then
|
||||
set -- `echo "${mounts}" | grep "^${testpath}" | lastline`
|
||||
echo ${1}
|
||||
break
|
||||
else
|
||||
testpath=`dirname $testpath`
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
fs_size ()
|
||||
{
|
||||
# Returns used/free fs kbytes + 5% more
|
||||
# You could pass a block device as $1 or the mount point as $2
|
||||
|
||||
dev="${1}"
|
||||
mountp="${2}"
|
||||
used="${3}"
|
||||
|
||||
if [ -z "${mountp}" ]; then
|
||||
mountp=$(where_is_mounted "${dev}")
|
||||
if [ "$?" -gt 0 ]; then
|
||||
mountp="/mnt/tmp_fs_size"
|
||||
mkdir -p "${mountp}"
|
||||
mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}"
|
||||
doumount=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${used}" = "used" ]; then
|
||||
size=$(du -ks ${mountp} | cut -f1)
|
||||
size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
|
||||
else
|
||||
# free space
|
||||
size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
|
||||
fi
|
||||
|
||||
if [ -n "${doumount}" ]; then
|
||||
umount "${mountp}"
|
||||
rmdir "${mountp}"
|
||||
fi
|
||||
echo "${size}"
|
||||
}
|
||||
|
||||
setup_loop() {
|
||||
local fspath=$1
|
||||
local module=$2
|
||||
local pattern=$3
|
||||
local offset=$4
|
||||
|
||||
modprobe ${MP_QUIET} -b "$module"
|
||||
/sbin/udevadm settle
|
||||
|
||||
if [ "$module" = loop ]; then
|
||||
if [ ! -e /dev/loop0 ]; then
|
||||
# temporary workaround for kernel bug
|
||||
for i in 0 1 2 3 4 5 6 7; do
|
||||
mknod "/dev/loop$i" b 7 "$i" || true
|
||||
done
|
||||
fi
|
||||
|
||||
dev="$(losetup -f)"
|
||||
if [ "$dev" ]; then
|
||||
if [ -n "$offset" ]; then
|
||||
losetup -o "$offset" "$dev" "$fspath"
|
||||
else
|
||||
losetup "$dev" "$fspath"
|
||||
fi
|
||||
echo "$dev"
|
||||
return 0
|
||||
else
|
||||
panic "No loop devices available"
|
||||
fi
|
||||
else
|
||||
for loopdev in $pattern; do
|
||||
if [ "$(cat $loopdev/size)" -eq 0 ]; then
|
||||
dev=$(sys2dev "${loopdev}")
|
||||
if [ -n "$offset" ]; then
|
||||
losetup -o "$offset" "$dev" "$fspath"
|
||||
else
|
||||
losetup "$dev" "$fspath"
|
||||
fi
|
||||
echo "$dev"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
panic "No loop devices available"
|
||||
fi
|
||||
}
|
||||
|
||||
try_mount ()
|
||||
{
|
||||
dev="${1}"
|
||||
mountp="${2}"
|
||||
opts="${3}"
|
||||
|
||||
if where_is_mounted ${dev} > /dev/null; then
|
||||
if [ "${opts}" != "ro" ]; then
|
||||
mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
|
||||
fi
|
||||
mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
|
||||
else
|
||||
mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
|
||||
fi
|
||||
}
|
||||
|
||||
find_cow_device() {
|
||||
pers_label="${1}"
|
||||
cow_backing="/${pers_label}-backing"
|
||||
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
|
||||
for dev in $(subdevices "${sysblock}"); do
|
||||
devname=$(sys2dev "${dev}")
|
||||
if [ "$(/sbin/blkid -s LABEL -o value $devname 2>/dev/null)" = "${pers_label}" ]; then
|
||||
echo "$devname"
|
||||
return
|
||||
# Do not add any filesystem types here that might be able to
|
||||
# mount a journalled filesystem and replay the journal. Doing so
|
||||
# will cause data loss when a live CD is booted on a system
|
||||
# where filesystems are in use by hibernated operating systems.
|
||||
elif [ "$(get_fstype ${devname})" = "vfat" ]; then
|
||||
mkdir -p "${cow_backing}"
|
||||
try_mount "${devname}" "${cow_backing}" "rw"
|
||||
if [ -e "${cow_backing}/${pers_label}" ]; then
|
||||
echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
|
||||
return 0
|
||||
else
|
||||
umount ${cow_backing}
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
find_files()
|
||||
# return the first of $filenames found on vfat and ext2 devices
|
||||
# FIXME: merge with above function
|
||||
{
|
||||
filenames="${1}"
|
||||
snap_backing="/snap-backing"
|
||||
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
|
||||
for dev in $(subdevices "${sysblock}"); do
|
||||
devname=$(sys2dev "${dev}")
|
||||
devfstype="$(get_fstype ${devname})"
|
||||
if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
|
||||
mkdir -p "${snap_backing}"
|
||||
try_mount "${devname}" "${snap_backing}" "ro"
|
||||
for filename in ${filenames}; do
|
||||
if [ -e "${snap_backing}/${filename}" ]; then
|
||||
echo "${devname} ${snap_backing} ${filename}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
umount ${snap_backing}
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user