Skip to content

Commit

Permalink
fix: Little refactor and remove Alpine compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ciro-mota committed Jun 6, 2024
1 parent 7fc3304 commit d7b9bb0
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions scripts/nginx.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,67 @@
#!/bin/sh
#!/bin/bash

if [ -f /etc/debian_version ]; then
export DEBIAN_FRONTEND=noninteractive
apt-get -q update && apt-get -qy install ansible
elif [ -f /etc/redhat-release ]; then
dnf update -y && dnf install -y ansible-core
dnf install -y ansible-core firewalld

firewallrule() {
firewall-cmd --permanent --zone=public --add-port=80/tcp &&
firewall-cmd --permanent --zone=public --add-port=443/tcp &&
systemctl start firewalld && \
systemctl enable firewalld && \
firewall-cmd --permanent --zone=public --add-port=80/tcp && \
firewall-cmd --permanent --zone=public --add-port=443/tcp && \
firewall-cmd --reload
}
}

firewallrule

ansible-galaxy collection install community.general
elif [ -f /etc/alpine-release ]; then
apk update && apk add ansible

else
echo "Unsuported Distro."
fi

tee -a requirements.yml <<'EOF'
---
- src: dev-sec.ssh-hardening
- src: nginxinc.nginx
- src: geerlingguy.nginx
EOF

tee -a playbook.yml <<'EOF'
---
- name: "Provision Nginx"
hosts: localhost
- hosts: localhost
become: true
vars:
ssh_kex:
- [email protected]
- [email protected]
- diffie-hellman-group-exchange-sha256
- [email protected]
- [email protected]
- diffie-hellman-group-exchange-sha256
ssh_server_ports: ['22']
ssh_permit_root_login: "without-password"
ssh_use_pam: "true"
sshd_authenticationmethods: "publickey"
ssh_authorized_keys_file: ".ssh/authorized_keys"
roles:
- dev-sec.ssh-hardening
- nginxinc.nginx
become: true
tasks:
- name: Install Nginx
include_role:
name: geerlingguy.nginx
- name: SSH Hardening
include_role:
name: dev-sec.ssh-hardening
handlers:
- name: start nginx
service:
name: nginx
state: started
EOF

ansible-galaxy install -r requirements.yml
ansible-playbook playbook.yml

printf "<h1>Linode - It Works</h1>" >/usr/share/nginx/html/index.html
if [ -f /etc/debian_version ]; then
printf "<h1>DigitalOcean - It Works</h1>" > /var/www/html/index.nginx-debian.html
elif [ -f /etc/redhat-release ]; then
printf "<h1>DigitalOcean - It Works</h1>" > /usr/share/nginx/html/index.html
else
echo "Unsuported Distro."
fi

0 comments on commit d7b9bb0

Please sign in to comment.