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:
- 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.
- 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.
- 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).
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>
The following methods of using the scripts have been evaluated:
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
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~.
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.
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.
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