#! /bin/bash

# Copyright (C) 2006,2009 Thomas Lange <lange@informatik.uni-koeln.de>
#
# 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.

# create entries for removable media in fstab and directories in /media

if [ "$CONVERT" = "true" ] ; then
    exit 0
fi

[ -b "$target/dev/fd0" ] && ainsl /etc/fstab "/dev/fd0  /media/floppy  auto  users,noauto 0 0"

cdromlist() {
    [ -f /proc/sys/dev/cdrom/info ] || return
    devs=$(grep 'drive name:' /proc/sys/dev/cdrom/info | cut -d ":" -f 2)
    for d in $devs; do
        echo "$d"
    done
}

fstabline () {
    line=$(printf "%-15s %-15s %-7s %-15s %-7s %s\n" "$1" "$2" "$3" "$4" "$5" "$6")
    ainsl /etc/fstab "$line"
}

i=0
for cdrom in $(cdromlist | tac); do
    [ "$i" -eq 0 ] && ln -sfn cdrom0 "$target/media/cdrom"
    mkdir -p "$target/media/cdrom$i"
    fstabline "/dev/$cdrom /media/cdrom$i udf,iso9660 ro,user,noauto 0 0"
    i=$((i + 1))
done
