Provision?
This commit is contained in:
parent
a36c347b4c
commit
056a59a07b
87
provision.sh
Executable file
87
provision.sh
Executable file
@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
GREEN='\033[1;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[1;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 1. Root Check
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}Please run this script as root.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. OS Detection
|
||||
echo -e "${YELLOW}LOG: Detecting OS...${NC}"
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
OS=$ID
|
||||
fi
|
||||
|
||||
# 3. Install Prerequisites (Git, Make, Zsh, Sudo)
|
||||
echo -e "${YELLOW}LOG: Updating system and installing base tools...${NC}"
|
||||
|
||||
if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then
|
||||
pacman -Sy --noconfirm git make curl zsh sudo
|
||||
SUDO_GROUP="wheel"
|
||||
elif [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
|
||||
apt-get update
|
||||
apt-get install -y git make curl zsh sudo
|
||||
SUDO_GROUP="sudo"
|
||||
else
|
||||
echo -e "${RED}Unsupported OS: $OS${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Interactive Prompts
|
||||
echo -e "${GREEN}---------------------------------------${NC}"
|
||||
echo -e "${GREEN} USER PROVISIONING WIZARD ${NC}"
|
||||
echo -e "${GREEN}---------------------------------------${NC}"
|
||||
|
||||
read -p "Enter Username (default: mangopig): " USERNAME
|
||||
USERNAME=${USERNAME:-mangopig}
|
||||
|
||||
read -p "Enter UID (default: 1000): " USER_UID
|
||||
USER_UID=${USER_UID:-1000}
|
||||
|
||||
read -p "Enter GID (default: 1000): " USER_GID
|
||||
USER_GID=${USER_GID:-1000}
|
||||
|
||||
# 5. Group Creation
|
||||
if getent group "$USER_GID" >/dev/null; then
|
||||
echo -e "${YELLOW}LOG: Group with GID $USER_GID already exists. Using it.${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}LOG: Creating group $USERNAME with GID $USER_GID...${NC}"
|
||||
groupadd -g "$USER_GID" "$USERNAME"
|
||||
fi
|
||||
|
||||
# 6. User Creation
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
echo -e "${YELLOW}LOG: User $USERNAME already exists. Skipping creation.${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}LOG: Creating user $USERNAME...${NC}"
|
||||
|
||||
# Detect Zsh path
|
||||
ZSH_PATH=$(which zsh)
|
||||
|
||||
# Create user with specific UID, GID, Groups, and Shell
|
||||
useradd -m -u "$USER_UID" -g "$USER_GID" -G "$SUDO_GROUP" -s "$ZSH_PATH" "$USERNAME"
|
||||
|
||||
echo -e "${GREEN}LOG: Setting password for $USERNAME...${NC}"
|
||||
passwd "$USERNAME"
|
||||
fi
|
||||
|
||||
# 7. Sudo Configuration (Passwordless)
|
||||
echo -e "${YELLOW}LOG: Configuring passwordless sudo...${NC}"
|
||||
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/90-$USERNAME"
|
||||
chmod 0440 "/etc/sudoers.d/90-$USERNAME"
|
||||
|
||||
# 8. Arch Specific: Uncomment wheel in sudoers if not already active
|
||||
if [ "$OS" == "arch" ]; then
|
||||
# Ensure the 'wheel' group is actually enabled in the main config if drop-in fails
|
||||
sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Server Provisioned! Log out and SSH as $USERNAME.${NC}"
|
||||
56
setup.sh
56
setup.sh
@ -132,31 +132,45 @@ fi
|
||||
# Install NVM, GVM, Rustup
|
||||
echo -e "${BLUE} LOG:${YELLOW} Installing NVM, GVM and Rustup...${NC}"
|
||||
|
||||
# NVM
|
||||
if [ ! -d "$HOME/.nvm" ]; then
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||
# 1. Setup Node (LTS + Global Tools)
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Load NVM
|
||||
|
||||
if command -v nvm &> /dev/null; then
|
||||
echo -e "${BLUE} LOG:${YELLOW} Installing Node LTS...${NC}"
|
||||
nvm install --lts
|
||||
nvm use --lts
|
||||
|
||||
echo -e "${BLUE} LOG:${YELLOW} Installing Global Node Packages (pnpm, yarn)...${NC}"
|
||||
npm install -g pnpm yarn
|
||||
fi
|
||||
|
||||
# Go and GVM
|
||||
wget https://go.dev/dl/go1.25.4.linux-amd64.tar.gz -O /tmp/go1.25.4.linux-amd64.tar.gz
|
||||
sudo rm -rf /usr/local/go
|
||||
sudo tar -C /usr/local -xzf /tmp/go1.25.4.linux-amd64.tar.gz
|
||||
rm -f /tmp/go1.25.4.linux-amd64.tar.gz
|
||||
# 2. Setup Go (Bootstrap + Target)
|
||||
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm" # Load GVM
|
||||
|
||||
if [ ! -d "$HOME/.gvm" ]; then
|
||||
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
|
||||
TARGET_GO="go1.25.5"
|
||||
|
||||
if command -v gvm &> /dev/null; then
|
||||
# Bootstrap check
|
||||
if ! command -v go &> /dev/null; then
|
||||
echo -e "${BLUE} LOG:${YELLOW} Bootstrapping Go...${NC}"
|
||||
gvm install go1.24.0 -B
|
||||
gvm use go1.24.0
|
||||
fi
|
||||
|
||||
# Install Target
|
||||
if [[ $(gvm list) != *"$TARGET_GO"* ]]; then
|
||||
echo -e "${BLUE} LOG:${YELLOW} Installing Target Go ($TARGET_GO)...${NC}"
|
||||
gvm install $TARGET_GO
|
||||
gvm use $TARGET_GO --default
|
||||
fi
|
||||
fi
|
||||
|
||||
# Rustup
|
||||
if ! command -v rustup &> /dev/null; then
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
fi
|
||||
|
||||
# Install Eza with Cargo
|
||||
echo -e "${BLUE} LOG:${YELLOW} Installing Eza via Cargo...${NC}"
|
||||
if ! command -v eza &> /dev/null; then
|
||||
source "$HOME/.cargo/env"
|
||||
cargo install eza
|
||||
# 3. Setup Rust (Stable Default)
|
||||
if command -v rustup &> /dev/null; then
|
||||
echo -e "${BLUE} LOG:${YELLOW} Setting Rust to stable...${NC}"
|
||||
rustup default stable
|
||||
rustup update
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
@ -213,7 +227,7 @@ touch "$HOME/.zsh_secrets"
|
||||
# Stow Dotfiles
|
||||
echo -e "${BLUE} LOG:${YELLOW} Stowing dotfiles...${NC}"
|
||||
cd "$DOTFILES_DIR"
|
||||
stow . --target="$HOME" --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile"
|
||||
stow . --target="$HOME" --ignore="setup.sh" --ignore=".git" --ignore=".gitignore" --ignore="README.md" --ignore=".zsh_secrets" --ignore=".zsh_secrets.example" --ignore="LICENSE" --ignore="Makefile" --ignore="provision.sh"
|
||||
|
||||
# Finish
|
||||
echo -e "${GREEN} LOG: Setup Complete! Please restart your terminal to apply all changes.${NC}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user