Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated setup script to check for the existence of YB_VOYAGER_SEND_DIAGNOSTICS env var in developers' machine env #1453

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions setup/hooks/post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ if [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ]; then
exit 0
fi

# Function to check if tarball is up to date
is_up_to_date() {
if [ ! -f "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1
fi

for file in $(find "$REPO_ROOT/$PARENT_DIR/$DIR_NAME" -type f); do
if [ "$file" -nt "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1 # Needs update
fi
done

return 0 # No update needed
}

if is_up_to_date; then
echo "No changes detected, tarball is up to date."
exit 0
fi

pushd "$REPO_ROOT/$PARENT_DIR" > /dev/null
tar -czf "$REPO_ROOT/$OUTPUT_TAR" $DIR_NAME
popd > /dev/null
Expand Down
20 changes: 20 additions & 0 deletions setup/hooks/post-rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ DIR_NAME="gather-assessment-metadata"
OUTPUT_TAR="yb-voyager/src/srcdb/data/gather-assessment-metadata.tar.gz"
REPO_ROOT=$(git rev-parse --show-toplevel)

# Function to check if tarball is up to date
is_up_to_date() {
if [ ! -f "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1
fi

for file in $(find "$REPO_ROOT/$PARENT_DIR/$DIR_NAME" -type f); do
if [ "$file" -nt "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1 # Needs update
fi
done

return 0 # No update needed
}

if is_up_to_date; then
echo "No changes detected, tarball is up to date."
exit 0
fi

pushd "$REPO_ROOT/$PARENT_DIR" > /dev/null
tar -czf "$REPO_ROOT/$OUTPUT_TAR" $DIR_NAME
popd > /dev/null
Expand Down
57 changes: 54 additions & 3 deletions setup/setup.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
#!/usr/bin/env bash

is_false_value() {
case "$1" in
"false"|"no"|"0")
return 0
;;
*)
return 1 # Non-false value
;;
esac
}

# Detecting the current shell and updating the corresponding configuration file
if [[ $SHELL == *"/zsh"* ]]; then
config_file=~/.zshrc
elif [[ $SHELL == *"/bash"* ]]; then
config_file=~/.bashrc
else
echo "Unsupported shell. Please add 'export YB_VOYAGER_SEND_DIAGNOSTICS=$requiredEnvVarValue' manually to your shell config."
break
fi

if [ -z "$YB_VOYAGER_SEND_DIAGNOSTICS" ] || ! is_false_value "$YB_VOYAGER_SEND_DIAGNOSTICS"; then
echo "YB_VOYAGER_SEND_DIAGNOSTICS is not set or is not set to a recognized false value."
while true; do
echo "Please enter a valid false value for YB_VOYAGER_SEND_DIAGNOSTICS (\"false\", \"0\", \"no\"):"
read requiredEnvVarValue
if is_false_value "$requiredEnvVarValue"; then
export YB_VOYAGER_SEND_DIAGNOSTICS=$requiredEnvVarValue
echo "export YB_VOYAGER_SEND_DIAGNOSTICS=$requiredEnvVarValue" >> $config_file
echo "YB_VOYAGER_SEND_DIAGNOSTICS is now set to '$requiredEnvVarValue' in your $config_file."
echo "To make this permanent, restart your terminal or run 'source $config_file'."
break
else
echo "Invalid input. The value '$requiredEnvVarValue' is not a recognized false value."
fi
done
else
echo "YB_VOYAGER_SEND_DIAGNOSTICS is already set to a recognized false value: '$YB_VOYAGER_SEND_DIAGNOSTICS'."
fi

REPO_ROOT="$(git rev-parse --show-toplevel)"
SOURCE_HOOK_DIR="$REPO_ROOT/setup/hooks"
TARGET_HOOK_DIR="$REPO_ROOT/.git/hooks"

# Copy hooks and make them executable
echo "Installing git hooks..."
for hook in $(ls $SOURCE_HOOK_DIR); do
cp "$SOURCE_HOOK_DIR/$hook" "$TARGET_HOOK_DIR/$hook"
chmod +x "$TARGET_HOOK_DIR/$hook"
echo "Installed $hook hook"
hook_path="$TARGET_HOOK_DIR/$hook"
# Backup existing hooks
if [ -f "$hook_path" ]; then
cp "$hook_path" "${hook_path}.backup"
fi

if cp "$SOURCE_HOOK_DIR/$hook" "$hook_path"; then
chmod +x "$hook_path"
echo "Installed $hook hook"
else
echo "Failed to install $hook hook. Check permissions or disk space."
exit 1
fi
done

echo "Git hooks setup completed successfully."
echo "setup.sh script complete, exiting..."
Loading