GovReady / govready

Toolkit for getting open source apps ready for secure, approved government use
GNU General Public License v3.0
97 stars 31 forks source link

Refactor step1 #67

Closed djk29a closed 9 years ago

djk29a commented 9 years ago

A few small edits for best practices and moved a lot of functions into a scripts/lib directory. I haven't had a good chance at testing this so please give this a whirl responsibly :smile:

gregelin commented 9 years ago

@djk29a Thanks for request. Will look at first thing in the morning!

gregelin commented 9 years ago

@djk29a I've been looking at this pull request. I pulled the branch refactor-step1 over to a branch in GovReady.

There's some variation between references to scripts/lib/<file> and lib/file. I assume that is just a typo?

I'm thinking of renaming that subdirectory to govreadylib so the main shell script govready can still be in /usr/local/bin so the path does not need to be updated. Alternatively, maybe the shared files should be put into usr/local/lib.

I'm testing the script with the code broken out into modular files and finding that the relative reference to the shared files need a path prefix of the shared files are not found. We seem to need something like this:

# get path
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
echo $DIR

. "$DIR/scripts/lib/common"
. "$DIR/scripts/lib/env" # top level environment variables