diff --git a/create_user.sh b/create_user.sh deleted file mode 100644 index 61188e3..0000000 --- a/create_user.sh +++ /dev/null @@ -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 diff --git a/index.sh b/index.sh new file mode 100644 index 0000000..c29ee4b --- /dev/null +++ b/index.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +echo "Installing and setting up nginx" + +# Function to create the static configuration template +function create_static_config() { + cat </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 diff --git a/install_docker.sh b/install_docker.sh deleted file mode 100644 index 37e159f..0000000 --- a/install_docker.sh +++ /dev/null @@ -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!" diff --git a/install_nginx.sh b/install_nginx.sh deleted file mode 100644 index 3dd0e9b..0000000 --- a/install_nginx.sh +++ /dev/null @@ -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:" diff --git a/setup.sh b/setup.sh index 3f925db..40a7c33 100644 --- a/setup.sh +++ b/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 " + 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"