2008-04-05 17:30:06 +08:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Copyright 2008 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Cygwin.
|
|
|
|
#
|
|
|
|
# This software is a copyrighted work licensed under the terms of the
|
|
|
|
# Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
export PATH="/bin:$PATH"
|
|
|
|
|
2008-04-09 00:12:24 +08:00
|
|
|
SYSCONFDIR=/etc
|
|
|
|
FSTAB="${SYSCONFDIR}/fstab"
|
|
|
|
FSTABDIR="${SYSCONFDIR}/fstab.d"
|
|
|
|
|
2008-04-05 17:30:06 +08:00
|
|
|
DEVDIR=/dev
|
|
|
|
|
2008-04-08 00:37:20 +08:00
|
|
|
print_flags ()
|
|
|
|
{
|
|
|
|
(( $1 & 0x0002 )) && echo -n "binary" || echo -n "text"
|
|
|
|
(( $1 & 0x0010 )) && echo -n ",exec"
|
|
|
|
(( $1 & 0x0040 )) && echo -n ",cygexec"
|
|
|
|
(( $1 & 0x0100 )) && echo -n ",notexec"
|
|
|
|
(( $1 & 0x0800 )) && echo -n ",managed"
|
|
|
|
}
|
|
|
|
|
2008-04-05 17:30:06 +08:00
|
|
|
# Create fstab file if it doesn't exist.
|
2008-04-09 00:12:24 +08:00
|
|
|
if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
|
2008-04-05 17:30:06 +08:00
|
|
|
then
|
|
|
|
# Try to move
|
2008-04-09 00:12:24 +08:00
|
|
|
mv -f "${FSTAB}" "${FSTAB}.orig"
|
|
|
|
if [ -e "${FSTAB}" -a ! -f "${FSTAB}" ]
|
2008-04-05 17:30:06 +08:00
|
|
|
then
|
|
|
|
echo
|
2008-04-09 00:12:24 +08:00
|
|
|
echo "${FSTAB} is existant but not a file."
|
2008-04-05 17:30:06 +08:00
|
|
|
echo "Since this file is specifying the mount points, this might"
|
|
|
|
echo "result in unexpected trouble. Please fix that manually."
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-04-09 00:12:24 +08:00
|
|
|
if [ ! -e "${FSTAB}" ]
|
2008-04-05 17:30:06 +08:00
|
|
|
then
|
2008-04-07 22:09:22 +08:00
|
|
|
# Set IFS to just a LF
|
|
|
|
_OLD_IFS="$IFS"
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
for line in $(mount)
|
|
|
|
do
|
|
|
|
[[ "$line" =~ ([^ ]*)\ on\ ([^ ]*)\ type\ ([^ ]*)\ .* ]]
|
|
|
|
if [ "${BASH_REMATCH[2]}" = "/" ]
|
|
|
|
then
|
|
|
|
CYGROOT="${BASH_REMATCH[1]}"
|
|
|
|
FS_TYPE="${BASH_REMATCH[3]}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2008-04-09 00:12:24 +08:00
|
|
|
cat > ${FSTAB} << EOF
|
2008-04-05 17:30:06 +08:00
|
|
|
# The file fstab contains descriptive information about the various file
|
|
|
|
# systems. fstab is only read by programs, and not written; it is the
|
|
|
|
# duty of the system administrator to properly create and maintain this
|
|
|
|
# file. Each filesystem is described on a separate line; fields on each
|
|
|
|
# line are separated by tabs or spaces. Lines starting with '#' are com-
|
|
|
|
# ments.
|
|
|
|
#
|
|
|
|
# The first field, (fs_spec), describes the block special device or
|
|
|
|
# remote filesystem to be mounted. On Cygwin, this is the native Windows
|
|
|
|
# path which the mount point links in. As path separator you MUST use a
|
|
|
|
# slash. Usage of a backslash might lead to unexpected results. UNC
|
|
|
|
# paths (using slashes, not backslashes) are allowed. If the path
|
|
|
|
# contains spaces these can be escaped as '\040'.
|
|
|
|
#
|
|
|
|
# The second field, (fs_file), describes the mount point for the filesys-
|
|
|
|
# tem. If the name of the mount point contains spaces these can be
|
|
|
|
# escaped as '\040'.
|
|
|
|
#
|
|
|
|
# The third field, (fs_vfstype), describes the type of the filesystem.
|
|
|
|
# Cygwin supports any string here, since the file system type is usually
|
|
|
|
# not evaluated. The noticable exception is the file system type
|
|
|
|
# cygdrive. This type is used to set the cygdrive prefix. See the
|
|
|
|
# user's guide for more information about the cygdrive prefix.
|
|
|
|
#
|
|
|
|
# The fourth field, (fs_mntops), describes the mount options associated
|
|
|
|
# with the filesystem. It is formatted as a comma separated list of
|
|
|
|
# options. It contains at least the type of mount (binary or text) plus
|
|
|
|
# any additional options appropriate to the filesystem type. Recognized
|
2008-04-06 17:56:42 +08:00
|
|
|
# options are binary, text, nouser, user, exec, notexec, cygexec, nosuid,
|
2008-04-05 17:30:06 +08:00
|
|
|
# managed. For a description of the options see the user's guide. Note
|
2008-04-06 17:56:42 +08:00
|
|
|
# that nouser mount points are not overridable by a later call to
|
2008-04-05 17:30:06 +08:00
|
|
|
# mount(2). This is only possible for user mount points. Mount points
|
2008-04-06 17:56:42 +08:00
|
|
|
# are by default nouser mount points, unless you specify the option user.
|
2008-04-05 17:30:06 +08:00
|
|
|
#
|
|
|
|
# The fifth (fs_freq) and sixth (fs_passno) field are ignored. They are
|
|
|
|
# so far only specified to keep a Linux-like fstab file layout.
|
|
|
|
#
|
|
|
|
# Note that you don't have to specify an fstab entry for the root dir,
|
|
|
|
# unless you want to have the root dir pointing to somewhere entirely
|
|
|
|
# different (hopefully you know what you're doing), or if you want to
|
|
|
|
# mount the root dir with special options (for instance, as text mount).
|
|
|
|
#
|
|
|
|
# Example entries:
|
|
|
|
#
|
|
|
|
# Just a normal mount point:
|
|
|
|
#
|
|
|
|
# c:/foo /bar fat32 binary 0 0
|
|
|
|
#
|
|
|
|
# A mount point for a managed, textmode mount:
|
|
|
|
#
|
|
|
|
# C:/foo /bar/baz ntfs text,managed 0 0
|
|
|
|
#
|
|
|
|
# A mount point for a Windows directory with spaces in it:
|
|
|
|
#
|
|
|
|
# C:/Documents\040and\040Settings /docs ext3 binary 0 0
|
|
|
|
#
|
|
|
|
# A mount point for a remote directory:
|
|
|
|
#
|
|
|
|
# //server/share/subdir /srv/subdir smbfs binary 0 0
|
|
|
|
#
|
|
|
|
# This is just a comment:
|
|
|
|
#
|
|
|
|
# # This is just a comment
|
|
|
|
#
|
|
|
|
# Set the cygdrive prefix to /mnt:
|
|
|
|
#
|
|
|
|
# none /mnt cygdrive binary 0 0
|
|
|
|
#
|
|
|
|
|
|
|
|
EOF
|
2008-04-07 22:09:22 +08:00
|
|
|
|
2008-04-21 22:00:24 +08:00
|
|
|
usr_bin=""
|
|
|
|
usr_lib=""
|
|
|
|
key='\HKLM\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2'
|
|
|
|
for subkey in $(regtool -q list "$key")
|
|
|
|
do
|
|
|
|
if [[ "$subkey" =~ /.* ]]
|
|
|
|
then
|
|
|
|
[ "$subkey" = "/usr/bin" ] && usr_bin="1"
|
|
|
|
[ "$subkey" = "/usr/lib" ] && usr_lib="1"
|
|
|
|
nat=$(regtool -q get "$key\\$subkey\native")
|
|
|
|
nat="${nat//\\//}"
|
|
|
|
nat="${nat// /\\040}"
|
|
|
|
psx="${subkey// /\\040}"
|
|
|
|
flags=$(regtool -q get "$key\\$subkey\flags")
|
|
|
|
echo -n "${nat} ${psx} some_fs "
|
|
|
|
print_flags $flags
|
|
|
|
echo " 0 0"
|
|
|
|
fi >> ${FSTAB}
|
|
|
|
done
|
|
|
|
[ -z "$usr_bin" ] &&
|
2008-04-09 00:12:24 +08:00
|
|
|
echo "${CYGROOT//\\//}/bin /usr/bin ${FS_TYPE} binary 0 0" >> ${FSTAB}
|
2008-04-21 22:00:24 +08:00
|
|
|
[ -z "$usr_lib" ] &&
|
2008-04-09 00:12:24 +08:00
|
|
|
echo "${CYGROOT//\\//}/lib /usr/lib ${FS_TYPE} binary 0 0" >> ${FSTAB}
|
2008-04-07 22:09:22 +08:00
|
|
|
|
2008-04-21 22:00:24 +08:00
|
|
|
cygd=""
|
|
|
|
prefix=$(regtool -q get "$key\cygdrive prefix")
|
|
|
|
flags=$(regtool -q get "$key\cygdrive flags")
|
|
|
|
[ -z "$flags" ] && flags=2
|
|
|
|
# Don't take system and cygdrive flags into account when testing
|
|
|
|
if [ -n "$prefix" \
|
|
|
|
-a \( "$prefix" != "/cygdrive" -o "$(( $flags & ~0x28 ))" -ne 2 \) ]
|
|
|
|
then
|
|
|
|
cygd="1"
|
|
|
|
psx="${prefix// /\\040}"
|
|
|
|
echo -n "none ${psx} cygdrive "
|
|
|
|
print_flags $flags
|
|
|
|
echo ",user 0 0"
|
|
|
|
fi >> ${FSTAB}
|
2008-04-07 22:09:22 +08:00
|
|
|
|
2008-04-21 22:00:24 +08:00
|
|
|
if [ -z "$cygd" ]
|
|
|
|
then
|
2008-04-09 00:12:24 +08:00
|
|
|
echo "# This is default anyway:" >> ${FSTAB}
|
|
|
|
echo "# none /cygdrive cygdrive binary,user 0 0" >> ${FSTAB}
|
2008-04-21 22:00:24 +08:00
|
|
|
fi
|
2008-04-07 22:09:22 +08:00
|
|
|
IFS="$_OLD_IFS"
|
2008-04-05 17:30:06 +08:00
|
|
|
fi
|
|
|
|
|
2008-04-09 00:12:24 +08:00
|
|
|
# Check for ${FSTABDIR} directory
|
|
|
|
|
|
|
|
if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
|
|
|
|
then
|
|
|
|
# No mercy. Try to remove.
|
|
|
|
rm -f "${FSTABDIR}"
|
|
|
|
if [ -e "${FSTABDIR}" -a ! -d "${FSTABDIR}" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "${FSTABDIR} is existant but not a directory."
|
|
|
|
echo "Please fix that manually."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create it if necessary
|
|
|
|
|
|
|
|
if [ ! -e "${FSTABDIR}" ]
|
|
|
|
then
|
|
|
|
mkdir -m 1777 "${FSTABDIR}"
|
|
|
|
if [ ! -e "${FSTABDIR}" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "Creating ${FSTABDIR} directory failed."
|
|
|
|
echo "Please fix that manually."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-04-05 17:30:06 +08:00
|
|
|
# Check for ${DEVDIR} directory
|
|
|
|
|
|
|
|
if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]
|
|
|
|
then
|
|
|
|
# No mercy. Try to remove.
|
|
|
|
rm -f "${DEVDIR}"
|
|
|
|
if [ -e "${DEVDIR}" -a ! -d "${DEVDIR}" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "${DEVDIR} is existant but not a directory."
|
|
|
|
echo "Please fix that manually, otherwise you WILL get problems."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create it if necessary
|
|
|
|
|
|
|
|
if [ ! -e "${DEVDIR}" ]
|
|
|
|
then
|
|
|
|
mkdir -m 755 "${DEVDIR}"
|
|
|
|
if [ ! -e "${DEVDIR}" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "Creating ${DEVDIR} directory failed."
|
|
|
|
echo "Please fix that manually, otherwise you WILL get problems."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
setfacl -m u:system:rwx "${DEVDIR}"
|
|
|
|
|
|
|
|
# Check for ${DEVDIR}/shm directory (for POSIX semaphores and POSIX shared mem)
|
|
|
|
|
|
|
|
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
|
|
|
|
then
|
|
|
|
# No mercy. Try to remove.
|
|
|
|
rm -f "${DEVDIR}/shm"
|
|
|
|
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "${DEVDIR}/shm is existant but not a directory."
|
|
|
|
echo "POSIX semaphores and POSIX shared memory will not work"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create it if necessary
|
|
|
|
|
|
|
|
if [ ! -e "${DEVDIR}/shm" ]
|
|
|
|
then
|
|
|
|
mkdir -m 1777 "${DEVDIR}/shm"
|
|
|
|
if [ ! -e "${DEVDIR}/shm" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "Creating ${DEVDIR}/shm directory failed."
|
|
|
|
echo "POSIX semaphores and POSIX shared memory will not work"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for ${DEVDIR}/mqueue directory (for POSIX message queues)
|
|
|
|
|
|
|
|
if [ -e "${DEVDIR}/mqueue" -a ! -d "${DEVDIR}/mqueue" ]
|
|
|
|
then
|
|
|
|
# No mercy. Try to remove.
|
|
|
|
rm -f "${DEVDIR}/shm"
|
|
|
|
if [ -e "${DEVDIR}/shm" -a ! -d "${DEVDIR}/shm" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "${DEVDIR}/mqueue is existant but not a directory."
|
|
|
|
echo "POSIX message queues will not work"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create it if necessary
|
|
|
|
|
|
|
|
if [ ! -e "${DEVDIR}/mqueue" ]
|
|
|
|
then
|
|
|
|
mkdir -m 1777 "${DEVDIR}/mqueue"
|
|
|
|
if [ ! -e "${DEVDIR}/mqueue" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "Creating ${DEVDIR}/mqueue directory failed."
|
|
|
|
echo "POSIX message queues will not work"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
fi
|