#! /bin/bash
#	$Id$
#
# Warning, this file was automatically created by the HylaFAX configure script
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1990-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# HylaFAX is a trademark of Silicon Graphics
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

#
# VERSION:	6.0.7
# DATE:		Wed, 13 Jan 2021 13:00:13 +0000
# TARGET:	x86_64-pc-linux-gnu
#

#
# faxsetup [options]
#
# This script interactively prepares and verifies 
# a HylaFAX client and/or server machine for use.
#
PATH=/bin:/usr/bin:/etc
test -d /usr/ucb  && PATH=$PATH:/usr/ucb		# Sun and others
test -d /usr/bsd  && PATH=$PATH:/usr/bsd		# Silicon Graphics
test -d /usr/5bin && PATH=/usr/5bin:$PATH:/usr/etc	# Sun and others
test -d /usr/sbin && PATH=/usr/sbin:$PATH		# 4.4BSD-derived
test -d /usr/local/bin && PATH=$PATH:/usr/local/bin	# for GNU tools

AWK=/usr/bin/awk			# awk for use below
CAT=/bin/cat			# cat command for use below
CHGRP=/bin/chgrp			# change file group for use below
CHMOD=/bin/chmod			# change file mode for use below
CHOWN=/bin/chown			# change file owner for use below
CP=/bin/cp				# cp command for use below
ECHO=/bin/echo			# echo command for use below
ENCODING=		# encoding style for uuencode/mimencode
FUSER=fuser			# fuser command to dump in setup.cache
GREP=/bin/grep			# grep command for use below
LN=/bin/ln				# ln command for use below
LN_S=-s			# ln option for creating a symbolic link
MKFIFO=/usr/bin/mkfifo			# FIFO creation program for use below
MV=/bin/mv				# move file for use below
PCL6CMD=pcl6		# pcl6 (GhostPCL) program
RMCMD=/bin/rm			# remove file for use below
SCRIPT_SH=/bin/bash		# shell for use below
SED=/bin/sed			# sed for use below
TIFF2PDF=/usr/bin/tiff2pdf		# tiff-to-pdf conversion tool
TTYCMD=/usr/bin/tty			# tty for error output

BASE64ENCODE=""	# base64encode command to dump in setup.cache
MIMENCODE=""		# mimeencode command to dump in setup.cache for old notifys
QPENCODE=""		# qpencode command to dump in setup.cache
UUENCODE=""		# uuencode command to dump in setup.cache

FAX=uucp			# identity of the fax user
SERVICES=/etc/services		# location of services database
INETDCONF=/etc/inetd.conf	# default location of inetd configuration file
ALIASES=/etc/aliases	# default location of mail aliases database file
PASSWD=/etc/passwd		# where to go for password entries
PROTOUID=uucp		# user who's uid we use for FAX user
defPROTOUID=3			# use this uid if PROTOUID doesn't exist
GROUP=/etc/group		# where to go for group entries
PROTOGID=uucp		# group who's gid we use for FAX user
defPROTOGID=10			# use this gid if PROTOGID doesn't exist

VERSION="6.0.7"		# configured version
DATE="Wed, 13 Jan 2021 13:00:13 +0000"			# data software was configured
TARGET="x86_64-pc-linux-gnu"		# configured target

PATH_AFM=/usr/share/fonts/type1/gsfonts		# directory for Adobe Font Metric files
PATH_FONTMAP=/usr/share/ghostscript/9.19/lib		# directory for FontMap files
DIR_BIN=/usr/bin			# directory for client applications
DIR_LIBDATA=/etc/hylafax		# directory for client data files
DIR_LIBEXEC=/usr/sbin		# directory where servers are located
DIR_LOCKS=/var/lock	# UUCP locking directory
DIR_MAN=/usr/share/man		# directory for manual pages
DIR_SBIN=/usr/sbin			# directory for server applications
DIR_SPOOL=/var/spool/hylafax		# top of fax spooling tree

TIFFBIN=/usr/bin		# TIFF tools
LOCKS=ascii		# UUCP lock type

PATH_GETTY=/etc/hylafax/getty-link		# pathname for getty program
PATH_SENDMAIL=/usr/lib/sendmail	# pathname for sendmail
PATH_VGETTY=/etc/hylafax/vgetty-link	# pathname for voice getty program
PATH_EGETTY=/etc/hylafax/egetty-link	# pathname for external getty program

PS=gs			# default PostScript RIP package
PATH_GSRIP=/usr/bin/gs		# pathname of Ghostscript RIP
PATH_DPSRIP=		# pathname of old IRIX DPS RIP
PATH_IMPRIP=/usr/bin/psrip		# pathname of IRIX Impressario RIP

POSIXLY_CORRECT=1; export POSIXLY_CORRECT		# disable GNU extensions

#
# Location of sysv init script
#
DIR_SYSVINIT=/etc/init.d
FAXQ_SERVER=yes
HFAXD_SERVER=yes
HFAXD_SNPP_SERVER=no

#
# These are the configuration parameters written to the
# setup.cache file and read in by all the HylaFAX scripts.
#
# We use the same names used by configure for consistency
# (but some confusion within this script).
#
VARS="SCRIPT_SH
FONTPATH		PATH_AFM
AWK
BASE64ENCODE
BIN		DIR_BIN
CAT
CHGRP
CHMOD
CHOWN
CP
DPSRIP		PATH_DPSRIP
ECHO
ENCODING
FAXQ_SERVER
FUSER
GREP
GSRIP		PATH_GSRIP
HFAXD_SERVER
HFAXD_SNPP_SERVER
IMPRIP		PATH_IMPRIP
LIBDATA		DIR_LIBDATA
LIBEXEC		DIR_LIBEXEC
LN
MANDIR		DIR_MAN
MIMENCODE
MKFIFO
MV
PATH
PATHGETTY	PATH_GETTY
PATHVGETTY	PATH_VGETTY
PATHEGETTY	PATH_EGETTY
PCL6CMD
PSPACKAGE	PS
QPENCODE
RM		RMCMD
SBIN		DIR_SBIN
SED
SENDMAIL	PATH_SENDMAIL
SPOOL		DIR_SPOOL
SYSVINIT
TIFF2PDF
TIFFBIN
TARGET
TTYCMD
UUENCODE
UUCP_LOCKDIR	DIR_LOCKS
UUCP_LOCKTYPE	LOCKS"
dumpvals()
{
    echo "$VARS" |
	while read a b; do eval c=\$${b:-$a}; echo "$a='$c'"; done
}

#
# Find the full pathname of an executable;
# supply a default if nothing is found.
#
findAppDef()
{
    app=$1; path=$2; def=$3
    case $app in
    /*) test -x $app && { echo $app; return; };;
    esac
    IFS=:
    for i in $path; do
	test -x $i/$app && { echo $i/$app; return; }
    done
    echo $def
}


#
# Error diagnostics that should go to the terminal are
# done with this interface or cat.
#
bitch()
{
    echo "$@" 1>&2
}

#
# This is the preferred interface for
# configure to terminate abnormally.
#
boom()
{
    $RM $JUNK
    # boom can be called before TMPDIR is set
    if test x$TMPDIR != x; then
	$RM -r $TMPDIR
    fi
    exit 1
}

usage()
{
    cat<<EOF
Usage: faxsetup [options] [host]
Options: [defaults in brackets after descriptions]
  -client		 setup client support
  -server		 setup server support
  -with-PARAM[=ARG]      set configuration PARAM [ARG=yes]

  -help                  print this message
  -quiet                 do not print 'Using ...' messages
  -verbose		 opposite of -quiet
EOF
}

QUIET=no
isServer=no
isClient=no

onClient()
{
    test $isClient = yes
}
onServer()
{
    test $isServer = yes
}

#
# Crack command line arguments.  We purposely
# use syntax and options that are compatible
# with GNU autoconf.
#
WITHARGS=no
ac_prev=
for ac_option
do
    if [ -n "$ac_prev" ]; then		# assign the argument to previous option
	eval "$ac_prev=\$ac_option"
	ac_prev=
	continue
    fi
    case "$ac_option" in		# collect optional argument
    -*=*)	ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'`;;
    *)		ac_optarg=;;
    esac
    case "$ac_option" in
    -with-*|--with-*)
	ac_with=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
	# Reject names that are not valid shell variable names.
	if [ -n "`echo $ac_with| sed 's/[-_a-zA-Z0-9]//g'`" ]; then
	    bitch "configure: $ac_with: invalid parameter name."
	    boom
	fi
	ac_with=`echo $ac_with| sed 's/-/_/g'`
	case "$ac_option" in
	*=*)	;;
	*)	ac_optarg=yes;;
	esac
	eval "${ac_with}='$ac_optarg'"
	WITHARGS=yes
	;;
    -client)		isClient=yes;;
    -server)		isServer=yes;;

    -quiet)		QUIET=yes;;
    -verbose)		QUIET=no;;
    -help)		usage; exit 0;;
    -*)
	bitch "faxsetup: $ac_option: invalid option; use -help for usage."
	boom
	;;
    esac
done

if [ -n "$ac_prev" ]; then
    bitch "faxsetup: missing argument to --`echo $ac_prev | sed 's/_/-/g'`"
    boom
fi

# if nothing specified on command line, default client+server
if [ $isClient = no ] && [ $isServer = no ]; then
    #
    # on debian the client configuration file is already bundled with the package
    #
    isClient=no
    isServer=yes
fi

#
# Descriptor usage:
# 1: ???
# 2: messages that should be seen even if we're in the background.
# 3: [stdout from test runs]
# 4: verbose-style messages (Using ...)
# 5: setup.cache file
#
if [ $QUIET = yes ]; then
    exec 4>/dev/null			# chuck messages
else
    exec 4>&1				# messages go to stdout
fi

Note()
{
    echo "$@" 1>&4
}

capture()
{
    (eval "set -x; $*") > /dev/null 2>&1
    return
}  

Note ""
Note "Setup program for HylaFAX (tm) $VERSION."
Note ""
Note "Created for $TARGET on $DATE."
Note ""

CPU=`expr $TARGET : '\([^\-]*\)'` || CPU=unknown
VENDOR=`expr $TARGET : '[^\-]*-\([^\-]*\)'` || VENDOR=unknown
OS=`expr $TARGET : '[^\-]*-[^\-]*-\([a-zA-Z]*\).*'` || OS=unknown
RELEASE=`(uname -r) 2>/dev/null` || RELEASE=unknown

#
# Read in any site, target, vendor, os, or os-release
# specific setup work.  Note that we read stuff here
# so that configuration parameters can be altered.  We
# use some pre-defined function names below to provide
# hooks for other actions.
#

#
# Hooks for additional client+server checks
#
otherBasicServerChecks()
{
    true
}
otherBasicClientChecks()
{
    true
}
#
# Hook for adding stuff to setup.modem
#
dumpOtherModemFuncs()
{
    true
}

#
# Figure out which brand of echo we have and define prompt
# and printf shell functions accordingly.  Note that we
# assume that if the System V-style echo is not present,
# then the BSD printf program is available.  These functions
# are defined here so that they can be tailored on a per-site,
# etc. basis.
#
if [ `echo foo\\\c`@ = "foo@" ]; then
    # System V-style echo supports \r
    # and \c which is all that we need
    prompt()
    {
       echo "$* \\c"
    }
    printf()
    {
       echo "$*\\c"
    }
    dumpPromptFuncs()
    {
	cat<<-'EOF'
	prompt()
	{
	   echo "$* \\c"
	}
	printf()
	{
	   echo "$*\\c"
	}
	EOF
    }
elif [ "`echo -n foo`@" = "foo@" ]; then
    # BSD-style echo; use echo -n to get
    # a line without the trailing newline
    prompt()
    {
       echo -n "$* "
    }
    dumpPromptFuncs()
    {
	cat<<-'EOF'
	prompt()
	{
	   echo -n "$* "
	}
	EOF
    }
else
    # something else; do without
    prompt()
    {
	echo "$*"
    }
    dumpPromptFuncs()
    {
	cat<<-'EOF'
	prompt()
	{
	    echo "$*"
	}
	EOF
    }
fi

if onServer; then
    #
    # Setup the password file manipulation functions according
    # to whether we have System-V style support through the
    # passmgmt program, or BSD style support through the chpass
    # program, or for SCO boxes through pwconv, or SVR4 style support
    # through useradd. If none are found, we setup functions that
    # will cause us to abort if we need to munge the password file.
    #
    # NB: some systems override these function definitions through
    #     per-os faxsetup files
    #
    if [ -f /bin/passmgmt ] || [ -f /usr/sbin/passmgmt ]; then
	addPasswd()
	{
	    passmgmt -o -a -c 'Facsimile Agent' -h $4 -u $2 -g $3 $1
	}
	deletePasswd()
	{
	    passmgmt -d $1
	}
	modifyPasswd()
	{
	    passmgmt -m -h $4 -u $2 -o -g $3 $1
	}
	lockPasswd()
	{
	    passwd -l $1
	}
    elif [ -f /usr/bin/chpass ]; then
	addPasswd()
	{
	    chpass -a "$1:*:$2:$3::0:0:Facsimile Agent:$4:"
	}
	modifyPasswd()
	{
	    chpass -a "$1:*:$2:$3::0:0:Facsimile Agent:$4:"
	}
	lockPasswd()
	{
	    return 0				# entries are always locked
	}
    elif [ -f /etc/pwconv ]; then	# could be a SCO box
	addPasswd()
	{
	    echo "${1}:NOLOGIN:${2}:${3}:Facsimile Agent:${4}:/bin/false" >> ${PASSWD}
	    /etc/pwconv
	}
	lockPasswd()
	{
	    return 0				# entries are always locked
	}
	modifyPasswd()
	{
	    OLD_HOME=`grep "^${1}:" ${PASSWD} | awk -F: '{print $6}'`
	    ed - $PASSWD <<_EOF
g~^$1:~s~${OLD_HOME}~$4~
w
q
_EOF
	}
    elif [ -f /usr/sbin/useradd ] || [ -f /etc/useradd ]; then
	addPasswd()
	{
	    useradd -c 'Facsimile Agent' -d $4 -u $2 -o -g $3 $1
	}
	deletePasswd()
	{
	    userdel $1
	}
	modifyPasswd()
	{
	    usermod -m -d $4 -u $2 -o -g $3 $1
	}
	lockPasswd()
	{
	    passwd -l $1
	}
    else
	addPasswd()
	{
	    cat >&2 <<EOF

FATAL ERROR: I don't know how to add a passwd entry!

You will have to create the password entry manually using the following info:

Login Name: $1
Password:   *
Uid:        $2
Gid:        $3
Full Name:  Facsimile Agent
Home Dir:   $4

EOF
	    boom
	}
	modifyPasswd()
	{
	    cat >&2 <<EOF

FATAL ERROR: I don't know how to modify a passwd entry!

You will have to update the password entry manually using the following info:

Login Name: $1
Password:   *
Uid:        $2
Gid:        $3
Full Name:  Facsimile Agent
Home Dir:   $4

EOF
	    boom
	}
    fi

    #
    # Functions required by faxaddmodem.
    #
    case $TARGET in
    *-sunos*|*-linux*|*-ultrix*|*-hpux*|*-freebsd*|*-netbsd*|*-sysv5SCO_SV6*)
	dumpTTYFuncs()
	{
	    cat<<'EOF'
	    ttyPort()
	    {
		expr $1 : 'tty\(.*\)'
	    }
	    ttyLocks()
	    {
		echo $UUCP_LOCKDIR/LCK..`expr /$1 : '.*/\(.*\)'`
	    }
	    ttyAliases()
	    {
		if [ -z "`echo $1 | grep "^/"`" ]; then printf "/dev/"; fi
		echo $1
	    }
	    ttyDev()
	    {
		if [ -z "`echo $1 | grep "^/"`" ]; then printf "/dev/"; fi
		echo $1
	    }
	    checkPort()
	    {
		 return
	    }
EOF
	}
	;;
    *-svr4*|*-sysv4*|*-sysv5*|*-solaris*)
	dumpTTYFuncs()
	{
	    cat<<'EOF'
	    ttyPort()
	    {
		port=`expr $1 : 'term\/\(.*\)' \| $1`		# Usual
		port=`expr $port : 'cua\/\(.*\)' \| $port`	# Solaris
		port=`expr $port : 'tty\(.*\)' \| $port`	# Old-style
		echo $port
	    }
	    ttyLocks()
	    {
		devs=$1
		locks="$UUCP_LOCKDIR/`$SVR4UULCKN /dev/$devs`" || {
		    echo "Sorry, I cannot determine the UUCP lock file name for $devs"
		    exit 1
		}
		echo $locks
	    }
	    ttyAliases()
	    {
		if [ -z "`echo $1 | grep "^/"`" ]; then printf "/dev/"; fi
		echo $1
	    }
	    ttyDev()
	    {
		if [ -z "`echo $1 | grep "^/"`" ]; then printf "/dev/"; fi
		echo $1
	    }
	    checkPort()
	    {
		 return
	    }
EOF
	}
	;;
    *)
	dumpTTYFuncs()
	{
	    Note ""
	    Note "Beware, I am guessing the tty naming conventions for your system."
	    cat<<'EOF'
	    ttyPort()
	    {
		expr $1 : 'tty\(.*\)'
	    }
	    ttyLocks()
	    {
		echo $UUCP_LOCKDIR/LCK..`expr /$1 : '.*/\(.*\)'`
	    }
	    ttyAliases()
	    {
		if [ -z "`echo $1 | grep "^/"`" ]; then printf "/dev/"; fi
		echo                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       