refactor(scripts): move debian scripts under linux dir
- Moved upgrade-gitlab.sh from Debian/ to Linux/Debian/ - Moved import-pubkeys-from-github.sh from Debian/ to Linux/
This commit is contained in:
2 files changed
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =================================================================
|
||||
# GitLab Upgrade and Patch Script
|
||||
# =================================================================
|
||||
|
||||
# Ensure the script is run as root to have necessary permissions for package management and patching
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run as root"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "--- 1. Stopping Puma and Sidekiq ---"
|
||||
# Stop data processing and web services before upgrading to reduce the risk of database migration issues
|
||||
gitlab-ctl stop puma
|
||||
gitlab-ctl stop sidekiq
|
||||
|
||||
echo "--- 2. Updating GitLab via apt ---"
|
||||
# Update package sources and install the latest version of gitlab-ce (change to gitlab-ee if using the EE edition)
|
||||
apt-get update
|
||||
apt-get install --only-upgrade gitlab-ce -y
|
||||
|
||||
echo "--- 3. Applying Custom Patches ---"
|
||||
|
||||
# 3.1 Applying language switcher patch
|
||||
# if [ -f /etc/gitlab/patches/language_fix.patch ]; then
|
||||
# echo "Applying language_fix.patch..."
|
||||
# patch /opt/gitlab/embedded/service/gitlab-rails/app/helpers/preferred_language_switcher_helper.rb < /etc/gitlab/patches/language_fix.patch
|
||||
# else
|
||||
# echo "Warning: language_fix.patch not found!"
|
||||
# fi
|
||||
|
||||
# # 3.2 Applying footer patch (e.g., ICP number)
|
||||
# if [ -f /etc/gitlab/patches/beian.patch ]; then
|
||||
# echo "Applying beian.patch..."
|
||||
# patch /opt/gitlab/embedded/service/gitlab-rails/app/views/devise/shared/_footer.html.haml < /etc/gitlab/patches/beian.patch
|
||||
# else
|
||||
# echo "Warning: beian.patch not found!"
|
||||
# fi
|
||||
|
||||
echo "--- 4. Verifying GitLab Version ---"
|
||||
# Output the currently installed version information
|
||||
gitlab-rake gitlab:env:info
|
||||
|
||||
echo "--- 5. Restarting GitLab Services ---"
|
||||
# After upgrading, GitLab usually runs reconfigure automatically, but to ensure patches take effect, perform a full restart
|
||||
gitlab-ctl restart
|
||||
|
||||
echo "--- Process Completed Successfully ---"
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Ensure a list of usernames is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Error: No usernames provided."
|
||||
echo "Usage: bash $0 username1,username2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET_FILE="$HOME/.ssh/authorized_keys"
|
||||
|
||||
# Initialising: Ensure .ssh directory exists with correct secure permissions
|
||||
mkdir -p "$HOME/.ssh"
|
||||
chmod 700 "$HOME/.ssh"
|
||||
|
||||
# Ensure the authorised keys file exists so we can safely check its content later
|
||||
touch "$TARGET_FILE"
|
||||
chmod 600 "$TARGET_FILE"
|
||||
|
||||
# Split the first argument by commas into an array
|
||||
IFS=',' read -r -a USERNAMES <<< "$1"
|
||||
|
||||
for USERNAME in "${USERNAMES[@]}"; do
|
||||
# Trim potential leading/trailing whitespaces from username
|
||||
USERNAME=$(echo "$USERNAME" | xargs)
|
||||
|
||||
if [ -z "$USERNAME" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Fetching SSH public keys for GitHub user: ${USERNAME}..."
|
||||
|
||||
# Fetch keys from GitHub API (following redirects)
|
||||
KEYS=$(curl -sSL "https://github.com/${USERNAME}.keys")
|
||||
|
||||
# Check if the user exists or has any public keys
|
||||
if [ -z "$KEYS" ] || [[ "$KEYS" == *"Not Found"* ]]; then
|
||||
echo "Warning: No public keys found for user '${USERNAME}' or user does not exist. Skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Format the header exactly as required
|
||||
HEADER="# === SSH PUB KEY FOR ${USERNAME} ==="
|
||||
|
||||
# Check if this specific header already exists to avoid duplicate entries
|
||||
if grep -qF "$HEADER" "$TARGET_FILE"; then
|
||||
echo "Notice: Keys for '${USERNAME}' have already been imported previously. Skipping to prevent duplicates."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Append the formatted block to the authorised keys file safely
|
||||
# The awk block ensures that the keys always end with a proper newline character
|
||||
{
|
||||
echo ""
|
||||
echo "$HEADER"
|
||||
echo "$KEYS" | awk '1; END {if (NR && !/\n$/) print ""}'
|
||||
} >> "$TARGET_FILE"
|
||||
|
||||
echo "Successfully appended keys for ${USERNAME}."
|
||||
done
|
||||
|
||||
echo "SSH key import process completed."
|
||||
Reference in new issue
Block a user