Permalink
Browse files

Merge branch 'issue-30-sshgate_editor'

  • Loading branch information...
2 parents ecf99e3 + 4dadb43 commit 8bd935fc028cbfb74ed976697c2aedd057da6f07 @Tauop committed Feb 16, 2012
Showing with 61 additions and 11 deletions.
  1. +40 −0 bin/core/sshgate.core
  2. +1 −1 bin/core/target-ssh.func
  3. +1 −1 bin/core/target-sshkey.func
  4. +1 −1 bin/core/user.func
  5. +16 −6 build-utils/bin/core/setup.func
  6. +2 −2 data/sshgate.conf
View
@@ -164,5 +164,45 @@ if [ "${__SSHGATE_CORE__:-}" != 'Loaded' ]; then
fi
echo 'false'; return 1;
}
+
+ # usage: EDIT_FILE <file>
+ # desc: Open a file with ${SSHGATE_EDITOR} to be edit
+ # return: 0 on success, otherwise 1
+ # note: can failed if ${SSHGATE_EDITOR} is empty and ${EDITOR} is empty too
+ EDIT_FILE() {
+ local the_editor= file= good= message_done=
+
+ if [ $# -ne 1 ]; then
+ BAD_ARGUMENTS ; return 1;
+ fi
+
+ file="$1"
+ if [ ! -f "${file}" ]; then
+ ERROR "The file ${file} doesn't exist"; return 1;
+ fi
+
+ the_editor="${SSHGATE_EDITOR:-${EDITOR}}"
+
+ # don't check for the binary existance if we are testing
+ if [ "${SSHGATE_TEST:-}" != 'sshGateTest' ]; then
+ message_done='false'
+ while [ true ]; do
+ which "${the_editor}" >/dev/null 2>/dev/null
+ [ $? -eq 0 ] && break;
+ BR
+ WARNING "sshGate can't find a editor. Provide a editor to use for the moment."
+ if [ "${message_done}" = 'false' ]; then
+ NOTICE "Ask the sshGate super-administrator (root unix account) to configure"
+ MESSAGE "sshGate via sshgate-configure or configure your \${EDITOR} environment variable"
+ BR
+ message_done='true'
+ fi
+ ASK the_editor "Editor to use for now : "
+ done
+ fi
+
+ eval "${the_editor} '${file}'"
+ return $?
+ }
fi # __SSHGATE_CORE__
@@ -83,7 +83,7 @@ if [ "${__TARGET_SSH_FUNC__:-}" != 'Loaded' ]; then
fi
# edit the file
- eval "${SSHGATE_EDITOR} '${file}'"
+ EDIT_FILE "${file}"
if [ $? -ne 0 ]; then
ERROR "Failed to edit the configuration file";
mv -f "${bckfile}" "${file}"
@@ -60,7 +60,7 @@ if [ "${__TARGET_SSHKEY_FUNC__:-}" != 'Loaded' ]; then
echo "# Put the private sshkey for '${target}' here. Then save & quit from the editor" >> "${tmpfile}"
echo "# line begins by '#' will be removed" >> "${tmpfile}"
- eval " ${SSHGATE_EDITOR} '${tmpfile}'"
+ EDIT_FILE "${tmpfile}"
if [ $? -ne 0 ]; then
ERROR "Can't edit sshkey file"; return 1;
fi
View
@@ -396,7 +396,7 @@ if [ "${__USER_FUNC__:-}" != 'Loaded' ]; then
touch "${tmpfile}"
echo "# Put the SSH public key for '${user}' here. Then save & quit from the editor" >> "${tmpfile}"
echo "# line begins by '#' will be removed" >> "${tmpfile}"
- eval " ${SSHGATE_EDITOR} '${tmpfile}'"
+ EDIT_FILE "${tmpfile}"
grep -v '^#' < "${tmpfile}" > "${SSHGATE_DIR_USERS}/${user}"
rm -f "${tmpfile}" > /dev/null 2>/dev/null
@@ -175,7 +175,7 @@ if [ "${__SETUP_FUNC__:-}" != 'Loaded' ]; then
SSHGATE_GATE_ACCOUNT="${SSHGATE_GATE_ACCOUNT:-sshgate}"
SSHGATE_TARGETS_DEFAULT_SSH_LOGIN="${SSHGATE_TARGETS_DEFAULT_SSH_LOGIN:-root}"
SSHGATE_DEFAULT_LANGUAGE="${SSHGATE_DEFAULT_LANGUAGE:-us}"
- SSHGATE_EDITOR="${SSHGATE_EDITOR:-vi}"
+ SSHGATE_EDITOR="${SSHGATE_EDITOR:-${EDITOR}}"
SSHGATE_MAIL_SEND="${SSHGATE_MAIL_SEND:-Y}"
SSHGATE_MAIL_TO="${SSHGATE_MAIL_TO:-you@yourdomain.tld}"
SSHGATE_USERS_MUST_ACCEPT_TOS="${SSHGATE_USERS_MUST_ACCEPT_TOS:-Y}"
@@ -269,12 +269,22 @@ if [ "${__SETUP_FUNC__:-}" != 'Loaded' ]; then
good='0'
while [ "${good}" = '0' ]; do
- private_CONF SSHGATE_EDITOR "Which editor to use [%%%] ?"
- which "${SSHGATE_EDITOR}" >/dev/null 2>/dev/null
- if [ $? -eq 0 ]; then
- good='1'; break;
+ private_CONF --allow-empty SSHGATE_EDITOR "Which editor to use (empty: use \${EDITOR} environnement variable) [%%%] ?"
+ if [ -n "${SSHGATE_EDITOR}" ]; then
+ which "${SSHGATE_EDITOR}" >/dev/null 2>/dev/null
+ if [ $? -eq 0 ]; then
+ good='1'; break;
+ fi
+ ERROR "Can't find editor '${SSHGATE_EDITOR}'. (Set the full path ?)"
+ else
+ if [ -z "${EDITOR}" ]; then
+ MESSAGE "You don't set an editor for sshGate, and \${EDITOR} isn't set."
+ ASK --yesno reply "Are you sure to continue [N] ?" 'N'
+ if [ "${reply}" = 'Y' ]; then
+ good='1'; break;
+ fi
+ fi
fi
- ERROR "Can't find editor '${SSHGATE_EDITOR}'. (Set the full path ?)"
done
private_CONF --yesno SSHGATE_MAIL_SEND "Activate mail notification system [%%%] ?"
View
@@ -34,8 +34,8 @@ SSHGATE_USE_REMOTE_ADMIN_CLI='Y'
SSHGATE_SUDO_WITH_NOPASSWORD='Y'
SSHGATE_USERS_MUST_ACCEPT_TOS='Y'
-# editor to use when editing files
-SSHGATE_EDITOR='vim'
+# editor to use when editing files. leave it empty to use ${EDITOR}
+SSHGATE_EDITOR=''
# default path where files where sent to the target host
SSHGATE_TARGETS_SCP_PATH='~'

0 comments on commit 8bd935f

Please sign in to comment.