Use FD 9 instead of {FD}. Move PLATFORM definition.
This commit is contained in:
parent
7cd16b4048
commit
ddf639d0bf
1 changed files with 11 additions and 13 deletions
24
.bashrc
24
.bashrc
|
@ -172,14 +172,14 @@ __read_ssh_agents() {
|
||||||
# Read all the known ssh agent sockets into an array.
|
# Read all the known ssh agent sockets into an array.
|
||||||
# Returns: 0 = Processed and read the agents file without issue.
|
# Returns: 0 = Processed and read the agents file without issue.
|
||||||
# 1 = Error processing/reading the agents file.
|
# 1 = Error processing/reading the agents file.
|
||||||
local ERR FD I SOCK
|
local ERR I SOCK
|
||||||
|
|
||||||
[[ ! -e "$HOME/.ssh/agents" ]] && touch "$HOME/.ssh/agents"
|
[[ ! -e "$HOME/.ssh/agents" ]] && touch "$HOME/.ssh/agents"
|
||||||
|
|
||||||
# Lock the ~/.ssh/agents file.
|
# Lock the ~/.ssh/agents file.
|
||||||
if [[ "$PLATFORM" == "Linux" ]]; then
|
if [[ "$PLATFORM" == "Linux" ]]; then
|
||||||
# Linux has 'flock', thankfully.
|
# Linux has 'flock', thankfully.
|
||||||
exec {FD}<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 "$FD"
|
exec 9<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 9
|
||||||
ERR=$?
|
ERR=$?
|
||||||
if (( ERR == 10 )); then
|
if (( ERR == 10 )); then
|
||||||
printf "\\033[1;31m%s\\033[39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
|
printf "\\033[1;31m%s\\033[39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
|
||||||
|
@ -196,7 +196,6 @@ __read_ssh_agents() {
|
||||||
for ((I = 0; I <= 5; I++)); do
|
for ((I = 0; I <= 5; I++)); do
|
||||||
if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then
|
if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then
|
||||||
exec 9<"$HOME/.ssh/agents"
|
exec 9<"$HOME/.ssh/agents"
|
||||||
FD="9"
|
|
||||||
# Make note of the mtime for use in write_ssh_agents.
|
# Make note of the mtime for use in write_ssh_agents.
|
||||||
SSH_AGENTS_MTIME="$(stat -f %Fm "$HOME/.ssh/agents")"
|
SSH_AGENTS_MTIME="$(stat -f %Fm "$HOME/.ssh/agents")"
|
||||||
ERR=0
|
ERR=0
|
||||||
|
@ -216,13 +215,13 @@ __read_ssh_agents() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read the socket list (bash v2+ compliant)
|
# Read the socket list (bash v2+ compliant)
|
||||||
while read -u "$FD" -r SOCK; do
|
while read -u 9 -r SOCK; do
|
||||||
[[ -n "$SOCK" ]] && SSH_AUTH_SOCKS+=("$SOCK")
|
[[ -n "$SOCK" ]] && SSH_AUTH_SOCKS+=("$SOCK")
|
||||||
done
|
done
|
||||||
ERR=$?
|
ERR=$?
|
||||||
|
|
||||||
# Close the file descriptor (which on Linux releases the flock too).
|
# Close the file descriptor (which on Linux releases the flock too).
|
||||||
: "$FD"<&-
|
exec 9<&-
|
||||||
|
|
||||||
# On Darwin, release the lock on the file.
|
# On Darwin, release the lock on the file.
|
||||||
rm -f "$HOME/.ssh/agents.lock"
|
rm -f "$HOME/.ssh/agents.lock"
|
||||||
|
@ -244,7 +243,7 @@ __write_ssh_agents() {
|
||||||
# Returns: 0 = Processed and wrote the agents file without issue.
|
# Returns: 0 = Processed and wrote the agents file without issue.
|
||||||
# 1 = Error processing/writing the agents file.
|
# 1 = Error processing/writing the agents file.
|
||||||
# 2 = The SSH_AUTH_SOCKS array may be out of date as the agents file'a mtime has changed.
|
# 2 = The SSH_AUTH_SOCKS array may be out of date as the agents file'a mtime has changed.
|
||||||
local FD ERR I J MTIME SOCKS
|
local ERR I J MTIME SOCKS
|
||||||
|
|
||||||
# Add the current agent socket to the sockets array.
|
# Add the current agent socket to the sockets array.
|
||||||
SSH_AUTH_SOCKS=("$SSH_AUTH_SOCK" "${SSH_AUTH_SOCKS[@]}")
|
SSH_AUTH_SOCKS=("$SSH_AUTH_SOCK" "${SSH_AUTH_SOCKS[@]}")
|
||||||
|
@ -267,7 +266,7 @@ __write_ssh_agents() {
|
||||||
(( ${MTIME/\.} > SSH_AGENTS_MTIME )) && return 2
|
(( ${MTIME/\.} > SSH_AGENTS_MTIME )) && return 2
|
||||||
|
|
||||||
# Lock the agents file.
|
# Lock the agents file.
|
||||||
exec {FD}>"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 "$FD"
|
exec 9<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 9
|
||||||
ERR=$?
|
ERR=$?
|
||||||
if (( ERR == 10 )); then
|
if (( ERR == 10 )); then
|
||||||
printf "\\033[1;31m%s\\033[39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
|
printf "\\033[1;31m%s\\033[39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2
|
||||||
|
@ -284,8 +283,7 @@ __write_ssh_agents() {
|
||||||
# Do locking the sucky way on OSX.
|
# Do locking the sucky way on OSX.
|
||||||
for ((I = 0; I <= 5; I++)); do
|
for ((I = 0; I <= 5; I++)); do
|
||||||
if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then
|
if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then
|
||||||
exec 9>"$HOME/.ssh/agents"
|
exec 9<"$HOME/.ssh/agents"
|
||||||
FD="9"
|
|
||||||
ERR=0
|
ERR=0
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
|
@ -307,7 +305,7 @@ __write_ssh_agents() {
|
||||||
[[ -n "${SOCKS[*]}" ]] && { printf "%s\\n" "${SOCKS[@]}" >"$HOME/.ssh/agents" 2>/dev/null; ERR=$?; }
|
[[ -n "${SOCKS[*]}" ]] && { printf "%s\\n" "${SOCKS[@]}" >"$HOME/.ssh/agents" 2>/dev/null; ERR=$?; }
|
||||||
|
|
||||||
# Release locks.
|
# Release locks.
|
||||||
: "$FD"<&-
|
exec 9<&-
|
||||||
rm -f "$HOME/.ssh/agents.lock"
|
rm -f "$HOME/.ssh/agents.lock"
|
||||||
|
|
||||||
# Error out if the data couldn't be written.
|
# Error out if the data couldn't be written.
|
||||||
|
@ -368,6 +366,9 @@ imagebin() {
|
||||||
curl -F file="@$1" https://imagebin.ca/upload.php | grep '^url:' | cut -d: -f2-
|
curl -F file="@$1" https://imagebin.ca/upload.php | grep '^url:' | cut -d: -f2-
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Determine the platform being logged into.
|
||||||
|
PLATFORM="$(uname -s)"
|
||||||
|
|
||||||
# Make bash a little more pleasent - these are valid for all versions.
|
# Make bash a little more pleasent - these are valid for all versions.
|
||||||
shopt -s cdspell checkhash checkwinsize cmdhist histappend no_empty_cmd_completion
|
shopt -s cdspell checkhash checkwinsize cmdhist histappend no_empty_cmd_completion
|
||||||
|
|
||||||
|
@ -451,9 +452,6 @@ hash ssh ssh-add >/dev/null 2>&1 && ssh() {
|
||||||
command "${_EXEC:-${FUNCNAME[0]}}" "$@"
|
command "${_EXEC:-${FUNCNAME[0]}}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine the platform being logged into.
|
|
||||||
PLATFORM="$(uname -s)"
|
|
||||||
|
|
||||||
# Platform specific set up.
|
# Platform specific set up.
|
||||||
if [[ "$PLATFORM" = "Linux" ]]; then
|
if [[ "$PLATFORM" = "Linux" ]]; then
|
||||||
# Linux specific functions.
|
# Linux specific functions.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue