#!/bin/sh -fu
# add any extra filesystems (currently excluding evms, md block devices);
# this implementation counts on a file created by
# installer-scripts-remount-stage2 >= 0.4-alt1
# FIXME: needs rewrite according to http://bugzilla.altlinux.org/29005

[ -s /tmp/blkid.dm ] || exit 0

a= . install2-init-functions
. /etc/sysconfig/i18n

# current alterator-vm always yields UUIDs in fstab
( cut -f1 < "$destdir/etc/fstab" | grep ^UUID \
    | sed 's/UUID=\([^ ]*\)/UUID="\1"/'
  echo -e "\\<swap\\>\n\\<mdraid\\>"
  echo -e "\\<swsuspend\\>"
  echo -e "LVM2_member"
  echo -e "linux_raid_member"
  echo -e "crypto_LUKS"
  echo -e "/dev/dm-\n/dev/evms/\n/dev/md[0-9]"
  echo -e "/boot/efi"
) > /tmp/fstab_excludes

# created by installer itself
[ ! -s /tmp/removable ] || cat /tmp/removable >> /tmp/fstab_excludes

# FIXME: cyrillic-slated, see also http://bugzilla.altlinux.org/11952
# FIXME: /mnt vs /media?
grep '\<UUID=' /tmp/blkid.dm \
| grep -vE -f /tmp/fstab_excludes \
| sed 's#/dev/mapper/\(\S*\):.*[[:blank:]]UUID="\([0-9a-zA-Z\-]*\)".*[[:blank:]]TYPE="\([0-9a-z]*\)".*#UUID=\2\t/mnt/\1\t\3 defaults 0 0#' \
| sed -e "s#vfat defaults#vfat showexec,quiet,codepage=866,iocharset=utf8,umask=0#" \
      -e "s#ntfs defaults#ntfs-3g ${LANG:+locale=$LANG,}nofail,comment=x-gvfs-show,dmask=0,fmask=0111#" \
| tee -a "$destdir/etc/fstab" \
| cut -f2 \
| sed -n 's,^/mnt,/mnt/destination&,p' \
| xargs -r -n 1 mkdir -p ||:
