Skip to content

aaron-kunde/setup-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setting up projects

A collection of shell scripts, to set up work projects. The primary focus are projects for developing software, but can be anything. These scripts deal with tasks, like

  • setting up the programming environment (e.g. a Java SDK) and
  • setting up build tools, like Apache Maven or Gradle.

In general the scripts fulfill the tasks:

  1. Installation of software
  2. Setting up the environment

Installation of software

  • Check, if the software in the wanted version is already installed.
  • Download the software in that version, if not installed.
  • Install the downloaded software into ​~/opt/, if not installed.

Setting up the environment

  • Set necessary environment variables in the shell to use the software in the given version.
  • Switch between versions of the same environment, without starting a new shell.

Requirements

  • The scripts must be usable from an interactive shell.
  • The scripts should not be specific to certain shell implementations. Still, the current supported shell is GNU Bash.
  • The scripts must be usable as a dependency for other scripts (e.g first setting up a JDK and then Gradle).

Usage

The preferred way, to use the scripts, is by including them using source or .:

git clone [email protected]:aaron-kunde/setup-project.git
. ./setup-project/src/<setup-script>

Usage options

The following methods of using the scripts have been evaluated:

Inclusion in the current shell

Including the script into the current shell, using source or . exposes all variables into the current shell or script, because no subshells are created. But it comes with some pitfalls, which have to be considered:

  • If the bash option -e is set in the script or one of its dependencies, it also closes the current shell, if an error occurs.
  • Inclusion of other scripts doesn’t work well with relative paths. This leads to errors if referencing dependencies with relative paths. Considering two scripts:
    • foo.sh:
    #!/bin/sh
    
    echo "foo: $0, $(dirname 0)"
        
    • bar.sh:
    #!/bin/sh
    
    . foo.sh
    
    echo "bar: $0, $(dirname 0)"
        

    While the inclusion from the same directory, where the scripts are, works fine

    ~/work/setup-project $ . bar.sh 
    foo: -bash, .
    bar: -bash, .
        

    it does not, if the scripts are included from a different directory:

    ~/work$ . setup-project/bar.sh
    -bash: foo.sh: No such file or directory
    bar: -bash, .
        
  • getopts doesn’t work properly for repeated calls without resetting $OPTIND

Using as init file

Creating a new subshell, Using the script as init file with, might be suitable for some situations:

bash --init-file ./setup-project/src/<setup-script> [-i]

This ignores the file ~~/.bashrc~.

Execution in a shell

Executing a script in a shell, executes it in a subshell. This does not export variables in the current (parent) shell, because variables are only exported in subshells. Therefore this method is not suitable.

Scripts

All scripts are in the src directory. They are generated by Org files using tangling. A basic template is defined, which is used as an abstract base for scripts for specific software.

Tests

For each setup script in src, a test script written with Bats exists in the test directory.

After setting up Bats executing:

git submodule init
git submodule update

The tests can be executed with:

./test/bats/bin/bats -t test/<test-file>.bats

About

Several scripts to inital setup software projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published