Morales Digital Technologies Morales CodeHub
68 lines · 2.6 KB
1#!/bin/bash
2
3set -e
4
5RED='\033[0;31m'
6YELLOW='\033[1;33m'
7GREEN='\033[0;32m'
8LIGHT_BLUE='\033[1;34m'
9NC='\033[0m'
10
11prompt() {
12 local PROMPT_MESSAGE=$1
13 local DEFAULT_VALUE=$2
14 read -p "$PROMPT_MESSAGE [$DEFAULT_VALUE]: " INPUT
15 echo "${INPUT:-$DEFAULT_VALUE}"
16}
17
18confirm_clean_install() {
19 echo -e "${LIGHT_BLUE}=================================================================${NC}"
20 echo -e "${LIGHT_BLUE} phpMyAdmin Panel Installer v4.0 by VS-Shop${NC}"
21 echo -e "${LIGHT_BLUE}=================================================================${NC}"
22 echo -e "${YELLOW}This installation script requires a clean installation of Ubuntu 22.04.${NC}"
23 echo -e "${YELLOW}If you believe this is a clean installation, please confirm by replying 'Y(es)'.${NC}"
24 echo -e "${YELLOW}If it is not a clean installation, please reply 'N(o)' and reinstall the operating system.${NC}"
25 echo -e "${LIGHT_BLUE}=================================================================${NC}"
26
27 while true; do
28 read -p "Is this a clean installation of Ubuntu 22.04? (Y/N): " response
29 case $response in
30 [Yy]* ) break;;
31 [Nn]* ) echo -e "${RED}Please reinstall Ubuntu 22.04 and run the script again.${NC}"; exit;;
32 * ) echo -e "${RED}Please answer with 'Y' (Yes) or 'N' (No).${NC}";;
33 esac
34 done
35}
36
37confirm_clean_install
38
39echo -e "${YELLOW}Updating system...${NC}\n"
40sudo apt update && sudo apt upgrade -y
41
42echo -e "${YELLOW}Installing required packages...${NC}\n"
43sudo apt install -y apache2 mysql-server php php-mysql phpmyadmin
44
45echo -e "${YELLOW}Configuring phpMyAdmin...${NC}\n"
46sudo phpenmod mysqli
47sudo service apache2 restart
48
49MYSQL_ROOT_PASSWORD=$(prompt "Enter a password for MySQL root user" "root")
50
51echo -e "${YELLOW}Changing MySQL root authentication method to mysql_native_password...${NC}"
52
53sudo mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$MYSQL_ROOT_PASSWORD';" 2>/dev/null
54sudo mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "FLUSH PRIVILEGES;" 2>/dev/null
55
56sleep 2
57
58echo -e "${YELLOW}Configuring phpMyAdmin...${NC}"
59sudo sed -i "s/127.0.0.1/localhost/" /etc/phpmyadmin/config.inc.php
60
61SERVER_IP=$(hostname -I | awk '{for (i=1; i<=NF; i++) if ($i != "127.0.0.1") {print $i; exit}}')
62
63if [ $? -eq 0 ]; then
64 echo -e "${GREEN}phpMyAdmin was installed succesfully, and MySQL root password with authentication method updated! Your phpMyAdmin Access http://$SERVER_IP/phpmyadmin${NC}"
65else
66 echo -e "${RED}There was an error updating the MySQL root password.${NC}"
67fi
68