mirror of
https://github.com/elAgala/server-initializer.git
synced 2026-02-14 05:06:18 +00:00
First working setup
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function create_user() {
|
||||
read -p "Enter username: " username
|
||||
|
||||
sudo useradd -m -d /home/$username $username
|
||||
sudo usermod -aG sudo $username
|
||||
|
||||
sudo mkdir -p /var/www/apps /var/www/static
|
||||
|
||||
echo "User $username created with sudo privileges"
|
||||
echo "Apps directory created: /var/www/apps/"
|
||||
echo "Static files directory: /var/www/static"
|
||||
echo "Next step: Create SSH keys. Refer to: [link to SSH key creation guide]"
|
||||
}
|
||||
|
||||
create_user
|
||||
106
index.sh
Normal file
106
index.sh
Normal file
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Installing and setting up nginx"
|
||||
|
||||
# Function to create the static configuration template
|
||||
function create_static_config() {
|
||||
cat <<EOF | sudo tee /etc/nginx/sites-available/static.example.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name YOUR_DOMAINS;
|
||||
|
||||
root CONTENT_PATH;
|
||||
|
||||
error_page 404 /;
|
||||
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
|
||||
location / {
|
||||
try_files \$uri \$uri/ =404;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
echo "Created static configuration template: /etc/nginx/sites-available/static.example.conf"
|
||||
}
|
||||
|
||||
# Function to create the API configuration template
|
||||
function create_api_config() {
|
||||
cat <<EOF | sudo tee /etc/nginx/sites-available/api.example.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name YOUR_API_DOMAIN;
|
||||
location / {
|
||||
proxy_pass http://localhost:API_PORT/;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
echo "Created API configuration template: /etc/nginx/sites-available/api.example.conf"
|
||||
}
|
||||
|
||||
# Function to install Nginx
|
||||
function install_nginx() {
|
||||
if ! dpkg -l | grep -q nginx; then
|
||||
sudo apt update
|
||||
sudo apt install -y nginx
|
||||
sudo systemctl start nginx
|
||||
sudo systemctl enable nginx
|
||||
else
|
||||
echo "Nginx is already installed."
|
||||
fi
|
||||
}
|
||||
|
||||
install_nginx
|
||||
create_api_config
|
||||
create_static_config
|
||||
sudo systemctl restart nginx
|
||||
|
||||
# Enable Nginx configurations
|
||||
sudo ln -s /etc/nginx/sites-available/static.example.conf /etc/nginx/sites-enabled/
|
||||
sudo ln -s /etc/nginx/sites-available/api.example.conf /etc/nginx/sites-enabled/
|
||||
|
||||
echo "To enable these configurations, symbolic links have been created in /etc/nginx/sites-enabled."
|
||||
|
||||
echo "Installing and setting up Docker"
|
||||
|
||||
# Install prerequisites
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ca-certificates curl
|
||||
|
||||
# Create directory for GPG key
|
||||
sudo mkdir -p /etc/apt/keyrings
|
||||
|
||||
# Download and install Docker GPG key
|
||||
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
||||
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
||||
|
||||
# Add Docker repository to sources.list
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
||||
|
||||
# Update package lists
|
||||
sudo apt-get update
|
||||
|
||||
# Install Docker Engine, CLI, containerd, Buildx plugin, and Compose plugin
|
||||
if ! dpkg -l | grep -q docker-ce; then
|
||||
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
echo "Docker installation completed!"
|
||||
else
|
||||
echo "Docker is already installed."
|
||||
fi
|
||||
|
||||
echo "New user creation"
|
||||
|
||||
function create_user() {
|
||||
read -p "Enter username: " username
|
||||
|
||||
sudo useradd -m -d /home/$username $username
|
||||
sudo usermod -aG sudo $username
|
||||
|
||||
sudo mkdir -p /var/www/apps /var/www/static
|
||||
|
||||
echo "User $username created with sudo privileges"
|
||||
echo "Apps directory created: /var/www/apps/"
|
||||
echo "Static files directory: /var/www/static"
|
||||
echo "Next step: Create SSH keys. Refer to: [link to SSH key creation guide]"
|
||||
}
|
||||
|
||||
create_user
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Install prerequisites
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ca-certificates curl
|
||||
|
||||
# Create directory for GPG key
|
||||
sudo mkdir -p /etc/apt/keyrings
|
||||
|
||||
# Download and install Docker GPG key
|
||||
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
||||
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
||||
|
||||
# Add Docker repository to sources.list
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
||||
|
||||
# Update package lists
|
||||
sudo apt-get update
|
||||
|
||||
# Install Docker Engine, CLI, containerd, Buildx plugin, and Compose plugin
|
||||
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
|
||||
echo "Docker installation completed!"
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to create the static configuration template
|
||||
function create_static_config() {
|
||||
cat << EOF > /etc/nginx/sites-available/static.example.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name (YOUR_DOMAINS);
|
||||
|
||||
root (CONTENT_PATH);
|
||||
|
||||
error_page 404 /;
|
||||
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
echo "Created static configuration template: /etc/nginx/sites-available/static.example.conf"
|
||||
}
|
||||
|
||||
# Function to create the API configuration template
|
||||
function create_api_config() {
|
||||
cat << EOF > /etc/nginx/sites-available/api.example.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name YOUR_API_DOMAIN;
|
||||
location / {
|
||||
proxy_pass http://localhost:(API_PORT)/;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
echo "Created API configuration template: /etc/nginx/sites-available/api.example.conf"
|
||||
}
|
||||
|
||||
# Function to install Nginx
|
||||
function install_nginx() {
|
||||
sudo apt update
|
||||
sudo apt install -y nginx
|
||||
sudo systemctl start nginx
|
||||
sudo systemctl enable nginx
|
||||
}
|
||||
|
||||
install_nginx
|
||||
create_api_config
|
||||
create_static_config
|
||||
sudo systemctl restart nginx
|
||||
|
||||
echo "To enable these configurations, create symbolic links to /etc/nginx/sites-enabled:"
|
||||
33
setup.sh
33
setup.sh
@@ -1,8 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Installing and setting up nginx"
|
||||
./install_nginx.sh
|
||||
echo "Installing and setting up Docker"
|
||||
./install_docker.sh
|
||||
echo "New user creation"
|
||||
./create_user.sh
|
||||
# Check for required arguments
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "Usage: $0 <username> <server_ip> <port>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract arguments
|
||||
username="$1"
|
||||
server_ip="$2"
|
||||
port="$3"
|
||||
|
||||
# Script path
|
||||
script_path="index.sh"
|
||||
|
||||
# Transfer the script to the server
|
||||
scp -P $port "$script_path" "$username@$server_ip:/tmp/" || {
|
||||
echo "Error transferring script"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Execute the script on the server
|
||||
ssh -P $port "$username@$server_ip" "bash /tmp/"$script_path"" || {
|
||||
echo "Error executing script on server"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "Script execution completed on $username@$server_ip"
|
||||
|
||||
Reference in New Issue
Block a user