From 2e92332e2edeb851fdec97ed4b77c69b470d76ef Mon Sep 17 00:00:00 2001
From: Chris Roberts <cpr420@gmail.com>
Date: Mon, 16 Sep 2019 18:31:57 -0600
Subject: [PATCH 1/1] Haiku fixes

---
 keychain | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/keychain b/keychain
index 0eee68f..37edc54 100755
--- a/keychain
+++ b/keychain
@@ -45,7 +45,7 @@ unset sshavail
 unset sshkeys
 unset gpgkeys
 unset mykeys
-keydir="${HOME}/.keychain"
+keydir="${HOME}/config/settings/keychain"
 unset envf
 evalopt=false
 queryopt=false
@@ -151,9 +151,9 @@ OPTIONS
         your ssh keys when you're logged out.
 
     ${GREEN}--confhost${OFF}
-        By default, keychain will look for key pairs in the ~/.ssh/
+        By default, keychain will look for key pairs in the ~/config/settings/ssh/
         directory. The ${GREEN}--confhost${OFF} option will inform keychain to look in
-        ~/.ssh/config for IdentityFile settings defined for particular
+        ~/config/settings/ssh/config for IdentityFile settings defined for particular
         hosts, and use these paths to locate keys.
 
     ${GREEN}--confirm${OFF}
@@ -167,7 +167,7 @@ OPTIONS
         compatibility.
 
     ${GREEN}--dir${OFF} ${CYAN}dirname${OFF}
-        Keychain will use dirname rather than \$HOME/.keychain
+        Keychain will use dirname rather than \$HOME/config/settings/keychain
 
     ${GREEN}--query${OFF}
         Keychain will print lines in KEY=value format representing the
@@ -181,8 +181,8 @@ OPTIONS
     ${GREEN}--env${OFF} ${CYAN}filename${OFF}
         After parsing options, keychain will load additional environment
         settings from "filename". By default, if "--env" is not given, then
-        keychain will attempt to load from ~/.keychain/[hostname]-env or
-        alternatively ~/.keychain/env. The purpose of this file is to
+        keychain will attempt to load from ~/config/settings/keychain/[hostname]-env or
+        alternatively ~/config/settings/keychain/env. The purpose of this file is to
         override settings such as PATH, in case ssh is stored in a
         non-standard place.
 
@@ -241,7 +241,7 @@ OPTIONS
 
     ${GREEN}--noask${OFF}
         This option tells keychain do everything it normally does (ensure
-        ssh-agent is running, set up the ~/.keychain/[hostname]-{c}sh files)
+        ssh-agent is running, set up the ~/config/settings/keychain/[hostname]-{c}sh files)
         except that it will not prompt you to add any of the keys you
         specified if they haven't yet been added to ssh-agent.
 
@@ -360,7 +360,7 @@ lockfile() {
 		tmpfile="$lockf.$$"
 
 		echo $$ >"$tmpfile" 2>/dev/null || exit
-		if ln "$tmpfile" "$lockf" 2>/dev/null; then
+		if ln -s "$tmpfile" "$lockf" 2>/dev/null; then
 				rm -f "$tmpfile"
 		havelock=true && return 0
 		fi
@@ -368,7 +368,7 @@ lockfile() {
 				rm -f "$tmpfile"
 			return 1
 	fi
-		if ln "$tmpfile" "$lockf" 2>/dev/null; then
+		if ln -s "$tmpfile" "$lockf" 2>/dev/null; then
 				rm -f "$tmpfile"
 		havelock=true && return 0
 		fi
@@ -432,6 +432,8 @@ findpids() {
 			esac ;;
 		GNU|gnu)
 			fp_psout=$(ps -g 2>/dev/null) ;;		# GNU Hurd syntax
+		haiku)
+			fp_psout=$(ps 2>/dev/null) ;; # Haiku OS
 	esac
 
 	# If we didn't get a match above, try a list of possibilities...
@@ -448,7 +450,7 @@ findpids() {
 	if [ -n "$fp_psout" ]; then
 		echo "$fp_psout" | \
 			awk "BEGIN{IGNORECASE=1} /defunct/{next}
-				/$fp_prog-[a]gen/{print \$1}" | xargs
+				/$fp_prog-[a]gen/{print \$2}" | xargs
 		return 0
 	fi
 
@@ -1091,8 +1093,8 @@ parse_mykeys() {
 		if wantagent ssh; then
 			if [ -f "$pm_k" ]; then
 				add_sshkey "$pm_k" ; continue
-			elif [ -f "$HOME/.ssh/$pm_k" ]; then
-				add_sshkey "$HOME/.ssh/$pm_k" ; continue
+			elif [ -f "$HOME/config/settings/ssh/$pm_k" ]; then
+				add_sshkey "$HOME/config/settings/ssh/$pm_k" ; continue
 			elif [ -f "$HOME/.ssh2/$pm_k" ]; then
 				add_sshkey "$HOME/.ssh2/$pm_k" ; continue
 			elif [ -f "$pkeypath" ]; then
@@ -1168,7 +1170,7 @@ confpath() {
 				break
 			fi
 		esac
-	done < ~/.ssh/config
+	done < ~/config/settings/ssh/config
 }
 
 # synopsis: wantagent prog
@@ -1314,11 +1316,11 @@ while [ -n "$1" ]; do
 			quietopt=true
 			;;
 		--confhost|-c)
-			if [ -e ~/.ssh/config ]; then
+			if [ -e ~/config/settings/ssh/config ]; then
 				sshconfig=true
 				confhost="$2"
 			else
-				warn "~/.ssh/config not found; --confhost/-c option ignored."
+				warn "~/config/settings/ssh/config not found; --confhost/-c option ignored."
 			fi
 			;;
 		--nocolor)
-- 
2.23.0

