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
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3
2 changed files with 28 additions and 25 deletions

View File

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

View File

@ -34,7 +34,8 @@ linux_next(){
git fetch --tags linux-next git fetch --tags linux-next
) )
local branch="next-$(date +%Y%m%d)" local branch
branch="next-$(date +%Y%m%d)"
echo "Checking out the correct branch ${branch}..." echo "Checking out the correct branch ${branch}..."
( (
cd "$dir" cd "$dir"
@ -58,7 +59,7 @@ install_kernel(){
if [[ "$VERSION" != "next" ]]; then if [[ "$VERSION" != "next" ]]; then
local MAJOR_VERSION=${VERSION:0:1} local MAJOR_VERSION=${VERSION:0:1}
local V=( ${VERSION//./ } ) local V=( "${VERSION//./ }" )
local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}" local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}"
# Get the kernel source. # Get the kernel source.
@ -69,7 +70,7 @@ install_kernel(){
MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN" MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN"
else else
[ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${VERSION}.tar.xz" | tar -C /usr/src -xJ [ -d "/usr/src/linux-${VERSION}" ] || curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${VERSION}.tar.xz" | tar -C /usr/src -xJ
fi fi
# Git clone and apply the patches for the aufs filesystem. # Git clone and apply the patches for the aufs filesystem.
@ -77,7 +78,7 @@ install_kernel(){
aufsdir=/aufs4-standalone aufsdir=/aufs4-standalone
echo "Cloning the git patches for the aufs filesystem..." echo "Cloning the git patches for the aufs filesystem..."
git clone --depth 1 --branch aufs${MAJOR_MINOR_VERSION} --single-branch https://github.com/sfjro/aufs4-standalone.git $aufsdir git clone --depth 1 --branch "aufs${MAJOR_MINOR_VERSION}" --single-branch https://github.com/sfjro/aufs4-standalone.git "$aufsdir"
( (
cd "$DIR" cd "$DIR"
@ -126,7 +127,7 @@ install_kernel(){
cd "$DIR" cd "$DIR"
echo "Building the kernel..." echo "Building the kernel..."
make -j$JOBS make -j"$JOBS"
echo "Installing the modules..." echo "Installing the modules..."
make modules_install make modules_install
echo "Installing the kernel..." echo "Installing the kernel..."
@ -134,7 +135,7 @@ install_kernel(){
) )
( (
echo "Stripping the modules..." echo "Stripping the modules..."
find /lib/modules/ -name *.ko -exec strip --strip-unneeded {} + find /lib/modules/ -name "*.ko" -exec strip --strip-unneeded {} +
) )
} }