-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mbland/walkers
Rename lib/process-files to lib/walk; add apps-home
- Loading branch information
Showing
11 changed files
with
175 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#! /usr/bin/env bash | ||
# | ||
# Utilities to manage the APPS_HOME directory structure | ||
# | ||
# Exports: | ||
# create_apps_home | ||
# Creates the APPS_HOME directory structure | ||
|
||
. "$_GO_USE_MODULES" 'log' 'walk' | ||
|
||
export APPS_HOME_DIRS=( | ||
"$APPS_HOME/etc/profile.d" | ||
) | ||
export APPS_HOME_DIR_PERMISSIONS="${APPS_HOME_DIR_PERMISSIONS:-755}" | ||
export APPS_HOME_FILE_PERMISSIONS="${APPS_HOME_FILE_PERMISSIONS:-644}" | ||
|
||
if [[ -z "$APPS_HOME" ]]; then | ||
@go.log FATAL "APPS_HOME not defined; set it in settings.bash" | ||
fi | ||
|
||
# Creates the APPS_HOME directory structure | ||
create_apps_home() { | ||
local dir | ||
|
||
for dir in "${APPS_HOME_DIRS[@]}"; do | ||
create_dirs_with_permissions "$dir" "$APPS_HOME_DIR_PERMISSIONS" | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#! /usr/bin/env bash | ||
# | ||
# Functions for processing lists of dev setup files | ||
# | ||
# Exports: | ||
# walk_files | ||
# Perform an operation on each path that is a regular file | ||
# | ||
# walk_dotfiles | ||
# Perform an operation on each dotfile path | ||
# | ||
# walk_user_bin_scripts | ||
# Perform an operation on all user-bin script paths | ||
# | ||
# walk_path_forward | ||
# Processes a file path from the first component to the last | ||
# | ||
# create_dir_with_permissions | ||
# Creates a directory with the specified permissions | ||
# | ||
# create_dirs_with_permissions | ||
# Creates a directory and its parents with the specified permissions | ||
|
||
# Perform an operation on each path that is a regular file | ||
# | ||
# The recursion is terminated when `operation` returns a nonzero value. | ||
# | ||
# Arguments: | ||
# operation: Name of the function taking a file path as an argument | ||
# ${@:1}: List of paths to begin examining | ||
walk_files() { | ||
local f | ||
for f in "${@:1}"; do | ||
if [[ -f "$f" ]] && ! "$1" "$f"; then | ||
return | ||
elif [[ -d "$f" ]]; then | ||
walk_files "$1" "$f"/* | ||
fi | ||
done | ||
} | ||
|
||
# Perform an operation on each dotfile path | ||
# | ||
# Arguments: | ||
# operation: Function taking a dotfile path as an argument | ||
walk_dotfiles() { | ||
walk_files "$1" dotfiles/.[A-Za-z0-9_-]* | ||
} | ||
|
||
# Perform an operation on all user-bin script paths | ||
# | ||
# Arguments: | ||
# operation: Function taking a user-bin script path as an argument | ||
walk_user_bin_scripts() { | ||
if [[ -z "$PLATFORM_ID" ]]; then | ||
. "$_GO_USE_MODULES" 'platform' | ||
fi | ||
walk_files "$1" user-bin/{common,$PLATFORM_ID}/* | ||
} | ||
|
||
# Processes a file path from the first component to the last | ||
# | ||
# The first call to `operation` receives the first component of the path as its | ||
# path argument. Each successive call to `operation` receives the previous path | ||
# plus its child component. The processing is terminated when `operation` | ||
# returns a nonzero value. | ||
# | ||
# Arguments: | ||
# operation: Name of the function taking a file path as an argument | ||
# ${@:1}: List of paths to begin examining | ||
walk_path_forward() { | ||
local operation="$1" | ||
local oldIFS="$IFS" | ||
local IFS='/' | ||
local components=($2) | ||
local component | ||
local current_path | ||
|
||
IFS="$oldIFS" | ||
|
||
for component in "${components[@]}"; do | ||
current_path+="$component/" | ||
if ! "$operation" "$current_path"; then | ||
break | ||
fi | ||
done | ||
} | ||
|
||
# Creates a directory with the specified permissions | ||
# | ||
# If a directory already exists, this function does not update its permissions. | ||
# | ||
# Globals: | ||
# permissions: May be defined as an alternative to passing as a parameter | ||
# | ||
# Arguments: | ||
# dir: The path of the directory to create | ||
# permissions: The permissions to set on the directory, if created | ||
create_dir_with_permissions() { | ||
local dir="$1" | ||
local permissions="${2:-$permissions}" | ||
|
||
if [[ -z "$dir" ]]; then | ||
@go.log FATAL "Directory argument not specified" | ||
elif [[ -z "$permissions" ]]; then | ||
@go.log FATAL "Permissions not specified" | ||
fi | ||
|
||
if [[ ! -d "$dir" ]]; then | ||
@go.log INFO "Creating $dir" | ||
|
||
if ! mkdir "$dir"; then | ||
@go.log FATAL "Could not create $dir" | ||
elif ! chmod "$permissions" "$dir"; then | ||
@go.log FATAL "Could not set permissions for $dir" | ||
fi | ||
fi | ||
} | ||
|
||
# Creates a directory and its parents with the specified permissions | ||
# | ||
# If a directory already exists, this function does not update its permissions. | ||
# | ||
# Arguments: | ||
# dir: The path of the directory to create | ||
# permissions: The permissions to set on any created directory | ||
create_dirs_with_permissions() { | ||
permissions="$2" walk_path_forward create_dir_with_permissions "$1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters