74ed527e2e85f76398076ec800dcb3c1e6f94eaf
max
  Wed Apr 30 12:32:56 2025 -0700
fixing gbic script again for normal linux installations

diff --git src/product/installer/browserSetup.sh src/product/installer/browserSetup.sh
old mode 100755
new mode 100644
index 5c8c2abaf54..ea76d776ada
--- src/product/installer/browserSetup.sh
+++ src/product/installer/browserSetup.sh
@@ -1435,30 +1435,31 @@
        brew update
    fi
    echo2 Installing homebrew packages libpng, openssl, mariadb, git
    brew install libpng openssl mariadb git freetype
 
    echo2 Allowing write access for all on Apple\'s Apache htdocs/cgi-bin directories.
    echo2 The chmod command requires sudo - please enter the admin password now:
    sudo chmod a+rw /Library/WebServer/CGI-Executables
    sudo chmod a+rw /Library/WebServer/Documents
 
    # create symlinks to Apple's paths so all our normal makefiles work
    if [ ! -e /usr/local/apache ]; then
       echo2 Creating /usr/local/apache to fill with symlinks later
       sudo mkdir -p /usr/local/apache
       sudo chmod a+rw /usr/local/apache
+      touch "$APACHEDIR"/.madeByBrowserBuild
    fi
 
    if [ ! -e /usr/local/apache/cgi-bin ]; then
       echo2 Creating symlink /usr/local/apache/cgi-bin to /Library/WebServer/CGI-Executables
       sudo ln -s /Library/WebServer/CGI-Executables /usr/local/apache/cgi-bin
    fi
    if [ ! -e /usr/local/apache/htdocs ]; then
       echo2 Creating symlink /usr/local/apache/htdocs to /Library/WebServer/Documents
       sudo ln -s /Library/WebServer/Documents/ /usr/local/apache/htdocs 
    fi
 
     if [[ ! -d /usr/local/apache/trash ]]; then
         mkdir -p /usr/local/apache/trash
         sudo chmod a+rwx /usr/local/apache/trash
         # cgis use ../trash to find the trash directory, but we have a symlink here
@@ -1484,30 +1485,35 @@
 }
 
 # install gcc, make etc so we can build the tree on linux
 function setupBuildLinux ()
 {
    echo2 Installing required linux packages from repositories: Git, GCC, G++, Mysql-client-libs, uuid, etc
    waitKey
    if [[ "$DIST" == "debian" ]]; then
       apt-get --assume-yes $APTERR install make git gcc g++ libpng-dev libmysqlclient-dev uuid-dev libfreetype-dev libbz2-dev
    elif [[ "$DIST" == "redhat" ]]; then
       yum install -y git vim gcc gcc-c++ make libpng-devel libuuid-devel freetype-devel
    else 
       echo Error: Cannot identify linux distribution
       exit 100
    fi
+   # the build target cgi-bin requires that these directories exist
+   mkdir -p $HTDOCDIR $CGIBINDIR
+   # leave a flag file so the script knows later that this directory did not exist and we made it
+   # and it is safe to write into it
+   touch "$APACHEDIR"/.madeByBrowserBuild
 }
 
 # set this machine for browser development: install required tools, clone the tree, build it
 function buildTree () 
 {
    if [[ "$DIST" == "OSX" ]]; then
        setupBuildOsx
    else
        setupBuildLinux
    fi
 
    if [ ! -e ~/kent ]; then
       echo2 Cloning kent repo into ~/kent using git with --depth=1
       echo2 Branch is: \"beta\" = our current release, beta = testing
       waitKey
@@ -1547,35 +1553,39 @@
     echo "Your distribution's package manager will be used for this."
     echo If MariaDB is not installed yet, it will be installed, secured and a root password defined.
     echo The MariaDB root password will be written into root\'s \~/.my.cnf
     echo
     echo This script will also deactivate SELinux if active and open port 80/http.
     waitKey
 
     # -----  OS - SPECIFIC part -----
     if [ ! -f $COMPLETEFLAG ]; then
        if [[ "$DIST" == "OSX" ]]; then
  	  echo2 OSX: build the CGIs from scratch using clang, brew and git
           buildTree
        elif [[ "$MACH" == "aarch64" ]]; then
           echo2 Linux, but ARM CPU: Need to build CGIs and htdocs locally from source using gcc, make and git
           buildTree
-       elif [[ "$DIST" == "debian" ]]; then
+       fi
+
+       # (For OSX, the buildTree step above includes the installation of Apache/MariaDB)
+       if [[ "$DIST" == "debian" ]]; then
           installDebian
        elif [[ "$DIST" == "redhat" ]]; then
           installRedhat
        fi
+
     fi
     # OS-specific mysql/apache installers can SET_MYSQL_ROOT to 1 to request that the root
     # mysql user password be changed
 
     # ---- END OS-SPECIFIC part -----
 
     mysqlAllowOldPasswords
 
     if [[ "${SET_MYSQL_ROOT}" == "1" ]]; then
        mysqlChangeRootPwd
     fi
 
     # Ideally, setup modern R fonts like at UCSC:
     # Rscript -e "install.packages(c('showtext', 'curl'), repos='http://cran.us.r-project.org')
 
@@ -1588,36 +1598,42 @@
 
     checkDownloadUdr
 
     # CGI DOWNLOAD AND HGCENTRAL MYSQL DB SETUP
 
     if [ ! -f $COMPLETEFLAG ]; then
         # test if an apache file is already present
         if [ -f "$APACHEDIR" ]; then
             echo2 error: please remove the file $APACHEDIR, then restart the script with "bash $0".
             exit 100
         fi
     fi
 
     # check if /usr/local/apache is empty
     # on OSX, we had to create an empty htdocs, so skip this check there
-    if [ -d "$APACHEDIR" -a "$OS" != "OSX" ]; then
+    if [ -d "$APACHEDIR" ] ; then
+        if [ -f "$APACHEDIR"/.madeByBrowserBuild ] ; then
+            # leave a flag file so the script knows later that this directory did not exist and we made it
+            # and it is safe to write into it
+            rm -f "$APACHEDIR"/.madeByBrowserBuild
+        else
             echo2 error: the directory $APACHEDIR already exists.
             echo2 This installer has to overwrite it, so please move it to a different name
             echo2 or remove it. Then start the installer again with "bash $0 install"
             exit 100
         fi
+    fi
 
     mysqlDbSetup
 
     # setup the cram cache so remote cram files will load correctly
     mkdir -p $APACHEDIR/userdata/cramCache/{error,pending}
     chmod -R 777 $APACHEDIR/userdata/cramCache
 
     # -------------------
     # CGI installation
     # -------------------
     echo2
     echo2 Creating $CGIBINDIR and $HTDOCDIR and downloading contents from UCSC
     waitKey
     
     # create apache directories: HTML files, CGIs, temporary and custom track files