summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-09-30 10:14:33 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-09-30 10:14:33 +0200
commit164a257c3e0af90736833e0febcfddd3ba2c285e (patch)
treedbb7d8adc0a58dee12936e5e8fef8c978374fb8d
parentc968d64b95f3b953093c7020730717ea7e7123cc (diff)
Support non-standard ssh ports without ~/.ssh/config adjustments
-rwxr-xr-xbin/ct40
-rwxr-xr-xexamples/bootstrap27
-rwxr-xr-xexamples/caretaker-ssh-command14
3 files changed, 58 insertions, 23 deletions
diff --git a/bin/ct b/bin/ct
index ee1eea3..7850b96 100755
--- a/bin/ct
+++ b/bin/ct
@@ -106,7 +106,7 @@ if (( ${#PKG_ROOTS} == 0 )) {
: ${MAGIC_ETC=1}
: ${PROGRESS=1}
export PKG_DIR
-export PKG_PROTO PKG_USER PKG_HOST PKG_UAH PKG_PATH
+export PKG_PROTO PKG_USER PKG_HOST PKG_PORT PKG_UAH PKG_PATH
if (( SILENT )) {
GIT_SILENT_ARG=--quiet
@@ -219,10 +219,17 @@ function list_update_remote {
if [[ ${PKGLIST_LOCAL} == 1 || ${PKG_PROTO} == 'file' ]] {
${PKGLIST_PATH} >> ${tmpfile}
} elif [[ ${PKG_PROTO} == 'ssh' ]] {
- ssh ${PKG_UAH} \
- "PKG_PATH=\"${PKG_PATH}\" PKG_UAH=\"${PKG_UAH}\"" \
- "PKG_PROTO=\"${PKG_PROTO}\"" \
- "${PKGLIST_PATH}" >> ${tmpfile}
+ if [[ -n ${PKG_PORT} ]] {
+ ssh -p ${PKG_PORT} ${PKG_UAH} \
+ "PKG_PATH=\"${PKG_PATH}\" PKG_UAH=\"${PKG_UAH}\"" \
+ "PKG_PORT=\"${PKG_PORT}\" PKG_PROTO=\"${PKG_PROTO}\"" \
+ "${PKGLIST_PATH}" >> ${tmpfile}
+ } else {
+ ssh ${PKG_UAH} \
+ "PKG_PATH=\"${PKG_PATH}\" PKG_UAH=\"${PKG_UAH}\"" \
+ "PKG_PROTO=\"${PKG_PROTO}\"" \
+ "${PKGLIST_PATH}" >> ${tmpfile}
+ }
}
pkgroot_clean
@@ -258,7 +265,7 @@ function pkgroot_setup {
}
function pkgroot_clean {
- unset PKG_PROTO PKG_HOST PKG_PATH PKG_USER PKG_UAH PKGLIST_PATH
+ unset PKG_PROTO PKG_HOST PKG_PORT PKG_PATH PKG_USER PKG_UAH PKGLIST_PATH
}
function check_installed {
@@ -386,12 +393,16 @@ function vcs_log {
function vcs_new {
(
- mkdir ${PKG_DIR}/${1}
- cd ${PKG_DIR}/${1} || die "Cannot cd to new package ${1}"
- git init
+ mkdir ${PKG_DIR}/${1}
+ cd ${PKG_DIR}/${1} || die "Cannot cd to new package ${1}"
+ git init
- git remote add origin ${PKG_PROTO}://${PKG_UAH}/${PKG_PATH}/${1}
-)
+ if [[ -n ${PKG_PORT} ]] {
+ git remote add origin ${PKG_PROTO}://${PKG_UAH}:${PKG_PORT}/${PKG_PATH}/${1}
+ } else {
+ git remote add origin ${PKG_PROTO}://${PKG_UAH}/${PKG_PATH}/${1}
+ }
+ )
}
function vcs_pull {
@@ -833,6 +844,7 @@ function pkg_debug {
echo " PKG_PROTO ${PKG_PROTO}"
echo " PKG_USER ${PKG_USER}"
echo " PKG_HOST ${PKG_HOST}"
+ echo " PKG_PORT ${PKG_PORT}"
echo " PKG_UAH ${PKG_UAH}"
echo " PKGLIST_PATH ${PKGLIST_PATH}"
echo " PKGLIST_LOCAL ${PKGLIST_LOCAL}"
@@ -962,7 +974,11 @@ function pkg_new {
if [[ ${PKG_PROTO} == ssh ]] {
info "Creating remote package...\n"
- ssh ${PKG_UAH} "GIT_DIR=${PKG_PATH}/${package} git --bare init"
+ if [[ -n ${PKG_PORT} ]] {
+ ssh -p ${PKG_PORT} ${PKG_UAH} "GIT_DIR=${PKG_PATH}/${package} git --bare init"
+ } else {
+ ssh ${PKG_UAH} "GIT_DIR=${PKG_PATH}/${package} git --bare init"
+ }
}
fi
diff --git a/examples/bootstrap b/examples/bootstrap
index d1acec1..e326e4b 100755
--- a/examples/bootstrap
+++ b/examples/bootstrap
@@ -17,13 +17,14 @@ if ! which git &> /dev/null; then
exit 200
fi
-if [[ ${#} -ge 4 ]] {
+if [[ ${#} -ge 5 ]] {
PKG_PROTO=${1}
PKG_USER=${2}
PKG_HOST=${3}
- PKG_PATH=${4}
- PKG_DIR=${~${5-${default_path}}}
- PKGLIST_PATH=""
+ PKG_PORT=${4}
+ PKG_PATH=${5}
+ PKG_DIR=${~${6-${default_path}}}
+ PKGLIST_PATH=""
if [[ $PKG_PROTO == "gitolite" ]]; then
pkglist_type="$PKG_PROTO"
PKG_PROTO="ssh"
@@ -31,18 +32,19 @@ if [[ ${#} -ge 4 ]] {
fi
} else {
cat <<- meow
- Usage: ./bootstrap PKG_PROTO PKG_USER PKG_HOST PKG_PATH [PKG_DIR]
+ Usage: ./bootstrap PKG_PROTO PKG_USER PKG_HOST PKG_PORT PKG_PATH [PKG_DIR]
PKG_PROTO : the protocol type, e.g. ssh, file or git.
PKG_USER : user on the package root host. May be left out if it
is identical to the local user name.
PKG_HOST : remote host to connect to
+ PKG_PORT : remote port to connect to
PKG_PATH : package root path on the remote host
PKG_DIR : the path where caretaker and all further packages will be installed,
by default ${default_path}
- Examples: ./bootstrap ssh '' aneurysm /home/derf/var/packages_root
- ./bootstrap file '' '' /home/derf/var/packages_root
- ./bootstrap ssh derf flux.derf0.net /home/derf/var/packages_root
+ Examples: ./bootstrap ssh '' arclight 22 /home/derf/var/packages_root
+ ./bootstrap file '' '' '' /home/derf/var/packages_root
+ ./bootstrap ssh derf flux.derf0.net 22 /home/derf/var/packages_root
etc.
meow
exit 100
@@ -53,6 +55,9 @@ if [[ -n ${PKG_USER} ]] {
} else {
PKG_UAH=${PKG_HOST}
}
+if [[ ${PKG_PORT} != 22 ]] {
+ PKG_UAH="${PKG_UAH}:${PKG_PORT}"
+}
# zsh keeps complaining about not having a configuration,
# so let's be kind and give it an empty one.
@@ -75,6 +80,10 @@ cd caretaker
echo "Writing ${XDG_CONFIG_HOME}/caretaker/caretaker.conf"
mkdir -p ${XDG_CONFIG_HOME}/caretaker
+PKG_PORT_STRING=''
+if [[ ${PKG_PORT} != 22 ]] {
+ PKG_PORT_STRING="\nPKG_PORT='${PKG_PORT}'"
+}
cat > ${XDG_CONFIG_HOME}/caretaker/caretaker.conf <<- flurbl
PKG_DIR="${PKG_DIR/${HOME}/\${HOME\}}"
PKG_ROOTS=(default)
@@ -82,7 +91,7 @@ cat > ${XDG_CONFIG_HOME}/caretaker/caretaker.conf <<- flurbl
function pkgroot_default {
PKG_PROTO='${PKG_PROTO}'
PKG_USER='${PKG_USER}'
- PKG_HOST='${PKG_HOST}'
+ PKG_HOST='${PKG_HOST}'${(g::)PKG_PORT_STRING}
PKG_PATH='${PKG_PATH}'
flurbl
if [[ $PKGLIST_PATH != "" ]]; then
diff --git a/examples/caretaker-ssh-command b/examples/caretaker-ssh-command
index 456a97d..352d22e 100755
--- a/examples/caretaker-ssh-command
+++ b/examples/caretaker-ssh-command
@@ -10,15 +10,18 @@
# Change this to reflect your settings
PKG_PROTO='ssh'
-PKG_UAH='derf@aneurysm'
+PKG_UAH='derf@pkgroot.finalrewind.org'
PKG_PATH='/home/derf/var/packages_root'
+PKG_PORT='2222'
# Change this to the location of your pkglist script (if non-default)
PKG_LIST=${PKG_PATH}/pkglist
args=(${(z)SSH_ORIGINAL_COMMAND})
-
+# Note: This check accepts connections on ports 22 (standard, PKG_PORT unset)
+# and 2222 (non-standard, PKG_PORT set). You can remove the second block if you
+# only use port 22.
if [[ \
( \
${args[1]} == "PKG_PATH=\"${PKG_PATH}\"" && \
@@ -27,6 +30,13 @@ if [[ \
${args[4]} == ${PKG_LIST} && \
${#args} == 4 \
) || ( \
+ ${args[1]} == "PKG_PATH=\"${PKG_PATH}\"" && \
+ ${args[2]} == "PKG_UAH=\"${PKG_UAH}\"" && \
+ ${args[3]} == "PKG_PORT=\"${PKG_PORT}\"" && \
+ ${args[4]} == "PKG_PROTO=\"${PKG_PROTO}\"" && \
+ ${args[5]} == ${PKG_LIST} && \
+ ${#args} == 5 \
+ ) || ( \
${args[1]} == 'git-'(upload|receive)'-pack' && \
${args[2]} != *'../'* && \
${args[2]} == \'${PKG_ROOT}/*\' && \