Skip to content

Commit

Permalink
Merge branch 'feature/wg-vps-setup' of github.com:Start9Labs/start-os…
Browse files Browse the repository at this point in the history
… into feature/wg-vps-setup
  • Loading branch information
dr-bonez committed Jan 22, 2025
2 parents 461b9c1 + dd4215b commit 1de38d2
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions build/lib/scripts/wg-vps-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NC='\033[0m' # No Color

# --- Constants ---
readonly WIREGUARD_INSTALL_URL="https://raw.githubusercontent.com/k0gen/wireguard-install/master/wireguard-install.sh"
readonly SSH_KEY_DIR="/etc/NetworkManager/system-connections"
readonly SSH_KEY_DIR="/home/start9/.ssh"
readonly SSH_KEY_NAME="id_ed25519"
readonly SSH_PRIVATE_KEY="$SSH_KEY_DIR/$SSH_KEY_NAME"
readonly SSH_PUBLIC_KEY="$SSH_PRIVATE_KEY.pub"
Expand All @@ -24,13 +24,14 @@ check_root() {
if [[ "$EUID" -ne 0 ]]; then
exec sudo "$0" "${SCRIPT_ARGS[@]}"
fi
sudo chown -R start9:start9 "$SSH_KEY_DIR"
}

# Function to print banner
print_banner() {
echo -e "${BLUE}"
echo "================================================"
echo " StartOS WireGuard VPS Setup Tool "
echo -e " ${NC}StartOS WireGuard VPS Setup Tool${BLUE} "
echo "================================================"
echo -e "${NC}"
}
Expand All @@ -50,7 +51,7 @@ print_usage() {
# Function to display end message
display_end_message() {
echo -e "\n${BLUE}------------------------------------------------------------------${NC}"
echo -e "${GREEN}WireGuard server setup complete!${NC}"
echo -e "${NC}WireGuard server setup complete!"
echo -e "${BLUE}------------------------------------------------------------------${NC}"
echo -e "\n${YELLOW}To expose your services to the Clearnet, use the following commands on your StartOS system (replace placeholders):${NC}"
echo -e "\n ${YELLOW}1. Initialize ACME (This only needs to be done once):${NC}"
Expand All @@ -73,21 +74,6 @@ validate_ip() {
fi
}

# Function to generate SSH key
generate_ssh_key() {
echo -e "${BLUE}Generating SSH key...${NC}"
if [ ! -f "$SSH_PRIVATE_KEY" ]; then
ssh-keygen -t ed25519 -f "$SSH_PRIVATE_KEY" -N "" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to generate SSH key.${NC}"
exit 1
fi
echo -e "${GREEN}SSH key generated successfully!${NC}"
else
echo -e "${YELLOW}SSH key already exists at '$SSH_PRIVATE_KEY', skipping key generation.${NC}"
fi
}

# Function to handle StartOS connection (download only)
handle_startos_connection() {
echo -e "${BLUE}Fetching the WireGuard configuration file...${NC}"
Expand Down Expand Up @@ -253,13 +239,17 @@ if [ -n "$CUSTOM_SSH_KEY" ]; then
fi
SSH_PRIVATE_KEY="$CUSTOM_SSH_KEY"
SSH_PUBLIC_KEY="$CUSTOM_SSH_KEY.pub"
if [ ! -f "$SSH_PUBLIC_KEY" ]; then
echo -e "${RED}Public key '$SSH_PUBLIC_KEY' not found. Try to create it with 'ssh-keygen -y -f $SSH_PRIVATE_KEY > $SSH_PUBLIC_KEY'${NC}"
else
# Use default StartOS SSH key
if [ ! -f "$SSH_PRIVATE_KEY" ]; then
echo -e "${RED}No SSH key found at default location '$SSH_PRIVATE_KEY'. Please ensure StartOS SSH keys are properly configured.${NC}"
exit 1
fi
else
# Generate SSH key if it doesn't exist
generate_ssh_key
fi

if [ ! -f "$SSH_PUBLIC_KEY" ]; then
echo -e "${RED}Public key '$SSH_PUBLIC_KEY' not found. Please ensure both private and public keys exist.${NC}"
exit 1
fi

# If VPS_IP is not provided via command line, ask for it
Expand All @@ -281,15 +271,7 @@ echo "VPS IP: $VPS_IP"
echo "SSH User: $SSH_USER"
echo "SSH Port: $SSH_PORT"

# Generate key or let user know it exist
if [ -z "$CUSTOM_SSH_KEY" ]; then
if [ ! -f "$SSH_PRIVATE_KEY" ]; then
echo -e "\nSetting up SSH key-based authentication..."
else
echo -e "\nSSH key already exist, skipping generation"
echo -e "\nSetting up SSH key-based authentication..."
fi
fi
echo -e "\n${GREEN}Proceeding with SSH key-based authentication...${NC}\n"

# Copy SSH public key to the remote server
if ! ssh-copy-id -i "$SSH_PUBLIC_KEY" -o StrictHostKeyChecking=no -p "$SSH_PORT" "$SSH_USER@$VPS_IP" >/dev/null 2>&1; then
Expand Down Expand Up @@ -327,7 +309,7 @@ if ! install_wireguard; then
fi

# Remove the local install script
rm wireguard-install.sh
rm wireguard-install.sh >/dev/null 2>&1

# Handle the StartOS config (download)
if ! handle_startos_connection; then
Expand Down

0 comments on commit 1de38d2

Please sign in to comment.