Skip to content

Commit

Permalink
add post-start-command to run non-interactive parts of initializing t…
Browse files Browse the repository at this point in the history
…he gitconfig so it happens before rapids-build-utils' post-start-command (#279)
  • Loading branch information
trxcllnt authored May 1, 2024
1 parent c1b1a45 commit d89bc61
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 23 deletions.
7 changes: 7 additions & 0 deletions features/src/utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"history",
"devcontainer-utils-post-create-command"
],
"postStartCommand": [
"/bin/bash",
"-li",
"+o",
"history",
"devcontainer-utils-post-start-command"
],
"postAttachCommand": [
"/bin/bash",
"-li",
Expand Down
3 changes: 3 additions & 0 deletions features/src/utils/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ declare -a commands_and_sources=(
"generate-bash-completion bash/generate-bash-completion.sh"
"shell-is-interactive shell-is-interactive.sh"
"post-create-command post-create-command.sh"
"post-start-command post-start-command.sh"
"post-start-command-entrypoint post-start-command-entrypoint.sh"
"post-attach-command post-attach-command.sh"
"post-attach-command-entrypoint post-attach-command-entrypoint.sh"
"python-repl-startup python-repl-startup.py"
"init-git git/init.sh"
"init-git-interactive git/init-interactive.sh"
"clone-git-repo git/repo/clone.sh"
"init-ssh-deploy-keys ssh/init-deploy-keys.sh"
"init-github-cli github/cli/init.sh"
Expand Down
26 changes: 26 additions & 0 deletions features/src/utils/opt/devcontainer/bin/git/init-interactive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env bash

init_git_cli_config_interactive() {
local -;
set -euo pipefail;

if [ -z "$(git config --get user.name)" ]; then
local git_user_name_default="anon";
local git_user_name="${git_user_name_default}";
if devcontainer-utils-shell-is-interactive; then
read -rsp "Git user.name (${git_user_name_default}): " git_user_name <$(tty);
fi
git config --global user.name "${git_user_name:-"${git_user_name_default}"}" >/dev/null 2>&1 || true;
fi

if [ -z "$(git config --get user.email)" ]; then
local git_user_email_default="users.noreply.${GITHUB_HOST:-github.com}";
local git_user_email="${git_user_email_default}";
if devcontainer-utils-shell-is-interactive; then
read -rsp "Git user.email (${git_user_email_default}): " git_user_email <$(tty);
fi
git config --global user.email "${git_user_email:-"${git_user_email_default}"}" >/dev/null 2>&1 || true;
fi
}

init_git_cli_config_interactive "$@";
18 changes: 0 additions & 18 deletions features/src/utils/opt/devcontainer/bin/git/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ init_git_cli_config() {
awk 'BEGIN {FS=" "; OFS=" "} {print $3, $1, $2}' <(ssh-add -L) > ~/.config/git/allowed_signers;
fi

if [ -z "$(git config --get user.name)" ]; then
local git_user_name_default="anon";
local git_user_name="${git_user_name_default}";
if devcontainer-utils-shell-is-interactive; then
read -rsp "Git user.name (${git_user_name_default}): " git_user_name <$(tty);
fi
git config --global user.name "${git_user_name:-"${git_user_name_default}"}" >/dev/null 2>&1 || true;
fi

if [ -z "$(git config --get user.email)" ]; then
local git_user_email_default="users.noreply.${GITHUB_HOST:-github.com}";
local git_user_email="${git_user_email_default}";
if devcontainer-utils-shell-is-interactive; then
read -rsp "Git user.email (${git_user_email_default}): " git_user_email <$(tty);
fi
git config --global user.email "${git_user_email:-"${git_user_email_default}"}" >/dev/null 2>&1 || true;
fi

if [ -z "$(git config --get pull.rebase)" ]; then
git config --global pull.rebase false >/dev/null 2>&1 || true;
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#! /usr/bin/env bash

if test -z "${SKIP_DEVCONTAINER_UTILS_POST_ATTACH_COMMAND:-}"; then
find ~/ -maxdepth 1 -exec bash -c '\
[ $(stat -c "%u:%g" "$0") != "$1" ] && \
sudo chown -R "$1" "$0"' {} "$(id -u):$(id -g)" \;

# shellcheck disable=SC1091
. devcontainer-utils-init-git;
. devcontainer-utils-init-git-interactive;
# shellcheck disable=SC1091
. devcontainer-utils-vault-s3-init;
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

export SKIP_DEVCONTAINER_UTILS_POST_START_COMMAND=;

# shellcheck disable=SC1091
. devcontainer-utils-post-start-command;

exec "$@";
10 changes: 10 additions & 0 deletions features/src/utils/opt/devcontainer/bin/post-start-command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /usr/bin/env bash

if test -z "${SKIP_DEVCONTAINER_UTILS_POST_START_COMMAND:-}"; then
find ~/ -maxdepth 1 -exec bash -c '\
[ $(stat -c "%u:%g" "$0") != "$1" ] && \
sudo chown -R "$1" "$0"' {} "$(id -u):$(id -g)" \;

# shellcheck disable=SC1091
. devcontainer-utils-init-git;
fi

0 comments on commit d89bc61

Please sign in to comment.