Browse Source

Install fixes for DB

pull/21/head
pb 3 days ago
parent
commit
8e4854d74d
4 changed files with 62 additions and 54 deletions
  1. 39
    39
      i.lin.sh
  2. 4
    4
      i.sqlexpress.sh
  3. 8
    6
      load.mysql.sh
  4. 11
    5
      load.sqlexpress.sh

+ 39
- 39
i.lin.sh View File

@@ -15,16 +15,16 @@ if [ -f /etc/os-release ]; then
OS_NAME=$NAME
fi

# Function to check the OS type
# Function to check if the OS is CentOS or CentOS Stream
is_centos() {
# Check if the OS is CentOS
# Check if the OS is CentOS or CentOS Stream
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$NAME" == "CentOS Linux" ]] || [[ "$NAME" == "CentOS" ]]; then
return 0 # It's CentOS
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$NAME" == "CentOS Stream" ]]; then
return 0 # It's CentOS or CentOS Stream
fi
fi
return 1 # Not CentOS
return 1 # Not CentOS or CentOS Stream
}

# Set ROOT directory
@@ -37,7 +37,6 @@ else
GROUP_NAME="wheel" # CentOS/RHEL typically use 'wheel'
fi


# Trim whitespace from both current_user and username
current_user=$(echo "$current_user" | xargs)
username=$(echo "$username" | xargs)
@@ -148,25 +147,23 @@ sudo chown -R $USER:$USER $ROOT
cd $ROOT || { echo "Failed to change to ROOT directory $ROOT"; exit 1; }
echo $PWD

# Only run this block if it's CentOS or CentOS Stream
# if is_centos; then
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$NAME" == "CentOS" ]]; then
echo "This is CentOS Running CentOS specific script..."

# Only run this block if it's CentOS
if is_centos; then
echo "This is CentOS. Running CentOS specific script..."

# Download and run CentOS-specific script
wget -q -O - http://git.bbh/chess/elxr/raw/branch/master/centosinit.sh > $ROOT/centosinit.sh
sudo chmod u+x $ROOT/centosinit.sh
sh $ROOT/centosinit.sh
else
echo "This is not CentOS. Skipping CentOS-specific setup."
fi

# Platform-specific installation
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME=$NAME
OS_VERSION=$VERSION_ID
fi
# Download and run CentOS-specific script
wget -q -O - http://git.bbh/chess/elxr/raw/branch/master/centosinit.sh > $ROOT/centosinit.sh
sudo chmod u+x $ROOT/centosinit.sh
sh $ROOT/centosinit.sh
fi
fi
# else
# echo "This is not CentOS. Skipping CentOS-specific setup."
# fi

# Function to check if a package is installed
is_package_installed() {
@@ -184,8 +181,8 @@ install_package() {
if [ "$OS_NAME" == "Ubuntu" ] || [ "$OS_NAME" == "Debian" ]; then
sudo apt update
sudo apt install -y $package || { echo "Failed to install $package"; exit 1; }
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
# Prefer dnf for CentOS 8 and above
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS Stream" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
# Prefer dnf for CentOS Stream
if command -v dnf &>/dev/null; then
sudo dnf install -y $package || { echo "Failed to install $package"; exit 1; }
else
@@ -216,18 +213,25 @@ else

# Install Python 2 if not installed
if ! is_package_installed "python2"; then
install_package "python2"
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$NAME" == "Ubuntu" ]]; then
install_package "python2"
fi
fi
fi

# Install build tools based on OS type
if [ "$OS_NAME" == "Ubuntu" ] || [ "$OS_NAME" == "Debian" ]; then
install_package "build-essential"
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS Stream" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
install_package "gcc"
install_package "make"
install_package "glibc-devel"
install_package "gcc-c++"
fi
fi

# Install NVM (Node Version Manager)
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
@@ -253,7 +257,6 @@ command -v nvm

# Install code editor (VSCode)
if [[ "$OS_NAME" == "Ubuntu" ]] || [[ "$OS_NAME" == "Debian" ]]; then
# VSCode installation for Debian-based systems (Ubuntu/Debian)
install_package "wget"
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
@@ -262,31 +265,28 @@ command -v nvm
sudo apt install apt-transport-https
sudo apt update
sudo apt install code -y
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
# VSCode installation for CentOS-based systems (CentOS 8 / RHEL)
elif [[ "$OS_NAME" == "CentOS Stream" ]] || [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf check-update
sudo dnf install code -y
fi
fi

# Install OpenJDK 11 (Java) for both Debian/Ubuntu and CentOS/RHEL systems
if [ "$OS_NAME" == "Ubuntu" ] || [ "$OS_NAME" == "Debian" ]; then
install_package "openjdk-11-jre-headless"
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
# Install Java 11 on CentOS/RHEL-based systems
elif [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
# [[ "$OS_NAME" == "CentOS Stream" ]] || -- skip java for centos stream
sudo dnf install java-11-openjdk -y || { echo "Failed to install Java 11"; exit 1; }
fi

# MySQL Installation for CentOS (without debconf-set-selections)
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS" ]] || [[ "$OS_NAME" == "Red Hat" ]]; then
# MySQL Installation for CentOS Stream
if [[ "$OS_NAME" == "CentOS Linux" ]] || [[ "$OS_NAME" == "CentOS Stream" ]]; then
sudo dnf install mysql-server -y
sudo systemctl start mysqld
sudo systemctl enable mysqld
MYSQL_ROOT_PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log | tail -n 1 | awk '{print $NF}')
echo "MySQL root temporary password: $MYSQL_ROOT_PASSWORD"
# Secure MySQL installation
sudo mysql_secure_installation
else
# If on Ubuntu/Debian, you can use debconf-set-selections
@@ -301,7 +301,7 @@ fi
git clone $REPOSERVER/$REPOOWNER/bbhverse
cd bbhverse
npm i
cd ..
cd ..
git clone $REPOSERVER/$REPOOWNER/serververse
git clone $REPOSERVER/$REPOOWNER/global-this
git clone $REPOSERVER/$REPOOWNER/elxr.git
@@ -336,7 +336,7 @@ echo "Setup completed successfully!"
# ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'cihsr';
# FLUSH PRIVILEGES;

bash elxr/load.mysql.init.sh
bash elxr/mysql.init.sh
bash elxr/load.mysql.sh
bash elxr/i.sqlexpress.sh
bash elxr/load.sqlexpress.sh

+ 4
- 4
i.sqlexpress.sh View File

@@ -69,7 +69,7 @@ install_sqlserver_centos() {
sudo rm -f /etc/yum.repos.d/mssql-server.repo

# Add Microsoft SQL Server repository for CentOS using wget
wget -qO /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2022.repo
sudo wget -qO /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/8/mssql-server-2022.repo

# Clean all dnf caches and make a new one
sudo dnf clean all
@@ -89,7 +89,7 @@ install_sqlserver_centos() {
sudo firewall-cmd --reload

# (Optional) Install SQL Server command-line tools
wget -qO https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
wget -qO- https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
sudo yum remove -y mssql-tools unixODBC-utf16 unixODBC-utf16-devel
sudo yum install -y mssql-tools18 unixODBC-devel
sudo dnf install -y msodbcsql18
@@ -99,14 +99,14 @@ install_sqlserver_centos() {
source ~/.bash_profile

# Verify installation
sqlcmd --version
sqlcmd -?
}

# Check the OS type and call appropriate function
if [[ "$OS_NAME" == "Ubuntu" || "$OS_NAME" == "Debian" ]]; then
echo "Installing Microsoft SQL Server on Ubuntu..."
install_sqlserver_ubuntu
elif [[ "$OS_NAME" == "CentOS" || "$OS_NAME" == "Red Hat" || "$OS_NAME" == "Fedora" ]]; then
elif [[ "$OS_NAME" == "CentOS Linux" || "$OS_NAME" == "Red Hat" || "$OS_NAME" == "Fedora" ]]; then
echo "Installing Microsoft SQL Server on CentOS..."
install_sqlserver_centos
else

+ 8
- 6
load.mysql.sh View File

@@ -9,7 +9,6 @@ echo "Enter instance name (default: $DEFAULT_INSTANCENAME):"
read instancename
INSTANCENAME=${instancename:-$DEFAULT_INSTANCENAME}


# Prompt for the database name with a default value
read -p "Enter the database name (default: cihsr): " DB_NAME
DB_NAME=${DB_NAME:-$INSTANCENAME}
@@ -26,8 +25,9 @@ fi
# MySQL user credentials
MYSQL_USER="root"

# Check if the database exists
DB_EXISTS=$(mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES LIKE '$DB_NAME';")
# Checking if the database exists
echo "Checking if the database exists..."
DB_EXISTS=$(mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES LIKE '$DB_NAME';" -s -N)

if [[ -z "$DB_EXISTS" ]]; then
# Database does not exist, create it
@@ -40,12 +40,14 @@ TEMP_SQL_FILE=$(mktemp)
sed "s/{{DB_NAME}}/$DB_NAME/g" "$SQL_FILE" > "$TEMP_SQL_FILE"

# Run the SQL script with the provided database name
echo "Running the SQL script to create the schema..."
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $DB_NAME < "$TEMP_SQL_FILE"

# Clean up the temporary file
rm "$TEMP_SQL_FILE"

mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $DB_NAME < $SQL_FILE -- Create Schema
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $DB_NAME < $DB_NAME.sql -- Load data
# Run additional SQL files if any
echo "Loading data into the database..."
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $DB_NAME < "$INSTANCENAME-data/$DB_NAME.sql"

echo "SQL script executed successfully on database $DB_NAME"
echo "SQL script executed successfully on database $INSTANCENAME-data/$DB_NAME"

+ 11
- 5
load.sqlexpress.sh View File

@@ -4,17 +4,23 @@
read -sp "Enter MySQL root password: " MYSQL_PASSWORD
echo # Newline after password input

# Prompt for the database name (default: elixir)
DEFAULT_INSTANCENAME="elixir"
echo "Enter instance name (default: $DEFAULT_INSTANCENAME):"
read instancename
INSTANCENAME=${instancename:-$DEFAULT_INSTANCENAME}


# Prompt for the database name with a default value
read -p "Enter the database name (default: cihsr): " DB_NAME
read -p "Enter the database name (default: $INSTANCENAME): " DB_NAME
DB_NAME=${DB_NAME:-$INSTANCENAME}

# Copy the backup file to /tmp
cp /home/elvt/pgsys/$INSTANCENAME-data/dbdumps/reduced_${DB_NAME}_backup /tmp

# Restore the database
sqlcmd -S localhost -U sa -Q "RESTORE DATABASE $DB_NAME FROM DISK = '/tmp/reduced_${DB_NAME}_backup' WITH MOVE '$DB_NAME' TO '/var/opt/mssql/data/$DB_NAME.mdf', MOVE '${DB_NAME}_log' TO '/var/opt/mssql/data/$DB_NAME_log.ldf'"

# Clean up by removing the backup file from /tmp
rm /tmp/reduced_${DB_NAME}_backup

cp /home/elvt/pgsys/$INSTANCENAME-data/dbdumps/reduced_$INSTANCENAME_backup' /tmp
sqlcmd -S localhost -U sa -Q "RESTORE DATABASE ELIXIR FROM DISK = '/tmp/reduced_$INSTANCENAME_backup' WITH MOVE 'Elixir' TO '/var/opt/mssql/data/$INSTANCENAME.mdf', MOVE '$INSTANCENAME_log' TO '/var/opt/mssql/data/$INSTANCENAME_log.ldf'"
rm /tmp/reduced_$INSTANCENAME_backup
echo "Database restore for '$DB_NAME' completed successfully."

Loading…
Cancel
Save