Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle
2018-09-24 19:31:37 -04:00
parent 5eccef3c66
commit 0ee7b3e78a
2 changed files with 28 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e
set -o pipefail
@@ -8,45 +8,46 @@ DAEMON=sshd
HOSTKEY=/etc/ssh/ssh_host_ed25519_key
# create the host key if not already created
if [ ! -f "${HOSTKEY}" ]; then
if [[ ! -f "${HOSTKEY}" ]]; then
ssh-keygen -A
fi
mkdir -p ${HOME}/.ssh
mkdir -p "${HOME}/.ssh"
# shellcheck disable=SC1091
source /etc/profile
[ "$PUBKEY" ] && echo "$PUBKEY" > ${HOME}/.ssh/authorized_keys
[ "$PUBKEY" ] && echo "$PUBKEY" > "${HOME}/.ssh/authorized_keys"
chown -R git:git ${HOME}
chmod -R 755 ${HOME}
chown -R git:git "${HOME}"
chmod -R 755 "${HOME}"
# Fix permissions, if writable
if [ -w ${HOME}/.ssh ]; then
chown git:git ${HOME}/.ssh && chmod 700 ${HOME}/.ssh/
if [[ -w "${HOME}/.ssh" ]]; then
chown git:git "${HOME}/.ssh" && chmod 700 "${HOME}/.ssh/"
fi
if [ -w ${HOME}/.ssh/authorized_keys ]; then
chown git:git ${HOME}/.ssh/authorized_keys
chmod 600 ${HOME}/.ssh/authorized_keys
if [[ -w "${HOME}/.ssh/authorized_keys" ]]; then
chown git:git "${HOME}/.ssh/authorized_keys"
chmod 600 "${HOME}/.ssh/authorized_keys"
fi
# Warn if no config
if [ ! -e ${HOME}/.ssh/authorized_keys ]; then
if [[ ! -e "${HOME}/.ssh/authorized_keys" ]]; then
echo "WARNING: No SSH authorized_keys found for git"
fi
# set the default shell
mkdir -p $HOME/git-shell-commands
cat >$HOME/git-shell-commands/no-interactive-login <<\EOF
mkdir -p "${HOME}/git-shell-commands"
cat > "${HOME}/git-shell-commands/no-interactive-login" <<\EOF
#!/bin/sh
printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
printf '%s\n' "provide interactive shell access."
exit 128
EOF
chmod +x $HOME/git-shell-commands/no-interactive-login
chmod +x "${HOME}/git-shell-commands/no-interactive-login"
stop() {
echo "Received SIGINT or SIGTERM. Shutting down $DAEMON"
# Get PID
pid=$(cat /var/run/$DAEMON/$DAEMON.pid)
pid=$(cat "/var/run/${DAEMON}/${DAEMON}.pid")
# Set TERM
kill -SIGTERM "${pid}"
# Wait for exit
@@ -55,12 +56,13 @@ stop() {
echo "Done."
}
echo "Running $@"
if [ "$(basename $1)" == "$DAEMON" ]; then
echo "Running $*"
if [[ "$(basename "$1")" == "$DAEMON" ]]; then
trap stop SIGINT SIGTERM
# shellcheck disable=SC2068
$@ &
pid="$!"
mkdir -p /var/run/$DAEMON && echo "${pid}" > /var/run/$DAEMON/$DAEMON.pid
mkdir -p "/var/run/${DAEMON}" && echo "${pid}" > "/var/run/${DAEMON}/${DAEMON}.pid"
wait "${pid}" && exit $?
else
exec "$@"