diff --git a/installers/db.bat b/installers/db.bat new file mode 100644 index 0000000..3e643f8 --- /dev/null +++ b/installers/db.bat @@ -0,0 +1,27 @@ +set "SQL_FILE_URL=https://github.com/aamitn/URLShortener/raw/master/create.sql" + +echo Waiting for MariaDB to start... +timeout /t 1 /nobreak + +cd mariadb-11.4.0-winx64/bin + +REM Run SQL commands using mysql command-line tool +mysql -u root -p1234qwer -e "CREATE DATABASE IF NOT EXISTS shortener;" + +REM Download SQL file +curl -LJO "%SQL_FILE_URL%" + +REM Run the SQL script +mysql -u root -p1234qwer < create.sql + +mysql -u root -p1234qwer -e "SHOW DATABASES;" +mysql -u root -p1234qwer -e "USE shortener" +mysql -u root -p1234qwer -e "SELECT * FROM shortener;" + + +REM Optionally, remove the downloaded SQL file +del create.sql + +echo Deployed Successfully... +start "" http://localhost:8080 +exit /b 0 \ No newline at end of file diff --git a/installers/install.bat b/installers/install.bat new file mode 100644 index 0000000..2b82328 --- /dev/null +++ b/installers/install.bat @@ -0,0 +1,91 @@ +@echo off + +setlocal enabledelayedexpansion + +REM Set Tomcat and URL variables +set "TOMCAT_VERSION=10.1.9" +set "TOMCAT_URL=https://archive.apache.org/dist/tomcat/tomcat-10/v%TOMCAT_VERSION%/bin/apache-tomcat-%TOMCAT_VERSION%-windows-x64.zip" +set "WAR_URL=https://github.com/aamitn/URLShortener/releases/download/WAR/shortener.war" +set "SQL_FILE_URL=https://github.com/aamitn/URLShortener/raw/master/create.sql" +set "SERVER_XML_URL=https://raw.githubusercontent.com/aamitn/URLShortener/master/server.xml" + +REM Function to download and extract Tomcat +:download_and_extract_tomcat +echo Downloading Tomcat... +curl -O "%TOMCAT_URL%" +PowerShell Expand-Archive "apache-tomcat-%TOMCAT_VERSION%-windows-x64.zip" -DestinationPath . +del "apache-tomcat-%TOMCAT_VERSION%-windows-x64.zip" + +REM Function to download the WAR file +:download_war_file +echo Downloading shortener.war... +curl -LJO "%WAR_URL%" + +REM Function to configure Tomcat and deploy the WAR file +:configure_and_deploy +echo Configuring and deploying... +copy shortener.war "apache-tomcat-%TOMCAT_VERSION%\webapps\" + +REM Downloading the server.xml file +echo Downloading server.xml... +curl -LJO "%SERVER_XML_URL%" + +REM Replace the existing server.xml with the downloaded one +echo Replacing server.xml... +copy /Y server.xml "apache-tomcat-%TOMCAT_VERSION%\conf\server.xml" + +REM Run Tomcat server using startup.bat +:run_tomcat +echo Running Tomcat server... +cd "apache-tomcat-%TOMCAT_VERSION%\bin" +call startup.bat +REM Wait for Tomcat to start (adjust sleep time as needed) +timeout /t 30 /nobreak +call shutdown.bat +timeout /t 2 /nobreak +call startup.bat +cd .. +cd .. + + + +REM Main Script Execution +if "%OS%"=="Windows_NT" ( + call :download_and_install_mariadb +) else ( + echo Unsupported operating system. + exit /b 1 +) + +echo Local deployment completed successfully! +exit /b 0 + +REM Function to download and install MariaDB +:download_and_install_mariadb +echo Downloading MariaDB installer... +curl -O "https://mirror.docker.ru/mariadb//mariadb-11.4.0/winx64-packages/mariadb-11.4.0-winx64.zip" + +echo Installing MariaDB... +PowerShell Expand-Archive "mariadb-11.4.0-winx64.zip" -DestinationPath . +del "mariadb-11.4.0-winx64.zip" + +cd mariadb-11.4.0-winx64/bin +cd.. +cd.. + +@echo SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234qwer');> init.txt + + + +REM Get the current directory +set "CURRENT_DIR=%CD%" + +start db.bat +cd mariadb-11.4.0-winx64/bin +REM Initialize DB +call mariadb-install-db.exe +REM Run MariaDB server with the init file +call mysqld.exe --console --init-file="%CURRENT_DIR%\\init.txt" + + + diff --git a/installers/install.sh b/installers/install.sh new file mode 100644 index 0000000..d7781cd --- /dev/null +++ b/installers/install.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Set Tomcat and URL variables +TOMCAT_VERSION="10.0.0-M15" +TOMCAT_URL="https://archive.apache.org/dist/tomcat/tomcat-10/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz" +WAR_URL="https://github.com/aamitn/URLShortener/releases/download/WAR/shortener.war" +SERVER_XML_CONTEXT="" +SQL_FILE_URL="https://github.com/aamitn/URLShortener/raw/master/create.sql" + +# Function to download and extract Tomcat +download_and_extract_tomcat() { + echo "Downloading Tomcat..." + curl -O "${TOMCAT_URL}" + tar -xzvf "apache-tomcat-${TOMCAT_VERSION}.tar.gz" + rm "apache-tomcat-${TOMCAT_VERSION}.tar.gz" +} + +# Function to download the WAR file +download_war_file() { + echo "Downloading shortener.war..." + curl -LJO "${WAR_URL}" +} + +# Function to configure Tomcat and deploy the WAR file +configure_and_deploy() { + echo "Configuring and deploying..." + # Copy the WAR file to Tomcat webapps directory + cp shortener.war apache-tomcat-${TOMCAT_VERSION}/webapps/ + + # Add Context to server.xml + echo "${SERVER_XML_CONTEXT}" >> apache-tomcat-${TOMCAT_VERSION}/conf/server.xml +} + +# Function to download and run MariaDB server and execute SQL file +download_and_configure_mariadb() { + echo "Downloading and configuring MariaDB..." + apt-get update + apt-get install -y mariadb-server + service mariadb start + sleep 10 + + # Set root password + mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('$ROOT_PASSWORD'); FLUSH PRIVILEGES;" + + # Create 'shortener' database + mysql -u root -p"$ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS shortener;" + + # Download SQL file + wget -O create.sql "$SQL_FILE_URL" + + # Run the SQL script + mysql -u root -p"$ROOT_PASSWORD" shortener < create.sql + + # Optionally, remove the downloaded SQL file + rm create.sql +} + +# Main Script Execution +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux specific commands + download_and_extract_tomcat + download_war_file + configure_and_deploy + download_and_configure_mariadb + +elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then + # Windows specific commands + echo "Windows is not currently supported for this script." + exit 1 + +else + echo "Unsupported operating system." + exit 1 + +fi + +echo "Local deployment completed successfully!" \ No newline at end of file diff --git a/out/artifacts/shortener_jar/shortener.jar b/out/artifacts/shortener_jar/shortener.jar index 90664cb..52909f8 100644 Binary files a/out/artifacts/shortener_jar/shortener.jar and b/out/artifacts/shortener_jar/shortener.jar differ