#!/usr/bin/env python #----------------------------------------------------------------------------- # Installation script for use in Bash. TC-shell still needed but not as # primary shell. #----------------------------------------------------------------------------- from sys import exit import subprocess, os from shutil import which from socket import gethostname def is_tool(name): #---------------------------------------------------------------- # Check whether 'name' is on PATH and marked as executable. #---------------------------------------------------------------- return which(name) is not None #-------------------------------- # Check for system tools #-------------------------------- print("\n1. Looking for tools") failed = False tools = ["wget", "gfortran", "tcsh"] for tool in tools: if is_tool(tool): print("%s is available"%(tool)) else: print("%s is NOT available"%(tool)) failed = True if failed: exit("--- Cannot install GIPSY ---") #-------------------------------- # Check for Python requirements #-------------------------------- print("\n2. Looking for Python packages") failed = False if is_tool("python"): proc = subprocess.run(['python', '-V'], stdout=subprocess.PIPE) # Get version number print("Found:", proc.stdout.decode('utf-8').strip()) else: print("\nNo Python interpreter found.\nGIPSY tasks written in Python will not be available") #---------------------------------------------------------------------------- # Next we check whether the current Python version can import # essential modules. We don't import them directly in this Python script to # keep memory requirements small. #---------------------------------------------------------------------------- required_modules = ["numpy", "matplotlib", "astropy.io.fits", "scipy", "PyQt5", "cython"] for modulename in required_modules: proc = subprocess.run(['python', '-c', "import %s"%(modulename)], stderr=open(os.devnull, 'w')) if proc.returncode == 0: print("Found:", modulename) if modulename == "cython": from cython import __version__ as cythonversion print('The Cython version is %s. I must not be 3.0!'%(cythonversion)) else: print("Did not find: %s"%(modulename)) failed = True if modulename == "cython": print('Install it with: pip install "cython<3"') print('which is also safe for conda users') print('Cython version 3.0 version has a bug which prevents to build the GIPSY Python module') if failed: print("\nNot all Python-related requirements are met.") print("You may proceed, but some or all Python tasks will be unavailable.") print("In principle, this can be corrected later.") #----------------------------------------- # Ask user for GIPSY's location # and test whether the installer can write # a file there. #----------------------------------------- print("\n3. Install directory") install_root = input("Enter directory where to install GIPSY (must not exist yet): ") os.mkdir(install_root) os.chdir(install_root) install_root = os.getcwd() # Get entire path dummy = "test.dum" try: open(dummy, 'w') except: exit("Cannot install GIPSY in %s", install_root) os.remove(dummy) proceed = input("OK to install GIPSY in %s ? [y/n] "%install_root) if not proceed in ['Y', 'y']: exit("Installation cancelled. Input is not y or Y") #------------------------------- # Start installation procedure #------------------------------- print("\n4. Installation of basic tools") logfile = install_root+"/install.log" print("\nLog file will be written to %s"%(logfile)) print("In case of problems, please check this file first and") print("attach it to your mail when you have to ask for help.\n") gip_root = install_root os.chdir(gip_root) os.mkdir("import") os.chdir("import") os.mkdir("src") os.chdir("src") print(" 1. Fetching GIPSY distribution ...") tarfile = "https://www.astro.rug.nl/~gipsy/installation2023/download/src/gipsy_src.tar.gz" proc = subprocess.run(['wget', tarfile, "-o", logfile]) if proc.returncode != 0: exit("Failed to fetch GIPSY distribution!") os.chdir("../..") proc = subprocess.run(['tar', "xfz", "import/src/gipsy_src.tar.gz"], stdout=subprocess.PIPE) if proc.returncode != 0: exit("Problem with untarring file.") #------------------------------------- # Setup the environment variables, # needed for the various csh scripts #------------------------------------- os.environ["gip_root"] = gip_root # Set environment variable for mkclients.csh os.environ["gip_inc"] = gip_root+"/inc" os.environ["gip_loc"] = gip_loc = gip_root+"/loc" os.environ["gip_mis"] = gip_root+"/mis" os.environ["gip_old"] = gip_root+"/old" os.environ["gip_sys"] = gip_sys = gip_root+"/sys" os.environ["gip_dat"] = gip_root+"/dat" os.environ["gip_sub"] = gip_root+"/sub" os.environ["gip_tsk"] = gip_root+"/tsk" os.environ["gip_doc"] = gip_root+"/doc" # lib, exe and tmp are defined later when we can read # the architecture from the clients file #------------------- # Make clients file #------------------- print(" 2. Make clients file") os.chdir(gip_sys) proc = subprocess.run(['./mkclient.csh', "103"], stdout=subprocess.PIPE) if proc.returncode != 0: print(proc.stdout.decode('utf-8').strip()) exit("Problem with mkclient script.") proc = subprocess.run(['mv', 'clients.new', gip_loc+"/clients"]) # Get architecture from clients file cf = open(gip_loc+"/clients") clientinfo = [] for line in cf.readlines(): if not line.startswith("#"): # Skip all comment lines clientinfo.append(line) hostname = gethostname() for info in clientinfo: if hostname in info: arch = info.split(":")[1] # Second field in client info is the architecture break os.environ["gip_exe"] = gip_exe = gip_root+"/exe/"+arch os.environ["gip_lib"] = gip_root+"/lib/"+arch os.environ["gip_tmp"] = gip_root+"/tmp/"+arch #-------------------- # Copy the setup file #-------------------- print(" 3. Create and copy setup file") os.chdir(gip_loc) proc = subprocess.run(['cp', gip_sys+"/setup.mgr", 'setup']) os.chdir(gip_sys) #------------------- # Run install script #------------------- print(" 4. Run install script to install tools etc.") f = open(logfile, "a") proc = subprocess.run([gip_sys+'/install.csh'], stdout=f) if proc.returncode != 0: exit("Could not finish compiler setup in install.csh") #--------------------- # Make bookkeeper file #--------------------- print(" 5. Make bookkeeper file") # Needs gip_sub and gip_tsk/doc proc = subprocess.run([gip_sys+'/mkbookkeeper.csh'], stdout=subprocess.PIPE) if proc.returncode != 0: print(proc.stdout.decode('utf-8').strip()) exit("Problem with bookkeeper script mkbookkeeper.csh") os.chdir(gip_sys) proc = subprocess.run(['mv', "bookkeeper.new", 'bookkeeper']) #---------------------------------------------- # Copy compile. On Mac/arm64 we see that # compile is missing after building the source # again in the next phase #---------------------------------------------- proc = subprocess.run(['cp', gip_exe+"/compile", gip_exe+"/compile2"]) #--------------------------------------- # Start the compilation of the sources #--------------------------------------- print("\n5. Start the compilation of the sources. This takes a while.") print(" To follow the progress you can enter on another command line:") print(" tail -f %s"%(logfile), "\n") proc = subprocess.run([gip_exe+'/compile2', '-update'], stdout=f) # also known as p -update if proc.returncode != 0: exit("Could not install all sources. See %s"%(logfile)) print("\n+++ FINISHED +++") print("\nAdd to your .bashrc file or enter on the command line the next lines:") print("export gip_root='%s'"%(gip_root)) print("source $gip_root/sys/gipenv.sh") print("\nTCSH users:") print("setenv gip_root '%s'"%(gip_root)) print("source $gip_root/sys/gipenv.csh") print("\nThen start GIPSY on the commandline with command: gipsy") #./mkclient.csh 231 >>& ${logfile} # The newer GIPSY versions cannot be updated with p -update #\mv clients.new $gip_root/loc/clients