Files
ministra5610/install.sh
2024-10-18 13:19:26 +03:00

345 lines
13 KiB
Bash

#!/usr/bin/env bash
# Function to check the exit status of commands
check_exit_status() {
if [ $? -ne 0 ]; then
echo "Error: $1 failed."
exit 1
fi
}
# Version selection before the source question
while true; do
echo "Which version of Ministra do you want to install?"
read -p "Enter the version number (5.6.9 or 5.6.10): " version_choice
case $version_choice in
5.6.9 ) ministra_source="https://www.dropbox.com/scl/fi/u5hoam8xg19ho1gkclhfh/ministra-5.6.9.zip?rlkey=729t7k8q67tky7di4gbdp2a3s&st=txy3qete&dl=0"; break;;
5.6.10 )
while true; do
echo "From which source do you want to download and install?"
echo "Selection:"
echo "- Press \"i\" if you want to download from Informir"
echo "- Press \"w\" if you want to download from WorldOfIPTV"
read -p "Enter your choice (i/w): " choice
case $choice in
[Ii]* ) ministra_source="http://download.ministra.com/downloads/159934057961c4dfe9153ee02d7e3fb1/ministra-5.6.10.zip"; break;;
[Ww]* ) ministra_source="https://www.dropbox.com/scl/fi/lbpm76rw5puwmfforgqy7/ministra-5.6.10.zip?rlkey=ytychga8fglydbeq993bt2zwd&st=zb4o6442&dl=0"; break;;
* ) echo "Please enter a valid option (i or w)." ;;
esac
done
break;;
* ) echo "Please enter a valid version (5.6.9 or 5.6.10)." ;;
esac
done
echo ""
echo "###########################################"
echo ""
echo "Setting locales..."
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
check_exit_status "Setting locales"
echo "###########################################"
echo "Setting up PHP 7.0 Repository..."
sudo apt-get install -y software-properties-common
check_exit_status "Installing software-properties-common"
add-apt-repository ppa:ondrej/php -y
check_exit_status "Adding PHP repository"
echo "###########################################"
echo "Running Apt Update & Upgrade..."
apt-get update && apt-get upgrade -y
check_exit_status "Updating and upgrading packages"
echo "###########################################"
echo "Installing Initial Packages..."
apt-get install -y dialog net-tools wget git curl nano sudo unzip sl lolcat software-properties-common aview
check_exit_status "Installing initial packages"
echo "###########################################"
echo "Installing Nginx..."
apt-get install nginx nginx-extras -y
check_exit_status "Installing Nginx"
sudo systemctl stop nginx
echo "###########################################"
echo "Installing Apache2..."
apt-get install apache2 -y
check_exit_status "Installing Apache2"
sudo systemctl stop apache2
echo "###########################################"
echo "Installing Additional Packages..."
apt-get -y install php7.0-dev php7.0-mcrypt php7.0-intl php7.0-mbstring php7.0-zip memcached php7.0-memcache php7.0 php7.0-xml php7.0-gettext php7.0-soap php7.0-mysql php7.0-geoip php-pear nodejs libapache2-mod-php php7.0-curl php7.0-imagick php7.0-sqlite3 unzip
check_exit_status "Installing additional packages"
echo "###########################################"
echo "Changing PHP Version..."
update-alternatives --set php /usr/bin/php7.0
check_exit_status "Changing PHP version"
echo "###########################################"
echo "Installing Phing..."
# Check if the Phing channel is already initialized
if pear list-channels | grep -q "pear.phing.info"; then
echo "Phing channel is already initialized."
else
pear channel-discover pear.phing.info || echo "Warning: Unable to discover Phing channel. Continuing..."
fi
# Check if Phing is already installed
if pear list -a | grep -q "phing/phing"; then
echo "Phing is already installed."
else
pear install phing/phing-2.15.0 || echo "Warning: Installing Phing failed. Continuing..."
fi
echo "###########################################"
echo "Installing npm 2.5.11..."
apt-get install npm -y
check_exit_status "Installing npm"
npm config set strict-ssl false
npm install -g npm@2.15.11
check_exit_status "Installing npm package"
# Check if the symbolic link already exists
if [ -L /usr/bin/node ]; then
echo "The symbolic link '/usr/bin/node' already exists. Skipping link creation."
elif [ -e /usr/bin/node ]; then
echo "'/usr/bin/node' exists but is not a symbolic link. Please check manually."
else
ln -s /usr/bin/nodejs /usr/bin/node
check_exit_status "Creating symbolic link for node"
fi
echo "###########################################"
echo "Configuring Timezone..."
sudo ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime
check_exit_status "Configuring timezone"
sudo dpkg-reconfigure --frontend noninteractive tzdata
echo "###########################################"
echo "Installing MySQL Server ..."
# Ensure the socket directory exists
if [ ! -d /var/run/mysqld ]; then
echo "Creating directory for MySQL socket file..."
sudo mkdir -p /var/run/mysqld
fi
# Prompt the user to enter the MySQL root password twice
while true; do
read -s -p "Please enter a MySQL root password: " rootpass
echo
read -s -p "Please confirm the MySQL root password: " rootpass_confirm
echo
if [ "$rootpass" == "$rootpass_confirm" ]; then
echo "MySQL root password confirmed."
break
else
echo "Passwords do not match. Please try again."
fi
done
# Prompt the user to enter the Ministra MySQL user password twice
while true; do
read -s -p "Please enter a Ministra MySQL user password: " stalkerpass
echo
read -s -p "Please confirm the Ministra MySQL user password: " stalkerpass_confirm
echo
if [ "$stalkerpass" == "$stalkerpass_confirm" ]; then
echo "Ministra MySQL user password confirmed."
break
else
echo "Passwords do not match. Please try again."
fi
done
# Set up the MySQL server with the provided root password
export DEBIAN_FRONTEND="noninteractive"
echo "mysql-server mysql-server/root_password password $rootpass" | sudo debconf-set-selections
check_exit_status "Setting MySQL root password"
echo "mysql-server mysql-server/root_password_again password $rootpass" | sudo debconf-set-selections
check_exit_status "Confirming MySQL root password"
apt-get install -y mysql-server
check_exit_status "Installing MySQL Server"
echo "###########################################"
echo "Creating Ministra MySQL Users..."
# Step 1: Check if MySQL is running
if ! systemctl is-active --quiet mysql; then
echo "MySQL is not running. Starting MySQL service..."
sudo systemctl start mysql
check_exit_status "Starting MySQL service"
else
echo "MySQL is already running."
fi
# Step 2: Attempt to connect to MySQL with the provided root password
attempts=3
while [ $attempts -gt 0 ]; do
mysql -uroot -p"$rootpass" -e "exit"
if [ $? -eq 0 ]; then
echo "Successfully connected to MySQL."
break
else
echo "Failed to connect to MySQL. Possible reasons:"
echo "1. The MySQL root password may be incorrect."
echo "2. The MySQL root user may be configured with an authentication method that does not allow password access."
echo "3. The MySQL server may not be running or reachable."
# Try resetting the root password if access is denied
if [ $attempts -eq 3 ]; then
echo "Attempting to reset the MySQL root password..."
# Stop MySQL service
sudo systemctl stop mysql
# Start MySQL with skip-grant-tables
sudo mysqld_safe --skip-grant-tables &
sleep 5
# Reset the root password to use mysql_native_password
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '${rootpass}';"
if [ $? -eq 0 ]; then
echo "MySQL root password has been reset successfully."
sudo killall mysqld
sleep 5
sudo systemctl start mysql
continue
else
echo "Failed to reset MySQL root password. Please check manually."
exit 1
fi
fi
# Re-enter the MySQL root password
read -s -p "Re-enter the MySQL root password: " rootpass
echo
((attempts--))
if [ $attempts -eq 0 ]; then
echo "Error: Could not connect to MySQL after multiple attempts. Please check your MySQL configuration."
exit 1
fi
fi
done
# Proceed with creating the database and user if the connection is successful
mysql -uroot -p"$rootpass" -e "CREATE DATABASE IF NOT EXISTS stalker_db;"
mysql -uroot -p"$rootpass" -e "CREATE USER IF NOT EXISTS 'stalker'@'localhost' IDENTIFIED BY '${stalkerpass}';"
mysql -uroot -p"$rootpass" -e "GRANT ALL PRIVILEGES ON stalker_db.* TO 'stalker'@'localhost' WITH GRANT OPTION;"
mysql -uroot -p"$rootpass" -e "FLUSH PRIVILEGES;"
check_exit_status "Creating Ministra MySQL users"
echo "###########################################"
echo "Installing Ministra..."
cd /var/www/html/
wget $ministra_source
check_exit_status "Downloading Ministra"
# Check which version was downloaded and unzip accordingly
if [[ "$version_choice" == "5.6.9" ]]; then
unzip ministra-5.6.9.zip
rm -rf ministra-5.6.9.zip
elif [[ "$version_choice" == "5.6.10" ]]; then
unzip ministra-5.6.10.zip
rm -rf ministra-5.6.10.zip
fi
# Clean up and configure the installation
rm /var/www/html/index*
touch /var/www/html/index.php
echo '<?php' >> /var/www/html/index.php
echo 'header("Location:stalker_portal/c/");' >> /var/www/html/index.php
echo '?>' >> /var/www/html/index.php
echo "###########################################"
echo "Configuring PHP..."
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/7.0/apache2/php.ini
ln -s /etc/php/7.0/mods-available/mcrypt.ini /etc/php/8.1/mods-available/
sudo a2dismod mpm_event
sudo a2enmod php7.0
phpenmod mcrypt
a2enmod rewrite
check_exit_status "Configuring PHP"
sudo systemctl restart apache2
echo "###########################################"
echo "Setting up Apache2 Config File..."
cd /etc/apache2/sites-enabled/
rm -rf *
wget https://git.bitmaster.cc/BitMaster/ministra5610/raw/branch/main/000-default.conf
check_exit_status "Downloading Apache2 config file"
cd /etc/apache2/
rm -rf ports.conf
wget https://git.bitmaster.cc/BitMaster/ministra5610/raw/branch/main/ports.conf
check_exit_status "Downloading Apache2 ports config file"
echo "###########################################"
echo "Setting up Nginx Config File..."
cd /etc/nginx/sites-available/
rm -rf default
wget https://git.bitmaster.cc/BitMaster/ministra5610/raw/branch/main/default
check_exit_status "Downloading Nginx config file"
echo "###########################################"
echo "Restarting Apache2 & Nginx..."
sudo systemctl restart apache2
check_exit_status "Restarting Apache2"
sudo systemctl restart nginx
check_exit_status "Restarting Nginx"
echo "###########################################"
echo "Fixing Smart Launcher..."
mkdir -p /var/www/.npm
chmod 777 /var/www/.npm
echo "###########################################"
echo "Patching Composer..."
cd /var/www/html/stalker_portal/deploy
wget https://git.bitmaster.cc/BitMaster/ministra5610/raw/branch/main/composer_version_1.9.1.patch
check_exit_status "Downloading Composer patch"
patch build.xml < composer_version_1.9.1.patch
check_exit_status "Applying Composer patch"
rm composer_version_1.9.1.patch
echo "###########################################"
echo "Installing custom.ini..."
cd /var/www/html/stalker_portal/server
wget -O custom.ini https://git.bitmaster.cc/BitMaster/ministra5610/raw/branch/main/custom.ini
check_exit_status "Downloading custom.ini"
echo "###########################################"
echo "Running Phing..."
sed -i "s/mysql_pass = 1/mysql_pass = $stalkerpass/g" /var/www/html/stalker_portal/server/config.ini
sed -i "s/mysql -u root -p mysql/mysql -u root -p$rootpass mysql/g" /var/www/html/stalker_portal/deploy/build.xml
git config --global http.sslVerify "false"
cd /var/www/html/stalker_portal/deploy
sudo phing
check_exit_status "Running Phing"
git config --global --unset http.sslVerify
sed -i "s/mysql -u root -p$rootpass mysql/mysql -u root -p mysql/g" /var/www/html/stalker_portal/deploy/build.xml
echo "###########################################"
# Detect the server's local IP address
YOURIP=$(hostname -I | awk '{print $1}')
# Fetch the server's public IP address
PUBLICIP=$(curl -s ifconfig.me)
echo ""
echo "Installation Done!"
echo ""
echo ""
echo -e "\033[1;33m#####################################################"
echo -e "### Ministra local WebUI: http://$YOURIP/stalker_portal"
echo -e "### Ministra public WebUI: http://$PUBLICIP/stalker_portal"
echo -e "### User: admin"
echo -e "### Pass: 1"
echo -e "#####################################################\033[0m"