feat manage script

This commit is contained in:
2025-02-24 09:51:41 +00:00
commit 1a3a374f3b
45 changed files with 2149 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root using sudo."
exit 1
fi
if [ -z "$1" ]; then
echo "Usage: $0 <new-hostname>"
exit 1
fi
NEW_HOSTNAME=$1
OLD_HOSTNAME=$(hostname)
hostnamectl set-hostname "$NEW_HOSTNAME"
sed -i "s/$OLD_HOSTNAME/$NEW_HOSTNAME/g" /etc/hosts
echo "Hostname has been changed to: $(hostname)"

63
scripts/linux-setup_docker.sh Executable file
View File

@@ -0,0 +1,63 @@
#!/bin/bash
set -e
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root: sudo $0"
exit 1
fi
echo "Removing old Docker versions..."
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do
apt-get remove -y $pkg || true
done
# Detect OS
if [ -f /etc/debian_version ]; then
DOCKER_OS="debian"
elif [ -f /etc/lsb-release ]; then
DOCKER_OS="ubuntu"
else
echo "Error: Unsupported OS"
exit 1
fi
echo "Updating package list and installing dependencies..."
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
echo "Setting up Docker repository..."
# Add Docker's official GPG key
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/${DOCKER_OS}/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/${DOCKER_OS} \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
echo "Installing Docker..."
apt-get update
apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
# Verify installation
echo "Verifying Docker installation..."
docker --version
containerd --version
echo "Configuring Docker permissions..."
groupadd docker 2>/dev/null || true
usermod -aG docker ${SUDO_USER:-$USER}
echo "Enabling and starting Docker services..."
systemctl enable --now docker.service
systemctl enable --now containerd.service
echo "Docker setup completed. Please log out and log back in for group changes to take effect."

30
scripts/linux-setup_zsh.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
set -e
if [ "$(id -u)" -ne 0 ]; then
echo "Please run this script as root: sudo $0"
exit 1
fi
# Check if Zsh is already installed
if command -v zsh &> /dev/null; then
echo "Zsh is already installed. Skipping installation."
else
echo "Updating package list..."
apt-get update
echo "Installing Zsh..."
apt-get install -y zsh
if ! command -v zsh &> /dev/null; then
echo "Error: Zsh installation failed."
exit 1
fi
fi
echo "Changing default shell to Zsh for user ${SUDO_USER:-$USER}..."
zsh_path=$(command -v zsh)
chsh -s "$zsh_path" "${SUDO_USER:-$USER}"
echo "Zsh installation and setup complete. Please log out and log back in for changes to take effect."

10
scripts/macos-brew_backup.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
BACKUP_FILE="$HOME/.dotfiles/config/envs/macos/homebrew/Brewfile"
echo "Backing up Homebrew installations..."
mkdir -p "$(dirname "$BACKUP_FILE")"
brew bundle dump --file="$BACKUP_FILE" --force
echo "Backup saved to $BACKUP_FILE"

13
scripts/macos-brew_restore.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
BACKUP_FILE="$HOME/.dotfiles/config/envs/macos/homebrew/Brewfile"
if [[ ! -f "$BACKUP_FILE" ]]; then
echo "Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Restoring Homebrew installations..."
brew bundle --file="$BACKUP_FILE"
echo "Homebrew restoration complete."

View File

@@ -0,0 +1,22 @@
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root using sudo."
exit 1
fi
if [ -z "$1" ]; then
echo "Usage: $0 <new-hostname>"
exit 1
fi
NEW_HOSTNAME=$1
scutil --set HostName "$NEW_HOSTNAME"
scutil --set ComputerName "$NEW_HOSTNAME"
scutil --set LocalHostName "$NEW_HOSTNAME"
echo "Hostname has been changed to:"
echo "HostName: $(scutil --get HostName)"
echo "ComputerName: $(scutil --get ComputerName)"
echo "LocalHostName: $(scutil --get LocalHostName)"

57
scripts/setup_ssh_keys.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
set -e
usage() {
echo "Usage: $0 --comment <comment> [--filename <filename>]"
echo " --comment <comment> The comment for the SSH key."
echo " --filename <filename> (optional) The filename suffix for the SSH key. Defaults to 'id_ed25519'."
exit 1
}
# Default values
COMMENT=""
FILENAME="id_ed25519"
# Parse named arguments
while [[ $# -gt 0 ]]; do
case $1 in
--comment)
COMMENT="$2"
shift 2
;;
--filename)
FILENAME="id_ed25519_$2"
shift 2
;;
*)
echo "Unknown argument: $1"
usage
;;
esac
done
# Validate required arguments
if [ -z "$COMMENT" ]; then
echo "Error: --comment is required."
usage
fi
SSH_DIR="$HOME/.ssh"
KEY_PATH="$SSH_DIR/$FILENAME"
# Ensure SSH directory exists
mkdir -p "$SSH_DIR"
chmod 700 "$SSH_DIR"
# Generate SSH key
if [ -f "$KEY_PATH" ]; then
echo "Error: Key file $KEY_PATH already exists."
exit 1
fi
ssh-keygen -t ed25519 -C "$COMMENT" -f "$KEY_PATH" -N ""
echo "SSH key created: $KEY_PATH"
echo "Public key:"
cat "$KEY_PATH.pub"