#! /bin/sh # CADP (CONSTRUCTION AND ANALYSIS OF DISTRIBUTED PROCESSES) # http://cadp.inria.fr - Copyright (C) INRIA 2002-2018 # cadp_cygwin.com version 2.72 -- date 2022/06/02 16:28:08 -- Hubert Garavel # ---------------------------------------------------------------------------- # IMPORTANT: This shell-script is designed to be reentrant, i.e., it can # be invoked several times without problem. This invariant should be respected # in future evolutions # ---------------------------------------------------------------------------- # make sure that $PATH is properly set PATH="/bin:/usr/bin:$PATH" export PATH # ---------------------------------------------------------------------------- # make sure that this shell is run on a Windows + Cygwin machine if [ ! -x /bin/cygpath.exe ] then echo "*** This machine does not seem to be running Windows and Cygwin" echo "==> Stop right now to avoid corrupting the operating system" exit 1 fi # ---------------------------------------------------------------------------- # make sure that this shell is executed with admininistrator privileges # see https://superuser.com/questions/660191/how-to-check-if-cygwin-mintty-bash-is-run-as-administrator # note: this code fragment also exists in the "installator" shell script id -G | grep -qE '\<(114|544)\>' if [ $? != 0 ] then echo "*** This script was not launched with administrator privileges" echo "==> Open a new terminal window by right-clicking on the Cygwin" echo " Terminal icon to select \`\`Run as Administrator'' and" echo " relaunch this script from this new window" exit 1 fi # ---------------------------------------------------------------------------- CYGWIN_ROOT=`cygpath -w /` if [ "$CYGWIN_ROOT" != "C:\\" ] then echo " The Cygwin software has been installed in $CYGWIN_ROOT" fi # ---------------------------------------------------------------------------- # phase 1: replace /bin/sh.exe (which used to be bugged) with /bin/bash.exe # Technical explanations: in former versions of Cygwin (until 2003) the "sh" # had several problems, which are listed in the source code of the "tst" # command of CADP (see problems #1 and #2). For this reason, we used to # replace "/bin/sh.exe" by "/bin/bash.exe", which is much more robust, # since it is the default user shell (the one used everytime one opens a # Cygwin window). # # In more recent versions of Cygwin (e.g., 1.5.4, 1.5.5, etc.), the "sh" # command no longer seems to have the aforementioned problems. But it might # have other ones that we don't know yet. For safety reasons, we continue to # replace "/bin/sh.exe" by "/bin/bash.exe", although it might not be necessary. # # In more recent versions of Cygwin (e.g., 1.5.23), the "sh" and "bash" # commands seem to be identical. # # In more recent versions of Cygwin (e.g., from 1.7.1 to 1.7.18), the "sh" # and "bash" binaries have the same size, same version number, but differ in # a few bytes : this means that the default "/bin/sh" is a "bash" variant that # we kept unchanged, as it seems to work correctly with CADP. # # But, in 2012, new problems were reported, which arise in part from the # difference between "sh" and "bash". Because (probably) of a change in # mounting filesystems (which now seem to be mounted as "binary" rather than # "unix"), setting the Cygwin-specific option "igncr" becomes mandatory to # continue execute CADP shells. Some versions of /bin/sh.exe (before version # 4.1.10(4)?) do not accept "set -o igncr" (unknown option). There have been # various messages about this issue, e.g. # http://cygwin.com/ml/cygwin/2011-04/msg00331.html # and # http://osdir.com/ml/bug-bash-gnu/2011-10/msg00036.html # On the contrary, /bin/bash.exe is designed to handle the "igncr" option for # Cygwin. Therefore, replacing "sh" by "bash" is either mandatory or probably # harmless. Anyway, there is no much interest in keeping /bin/sh.exe if it # only slightly differs from /bin/bash.exe. cmp -s /bin/bash.exe /bin/sh.exe if [ $? -ne 0 ] then # /bin/bash.exe et /bin/sh.exe are different. We archive # sh.exe (since Windows 7, one must use "cp" instead of "mv" # so that a valid "sh.exe" remains available at any time) cp -p /bin/sh.exe /bin/sh.exe.ORIG # replace "sh" with "bash" cp -p /bin/bash.exe /bin/sh.exe fi # ---------------------------------------------------------------------------- # phase 2: determine whether /bin/bash.exe accepts the 'igncr' option # Technical explanations: with recent versions of the Cygwin bash, one needs # to set the 'igncr' option, otherwise the '\r' characters that may occur # in shell-scripts will not be handled properly. More details can be found in # http://cygwin.com/ml/cygwin-announce/2010-08/msg00015.html # We consider that bash will accept 'igcr' if its version number is greater or # equal than 3.2.9(10). Notice that this option might have been supported in # earlier versions, possibly 3.2.3-5, but this is no longer important. MAJOR="`/bin/bash --version | head -1 | sed -e 's/[^0-9]*\([0-9.]*\).*/\1/'`" MINOR="`/bin/bash --version | head -1 | sed -e 's/[^(]*(\([0-9]*\)).*/\1/'`" # for bash 3.2.9(10), $MAJOR = "3.2.9" and $MINOR = 10 # for bash 4.1.10(4), $MAJOR = "4.1.10" and $MINOR = 4 case "$MAJOR" in [012].* | 3.[01].* | 3.0[01].* | 3.2.[012345678].* | 3.2.0[012345678].*) # $MAJOR is less than 3.2.9: nothing done BASH_ACCEPTS_IGNCR=0 ;; 3.2.9 ) if [ "$MINOR" -le 9 ] then # $MINOR is less or equal than 9: nothing done BASH_ACCEPTS_IGNCR=0 else # $MINOR is greater than 10 BASH_ACCEPTS_IGNCR=1 fi ;; * ) BASH_ACCEPTS_IGNCR=1 ;; esac # ---------------------------------------------------------------------------- # phase 3: modify /etc/profile for recent versions of bash # For long, CADP installation procedure has addressed the problem by setting # the 'igncr' option in the /Cygwin.bat script that has been used to launch # Cygwin windows. This is no longer sufficient because, in recent versions of # Cygwin, "/Cygwin.bat" is bypassed, as Cygwin windows are most of the time # launched by a "Cygwin Terminal" icon, which invokes the following command # "C:\bin\mintty.exe -i /Cygwin-Terminal.ico -". # To position the 'igncr' option for all users and for all manners of opening # windows, the best solution seems to add it in "/etc/profile". This will # only work if /bin/sh.exe handles the 'igncr' option, i.e., if it has been # replaced by /bin/bash.exe (see phase 1 above). if [ "$BASH_ACCEPTS_IGNCR" -eq 1 ] then if [ ! -f /etc/profile ] then echo "*** File \`\`/etc/profile'' does not exist and cannot be updated" echo "==> Please, notify cadp@inria.fr" exit 1 fi # check whether /etc/profile has already been patched grep -s '^set -o igncr ; export SHELLOPTS$' /etc/profile > /dev/null 2> /dev/null if [ $? -ne 0 ] then # /etc/profile has not been patched yet; let's do it cp -p /etc/profile /etc/profile.ORIG cat >> /etc/profile << EOF # added for CADP by the cadp_cygwin.com shell-script set -o igncr ; export SHELLOPTS EOF fi fi # ---------------------------------------------------------------------------- # phase 4: if Cygwin was not installed in C:/, create Windows-compatible # symbolic links to the base directories of Cygwin: /bin, /dev, etc. if [ "$CYGWIN_ROOT" != "C:\\" ] then for DIR in bin dev etc home lib sbin tmp usr var do # we want to create a Windows link C:\$DIR -> $CYGWIN_ROOT\$DIR if [ -L "C:\\$DIR" ] then # a Windows symbolic link already exists if [ ! "C:\\$DIR" -ef "$CYGWIN_ROOT\\$DIR" ] then # the symbolic link does not point to the # expected directory echo "*** Symbolic link \`\`C:\\$DIR'' is not a link to \`\`$CYGWIN_ROOT\\$DIR''" echo "==> Please, remove \`\`C:\\$DIR'' and rerun this script" exit 1 fi elif [ -e "C:\\$DIR" ] then # a file (or directory, socket, etc.) that is not # a symbolic link already exists, preventing the # creation of a symbolic link echo "*** Symbolic link \`\`C:\\$DIR -> $CYGWIN_ROOT\\$DIR'' cannot be created because \`\`C:\\$DIR'' already exists" echo "==> Please remove or rename \`\`C:\\$DIR'' and rerun this script" exit 1 else cmd.exe /c mklink /d "C:\\$DIR" "$CYGWIN_ROOT\\$DIR" > /dev/null fi done fi # ---------------------------------------------------------------------------- # phase 5: leave a mark to indicate that this script was successfully applied mkdir -p /etc/setup echo "cadp_cygwin.com 2.72 -- `uname -s` `uname -r` -- `date`" >> /etc/setup/cadp_cygwin # ---------------------------------------------------------------------------- exit 0