Initialer Import der Synology Scripts
This commit is contained in:
Executable
+280
@@ -0,0 +1,280 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
# Log file
|
||||
LOG_FILE="/var/log/ejbca_install.log"
|
||||
exec > >(tee -i $LOG_FILE)
|
||||
exec 2>&1
|
||||
|
||||
# State file
|
||||
STATE_FILE="/var/log/ejbca_install_state.log"
|
||||
|
||||
# Variables
|
||||
EJBCA_VERSION="r8.3.2"
|
||||
DB_NAME="ejbca"
|
||||
DB_USER="ejbcauser"
|
||||
DB_PASS="your_password"
|
||||
EJBCA_HOST="localhost"
|
||||
EJBCA_PORT="8080"
|
||||
ADMIN_PASSWORD="adminpassword"
|
||||
EJBCA_URL="https://github.com/Keyfactor/ejbca-ce/archive/refs/tags/${EJBCA_VERSION}/${EJBCA_VERSION}.zip"
|
||||
EJBCA_DIR="/opt/ejbca-ce-r8.3.2"
|
||||
|
||||
# Update state function
|
||||
update_state() {
|
||||
echo "$1" > $STATE_FILE
|
||||
}
|
||||
|
||||
# Read state function
|
||||
read_state() {
|
||||
if [ -f $STATE_FILE ]; then
|
||||
cat $STATE_FILE
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
# Hauptfunktion: Installation Prerequisites
|
||||
installation_prerequisites() {
|
||||
echo "Installation Prerequisites..."
|
||||
update_state "1"
|
||||
|
||||
# Subfunktion: System Update
|
||||
system_update
|
||||
|
||||
# Subfunktion: Install Utilities
|
||||
install_utilities
|
||||
}
|
||||
|
||||
system_update() {
|
||||
echo "Updating system..."
|
||||
sudo dnf update -y
|
||||
update_state "1.1"
|
||||
}
|
||||
|
||||
install_utilities() {
|
||||
echo "Installing utilities..."
|
||||
sudo dnf install -y epel-release wget unzip
|
||||
update_state "1.2"
|
||||
}
|
||||
|
||||
# Hauptfunktion: Managing EJBCA Configurations
|
||||
managing_ejbca_configurations() {
|
||||
echo "Managing EJBCA Configurations..."
|
||||
update_state "2"
|
||||
|
||||
# Subfunktion: Install Java
|
||||
install_java
|
||||
|
||||
# Subfunktion: Install Application Server
|
||||
install_application_server
|
||||
}
|
||||
|
||||
install_java() {
|
||||
echo "Installing Java..."
|
||||
sudo dnf install -y java-11-openjdk java-11-openjdk-devel
|
||||
java -version
|
||||
update_state "2.1"
|
||||
}
|
||||
|
||||
install_application_server() {
|
||||
echo "Installing Application Server..."
|
||||
sudo dnf install -y tomcat
|
||||
sudo systemctl start tomcat
|
||||
sudo systemctl enable tomcat
|
||||
update_state "2.2"
|
||||
}
|
||||
|
||||
# Hauptfunktion: Creating Database
|
||||
creating_database() {
|
||||
echo "Creating Database..."
|
||||
update_state "3"
|
||||
|
||||
# Subfunktion: Install MariaDB
|
||||
install_mariadb
|
||||
|
||||
# Subfunktion: Secure MariaDB
|
||||
secure_mariadb
|
||||
|
||||
# Subfunktion: Setup Database
|
||||
setup_database
|
||||
}
|
||||
|
||||
install_mariadb() {
|
||||
echo "Installing MariaDB..."
|
||||
sudo dnf install -y mariadb-server
|
||||
sudo systemctl start mariadb
|
||||
sudo systemctl enable mariadb
|
||||
update_state "3.1"
|
||||
}
|
||||
|
||||
secure_mariadb() {
|
||||
echo "Securing MariaDB installation..."
|
||||
sudo mysql_secure_installation <<EOF
|
||||
|
||||
Y
|
||||
${DB_PASS}
|
||||
${DB_PASS}
|
||||
Y
|
||||
Y
|
||||
Y
|
||||
Y
|
||||
EOF
|
||||
update_state "3.2"
|
||||
}
|
||||
|
||||
setup_database() {
|
||||
echo "Setting up EJBCA database..."
|
||||
sudo mysql -u root -p${DB_PASS} -e "CREATE DATABASE ${DB_NAME};"
|
||||
sudo mysql -u root -p${DB_PASS} -e "CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';"
|
||||
sudo mysql -u root -p${DB_PASS} -e "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost';"
|
||||
sudo mysql -u root -p${DB_PASS} -e "FLUSH PRIVILEGES;"
|
||||
update_state "3.3"
|
||||
}
|
||||
|
||||
# Hauptfunktion: Deploying EJBCA
|
||||
deploying_ejbca() {
|
||||
echo "Deploying EJBCA..."
|
||||
update_state "4"
|
||||
|
||||
# Subfunktion: Download EJBCA
|
||||
download_ejbca
|
||||
|
||||
# Subfunktion: Unzip EJBCA
|
||||
unzip_ejbca
|
||||
}
|
||||
|
||||
download_ejbca() {
|
||||
echo "Downloading EJBCA..."
|
||||
wget ${EJBCA_URL} -O ${EJBCA_VERSION}.zip
|
||||
update_state "4.1"
|
||||
}
|
||||
|
||||
unzip_ejbca() {
|
||||
echo "Unzipping EJBCA..."
|
||||
unzip ${EJBCA_VERSION}.zip -d /opt
|
||||
update_state "4.2"
|
||||
}
|
||||
|
||||
# Hauptfunktion: Installing EJBCA
|
||||
installing_ejbca() {
|
||||
echo "Installing EJBCA..."
|
||||
update_state "5"
|
||||
|
||||
# Subfunktion: Setup EJBCA
|
||||
setup_ejbca
|
||||
|
||||
# Subfunktion: Configure EJBCA
|
||||
configure_ejbca
|
||||
}
|
||||
|
||||
setup_ejbca() {
|
||||
echo "Setting up EJBCA..."
|
||||
cd ${EJBCA_DIR}
|
||||
./bin/ejbca.sh install
|
||||
update_state "5.1"
|
||||
}
|
||||
|
||||
configure_ejbca() {
|
||||
echo "Configuring EJBCA..."
|
||||
sudo cp conf/database.properties.sample conf/database.properties
|
||||
sudo sed -i "s/ejbcauser:ejbcauser_password@localhost:3306/${DB_USER}:${DB_PASS}@localhost:3306/" conf/database.properties
|
||||
update_state "5.2"
|
||||
}
|
||||
|
||||
# Hauptfunktion: Finalizing the Installation
|
||||
finalizing_the_installation() {
|
||||
echo "Finalizing the Installation..."
|
||||
update_state "6"
|
||||
|
||||
# Subfunktion: Deploy on Tomcat
|
||||
deploy_on_tomcat
|
||||
|
||||
# Subfunktion: Configure Firewall
|
||||
configure_firewall
|
||||
|
||||
# Subfunktion: Check Services
|
||||
check_services
|
||||
|
||||
# Subfunktion: Create Status File
|
||||
create_status_file
|
||||
}
|
||||
|
||||
deploy_on_tomcat() {
|
||||
echo "Deploying EJBCA on Tomcat..."
|
||||
sudo ./bin/ejbca.sh deploy tomcat
|
||||
sudo systemctl restart tomcat
|
||||
update_state "6.1"
|
||||
}
|
||||
|
||||
configure_firewall() {
|
||||
echo "Configuring firewall..."
|
||||
sudo firewall-cmd --zone=public --add-port=${EJBCA_PORT}/tcp --permanent
|
||||
sudo firewall-cmd --reload
|
||||
update_state "6.2"
|
||||
}
|
||||
|
||||
check_services() {
|
||||
echo "Checking Tomcat status..."
|
||||
sudo systemctl status tomcat
|
||||
|
||||
echo "Checking MariaDB status..."
|
||||
sudo systemctl status mariadb
|
||||
|
||||
update_state "6.3"
|
||||
}
|
||||
|
||||
create_status_file() {
|
||||
STATUS_FILE="/var/log/ejbca_install_status.txt"
|
||||
{
|
||||
echo "EJBCA Installation Status"
|
||||
echo "-------------------------"
|
||||
echo "Java version:"
|
||||
java -version
|
||||
echo "Tomcat status:"
|
||||
check_service_status tomcat
|
||||
echo "MariaDB status:"
|
||||
check_service_status mariadb
|
||||
echo "Firewall status:"
|
||||
check_port_status $EJBCA_PORT
|
||||
echo "Installation log:"
|
||||
cat $LOG_FILE
|
||||
} > $STATUS_FILE
|
||||
|
||||
echo "EJBCA has been installed and deployed. Access it at http://${EJBCA_HOST}:${EJBCA_PORT}/ejbca"
|
||||
echo "Use the password ${ADMIN_PASSWORD} for the WildFly management console."
|
||||
echo "Installation status saved to ${STATUS_FILE}"
|
||||
update_state "6.4"
|
||||
}
|
||||
|
||||
check_service_status() {
|
||||
local service=$1
|
||||
if systemctl is-active --quiet $service; then
|
||||
echo "$service is active."
|
||||
else
|
||||
echo "$service is not active."
|
||||
fi
|
||||
}
|
||||
|
||||
check_port_status() {
|
||||
local port=$1
|
||||
if sudo firewall-cmd --list-ports | grep -q $port; then
|
||||
echo "Port $port is open."
|
||||
else
|
||||
echo "Port $port is not open."
|
||||
fi
|
||||
}
|
||||
|
||||
# Main script execution based on state
|
||||
case $(read_state) in
|
||||
0) installation_prerequisites ;;
|
||||
1) managing_ejbca_configurations ;;
|
||||
2) creating_database ;;
|
||||
3) deploying_ejbca ;;
|
||||
4) installing_ejbca ;;
|
||||
5) finalizing_the_installation ;;
|
||||
6) echo "Installation is complete." ;;
|
||||
*) echo "Unknown state. Exiting." ;;
|
||||
esac
|
||||
Reference in New Issue
Block a user