Add files via upload

This commit is contained in:
Sebastian Palencsár
2025-01-22 09:13:20 +01:00
committed by GitHub
parent d5dca126a6
commit 5ecb235919
19 changed files with 821 additions and 2 deletions

68
lib/docker.sh Normal file
View File

@@ -0,0 +1,68 @@
#!/bin/bash
install_docker() {
log_info "Installing Docker..."
# Update package index and install prerequisites
handle_error sudo apt-get update
handle_error sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Add Docker's official GPG key
handle_error curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Add Docker's official APT repository
handle_error sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Update package index again
handle_error sudo apt-get update
# Install Docker CE
handle_error sudo apt-get install -y docker-ce
# Add user to the docker group
handle_error sudo usermod -aG docker "$NEW_USER"
case $DISTRO in
ubuntu|debian)
handle_error sudo apt-get install -y docker.io
;;
fedora)
handle_error sudo dnf install -y docker
;;
arch)
handle_error sudo pacman -S --noconfirm docker
;;
opensuse)
handle_error sudo zypper install -y docker
;;
*)
log_error "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
handle_error sudo systemctl enable docker
handle_error sudo systemctl start docker
# Configure Docker data directory
if [[ "$DOCKER_DATA_DIR" != "$DEFAULT_DOCKER_DATA_DIR" ]]; then
log_info "Configuring Docker data directory to $DOCKER_DATA_DIR..."
handle_error sudo mkdir -p "$DOCKER_DATA_DIR"
echo "{\"data-root\": \"$DOCKER_DATA_DIR\"}" | sudo tee /etc/docker/daemon.json > /dev/null
handle_error sudo systemctl restart docker
fi
export DOCKER_CONTENT_TRUST=1
log_info "Docker installed successfully."
log_info "Instructions for installing Docker in rootless mode:"
echo "1. Ensure required packages are installed: uidmap"
echo "2. Run Docker rootless installation script: curl -fsSL https://get.docker.com/rootless | sh"
echo "3. Set the following environment variables in your shell profile (e.g., ~/.bashrc):"
echo " export PATH=/usr/bin:\$PATH"
echo " export DOCKER_HOST=unix:///run/user/\$(id -u)/docker.sock"
echo "4. Start and enable Docker service in user mode:"
echo " systemctl --user start docker"
echo " systemctl --user enable docker"
echo "5. Enable linger for the user:"
echo " sudo loginctl enable-linger \$(whoami)"
}

66
lib/firewall.sh Normal file
View File

@@ -0,0 +1,66 @@
#!/bin/bash
# Function to set up firewall rules for Fedora
setup_firewall_fedora() {
echo "Setting up firewall for Fedora..."
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
echo "Firewall setup complete for Fedora."
}
# Function to set up firewall rules for Arch Linux
setup_firewall_arch() {
echo "Setting up firewall for Arch Linux..."
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
echo "Firewall setup complete for Arch Linux."
}
# Function to set up firewall rules for openSUSE
setup_firewall_opensuse() {
echo "Setting up firewall for openSUSE..."
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
echo "Firewall setup complete for openSUSE."
}
# Detect the operating system and call the appropriate function
if [ -f /etc/fedora-release ]; then
setup_firewall_fedora
elif [ -f /etc/arch-release ]; then
setup_firewall_arch
elif [ -f /etc/SuSE-release ]; then
setup_firewall_opensuse
else
echo "Unsupported operating system."
exit 1
fi
configure_firewall() {
log_info "Configuring firewall..."
# Allow SSH
ufw allow "${DEFAULT_SSH_PORT}/tcp"
# Allow Samba
ufw allow from any to any port 137,138 proto udp
ufw allow from any to any port 139,445 proto tcp
# Allow NFS
ufw allow from any to any port 2049 proto tcp
# Allow Netdata
ufw allow "${NETDATA_PORT}/tcp"
# Allow Docker
ufw allow 2375/tcp
ufw allow 2376/tcp
# Enable UFW
ufw --force enable
log_info "Firewall configuration completed."
}

11
lib/internet.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
check_internet_connection() {
log_info "Checking internet connection..."
if ping -c 1 google.com &> /dev/null; then
log_info "Internet connection is active."
else
log_error "No internet connection. Please check your network settings."
exit 1
fi
}

65
lib/jellyfin.sh Normal file
View File

@@ -0,0 +1,65 @@
#!/bin/bash
# Jellyfin installation and configuration script
log_info() {
echo "[INFO] $1"
}
log_error() {
echo "[ERROR] $1" >&2
}
handle_error() {
"$@"
local status=$?
if [ $status -ne 0 ]; then
log_error "Error with $1"
exit 1
fi
}
install_jellyfin() {
log_info "Installing Jellyfin..."
case $DISTRO in
ubuntu|debian)
handle_error sudo apt-get update
handle_error sudo apt-get install -y apt-transport-https software-properties-common
handle_error wget -O - https://repo.jellyfin.org/jellyfin_team.gpg.key | sudo apt-key add -
handle_error sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://repo.jellyfin.org/$(lsb_release -cs) main"
handle_error sudo apt-get update
handle_error sudo apt-get install -y jellyfin
;;
fedora)
handle_error sudo dnf install -y https://repo.jellyfin.org/releases/server/fedora/releases/jellyfin-server.rpm
;;
arch)
handle_error sudo pacman -S --noconfirm jellyfin
;;
opensuse)
handle_error sudo zypper addrepo https://repo.jellyfin.org/releases/server/opensuse/jellyfin.repo
handle_error sudo zypper refresh
handle_error sudo zypper install -y jellyfin
;;
*)
log_error "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
handle_error sudo systemctl enable jellyfin
handle_error sudo systemctl start jellyfin
log_info "Jellyfin installation completed."
}
# Detect the distribution and call the appropriate function
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
install_jellyfin
else
log_error "Cannot detect the operating system."
exit 1
fi

22
lib/logging.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
log_info() {
echo -e "${GREEN}[INFO] $1${NC}"
}
log_warning() {
echo -e "${YELLOW}[WARNING] $1${NC}"
}
log_error() {
echo -e "${RED}[ERROR] $1${NC}" >&2
}
backup_config() {
local config_file=$1
if [ -f "$config_file" ]; then
local backup_file="${config_file}.$(date +%F-%T).bak"
handle_error sudo cp "$config_file" "$backup_file"
log_info "Backup of $config_file created at $backup_file"
fi
}

19
lib/netdata.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# Netdata installation and configuration script
install_netdata() {
log_info "Installing Netdata..."
# Install dependencies
handle_error sudo apt-get update
handle_error sudo apt-get install -y curl git
# Install Netdata from GitHub
handle_error bash <(curl -Ss https://my-netdata.io/kickstart.sh) --stable-channel --disable-telemetry
handle_error sudo systemctl enable netdata
handle_error sudo systemctl start netdata
log_info "Netdata installation completed."
}

55
lib/network.sh Normal file
View File

@@ -0,0 +1,55 @@
#!/bin/bash
configure_network() {
log_info "Configuring network..."
local interface=$(ip route | awk '/default/ {print $5}')
local current_ip=$(ip addr show $interface | awk '/inet / {print $2}' | cut -d/ -f1)
read -p "Enter static IP address [$current_ip]: " static_ip
static_ip=${static_ip:-$current_ip}
read -p "Enter gateway IP: " gateway_ip
read -p "Enter DNS server IP: " dns_ip
backup_config "/etc/netplan/01-netcfg.yaml"
case $DISTRO in
ubuntu|debian)
cat <<EOL | sudo tee /etc/netplan/01-netcfg.yaml > /dev/null
network:
version: 2
renderer: networkd
ethernets:
$interface:
addresses: [$static_ip/24]
routes:
- to: default
via: $gateway_ip
nameservers:
addresses: [$dns_ip]
EOL
sudo netplan apply
;;
fedora|arch|opensuse)
cat <<EOL | sudo tee /etc/sysconfig/network-scripts/ifcfg-$interface > /dev/null
DEVICE=$interface
BOOTPROTO=none
ONBOOT=yes
IPADDR=$static_ip
PREFIX=24
GATEWAY=$gateway_ip
DNS1=$dns_ip
EOL
sudo systemctl restart NetworkManager
;;
*)
log_error "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
log_info "Network configuration applied."
}
# ...existing code...

24
lib/nfs.sh Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
install_nfs() {
log_info "Installing NFS..."
case $DISTRO in
ubuntu|debian)
handle_error sudo apt-get install -y nfs-kernel-server
;;
fedora)
handle_error sudo dnf install -y nfs-utils
;;
arch)
handle_error sudo pacman -S --noconfirm nfs-utils
;;
opensuse)
handle_error sudo zypper install -y nfs-kernel-server
;;
*)
log_error "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
log_info "NFS installation completed."
}

82
lib/portainer.sh Normal file
View File

@@ -0,0 +1,82 @@
#!/bin/bash
# portainer.sh - Script to install Portainer on various Linux distributions
# Function to install Portainer on Ubuntu
install_portainer_ubuntu() {
sudo apt-get update
sudo apt-get install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
}
# Function to install Portainer on Debian
install_portainer_debian() {
sudo apt-get update
sudo apt-get install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
}
# Function to install Portainer on Fedora
install_portainer_fedora() {
sudo dnf -y update
sudo dnf -y install docker
sudo systemctl start docker
sudo systemctl enable docker
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
}
# Function to install Portainer on Arch Linux
install_portainer_arch() {
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm docker
sudo systemctl start docker
sudo systemctl enable docker
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
}
# Function to install Portainer on openSUSE
install_portainer_opensuse() {
sudo zypper refresh
sudo zypper install -y docker
sudo systemctl start docker
sudo systemctl enable docker
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
}
# Main script logic to detect the distribution and call the appropriate function
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu)
install_portainer_ubuntu
;;
debian)
install_portainer_debian
;;
fedora)
install_portainer_fedora
;;
arch)
install_portainer_arch
;;
opensuse)
install_portainer_opensuse
;;
*)
echo "Unsupported distribution: $ID"
exit 1
;;
esac
else
echo "Cannot detect the operating system."
exit 1
fi

37
lib/security.sh Normal file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# Security configuration script
secure_shared_memory() {
log_info "Securing shared memory..."
handle_error sudo cp /etc/fstab /etc/fstab.bak
echo "tmpfs /run/shm tmpfs defaults,noexec,nosuid 0 0" | sudo tee -a /etc/fstab
handle_error sudo mount -o remount /run/shm
log_info "Shared memory secured."
}
install_fail2ban() {
log_info "Installing Fail2Ban..."
case $DISTRO in
ubuntu|debian)
handle_error sudo apt-get update
handle_error sudo apt-get install -y fail2ban
;;
fedora)
handle_error sudo dnf install -y fail2ban
;;
arch)
handle_error sudo pacman -S --noconfirm fail2ban
;;
opensuse)
handle_error sudo zypper install -y fail2ban
;;
*)
log_error "Unsupported Linux distribution: $DISTRO"
exit 1
;;
esac
handle_error sudo systemctl enable fail2ban
handle_error sudo systemctl start fail2ban
log_info "Fail2Ban installation completed."
}

0
lib/ufw.sh Normal file
View File

View File

@@ -0,0 +1,38 @@
#!/bin/bash
# unattended-upgrades.sh
# This script sets up unattended upgrades for various Linux distributions
set -e
DISTRO=$(lsb_release -is)
case "$DISTRO" in
Ubuntu|Debian)
echo "Setting up unattended upgrades for $DISTRO..."
sudo apt-get update
sudo apt-get install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
;;
Fedora)
echo "Setting up unattended upgrades for Fedora..."
sudo dnf install -y dnf-automatic
sudo systemctl enable --now dnf-automatic-install.timer
;;
"Arch Linux")
echo "Setting up unattended upgrades for Arch Linux..."
sudo pacman -Syu --noconfirm
sudo systemctl enable --now paccache.timer
;;
openSUSE)
echo "Setting up unattended upgrades for openSUSE..."
sudo zypper install -y yast2-online-update-configuration
sudo yast2 online_update_configuration
;;
*)
echo "Unsupported distribution: $DISTRO"
exit 1
;;
esac
echo "Unattended upgrades setup complete."

64
lib/vaultwarden.sh Normal file
View File

@@ -0,0 +1,64 @@
#!/bin/bash
# Vaultwarden installation and configuration script
install_vaultwarden() {
log_info "Installing Vaultwarden..."
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
else
echo "Unsupported OS"
exit 1
fi
case $OS in
ubuntu|debian)
sudo apt update
sudo apt install -y docker.io docker-compose
;;
fedora)
sudo dnf install -y docker docker-compose
;;
arch)
sudo pacman -Syu --noconfirm docker docker-compose
;;
opensuse)
sudo zypper install -y docker docker-compose
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
sudo systemctl start docker
sudo systemctl enable docker
mkdir -p ~/vaultwarden
cd ~/vaultwarden
cat <<EOF > docker-compose.yml
version: '3'
services:
vaultwarden:
image: vaultwarden/server:latest
container_name: vaultwarden
restart: unless-stopped
volumes:
- ./vw-data:/data
ports:
- 80:80
EOF
# Pull the Vaultwarden image
handle_error sudo docker pull vaultwarden/server:latest
# Create the Vaultwarden container
handle_error sudo docker run -d --name vaultwarden -v /vw-data/:/data/ -p 80:80 --restart always vaultwarden/server:latest
log_info "Vaultwarden installation completed."
}
install_vaultwarden