diff --git a/apps/cloudron-latest-offirepo b/apps/cloudron-latest-offirepo index c85c6505..11bc5598 100755 --- a/apps/cloudron-latest-offirepo +++ b/apps/cloudron-latest-offirepo @@ -1,30 +1,129 @@ #!/bin/bash + if [ -f "include/startup.sh" ]; then . include/startup.sh elif [ -f "../include/startup.sh" ]; then . ../include/startup.sh fi -rootDir=$(rootDir) +updateAndFinalize() { + local rootDir="$1" + local CWM_DOMAIN="$2" + + # Target directories and files + local html_target="/home/yellowtent/box/dashboard/dist/setupdns.html" + local js_target_dir="/home/yellowtent/box/dashboard/dist/js" + local js_target="${js_target_dir}/setupdns.js" + + # Check every if the directories and files exist + while [[ ! -d "/home/yellowtent/box/dashboard/dist" || ! -d "$js_target_dir" ]]; do + #echo "Waiting for Cloud-Ron's app directory..." + sleep 3 + done + + # Perform operations once the directories exist + echo "Cloud-Ron Directories found. Performing operations..." | log + + # Ensure target files do not exist before copying new ones + rm -rf "$html_target" + rm -rf "$js_target" + + # Copy new files from source to target locations + cp "${rootDir}/tweaks/extras/cloudron/setupdns.html" "$html_target" + cp "${rootDir}/tweaks/extras/cloudron/setupdns.js" "$js_target" + + # Replace placeholders in HTML and JS files + sed -i "s/CWMDOMAIN/${CWM_DOMAIN}/g" "$html_target" + sed -i "s/CWMDOMAIN/${CWM_DOMAIN}/g" "$js_target" + + echo "Setup DNS files have been updated." | log + + # Touchups + bash tweaks/motd-description-append + bash tweaks/cwm-description-autoconfig + + echo "Adding descriptions" | log + descriptionAppend "CloudRon Web UI: https://${CWM_DOMAIN}" + descriptionAppend "SSL will be configured after the first step." + + # Cleanup + echo "Cleaning up..." | log + sleep 5 + systemctl stop apache2 + apt-get purge apache2 apache2-utils apache2-bin apache2.2-common + rm -rf /etc/apache2 + apt-get autoremove -y + apt-get autoclean -y + + end_time=$(date +%s) + duration=$((end_time - start_time)) + echo "Installation completed in $duration seconds." | log + + tagScript success + exit 0 +} + +# Define variables +rootDir="$(rootDir)" +updateStatus="$rootDir/include/updateInstallStatus.sh" +LOG_PATH="/var/log/cloudron-setup.log" +WEB_PATH="/var/www/html" +HTML_PATH="/var/www/html/index.html" + +clear echo "Downloading and installing CloudRon" | log curlDownload https://cloudron.io/cloudron-setup chmod +x cloudron-setup -bash cloudron-setup -sleep 5 -rm -rf /home/yellowtent/box/dashboard/dist/setupdns.html -rm -rf /home/yellowtent/box/dashboard/dist/js/setupdns.html -cp $rootDir/tweaks/extras/cloudron/setupdns.html /home/yellowtent/box/dashboard/dist/setupdns.html -cp $rootDir/tweaks/extras/cloudron/setupdns.js /home/yellowtent/box/dashboard/dist/js/setupdns.js -sed -i "s/CWMDOMAIN/${CWM_DOMAIN}/g" /home/yellowtent/box/dashboard/dist/setupdns.html -sed -i "s/CWMDOMAIN/${CWM_DOMAIN}/g" /home/yellowtent/box/dashboard/dist/js/setupdns.js +# Run the Cloudron setup and tee the output to both stdout and the log file +if [ ! -f "$LOG_PATH" ]; then + touch "$LOG_PATH" +fi + +# Wait for App dir and replace files +echo "Starting listener for Cloud-Ron app dirs & DNS update..." | log +updateAndFinalize "$rootDir" "${CWM_DOMAIN}" & + +echo "Running CloudRon setup..." | log +start_time=$(date +%s) +echo Y | bash cloudron-setup | tee "$LOG_PATH" & + +# Define lists to hold log messages +declare -a pre_display_list=() +declare -A seen # associative array to track seen lines + +# Start tailing the log file and process lines as they come +while read line; do + # Locate the line to display + if [[ "$line" == *"==> "* ]]; then + if [[ "$line" == *"Pulling docker images"* ]]; then + line="Pulling docker images (Takes some time)..." + else + line="${line#*==> }" + fi + + # Clean the line from extras + line=$(echo "$line" | sed -e 's/installer://g' -e 's/start://g' -e 's/"$//' -e 's/ \+.*//') -echo "Adding descriptions" | log -descriptionAppend "CloudRon Web UI: https://${CWM_DOMAIN}" -descriptionAppend "SSL will be configured after the first step." + # Check if the line has been seen already + if [[ -z "${seen[$line]}" ]]; then + seen[$line]=1 + pre_display_list+=("$line") -tagScript success + "$updateStatus" "$HTML_PATH" -cp + for stage in "${pre_display_list[@]}"; do + # Remove all trailing dots first + cleaned_stage=$(echo "$stage" | sed 's/\.*$//') + + # Append exactly three dots + final_stage="${cleaned_stage}..." + + # Update the installation landing page + "$updateStatus" "$HTML_PATH" -ap "${final_stage}" + done + fi + fi +done < <(tail -f "$LOG_PATH") -exit 0 diff --git a/apps/redmine-4.2-offisrc-nginx b/apps/redmine-4.2-offisrc-nginx index e05c15e4..820ec4c4 100755 --- a/apps/redmine-4.2-offisrc-nginx +++ b/apps/redmine-4.2-offisrc-nginx @@ -46,7 +46,11 @@ EOF echo "Installing Bundle" | log cd $appPath -gem install bundler --no-document +gem install nokogiri -v 1.15.6 +gem install net-imap -v 0.3.7 +gem install rails -v 6.1.7.7 +gem install bundler -v 2.4.22 + bundle install --without development test postgresql sqlite bundle exec rake generate_secret_token RAILS_ENV=production bundle exec rake db:migrate diff --git a/apps/redmine-5.0-offisrc-nginx b/apps/redmine-5.0-offisrc-nginx index fa26892b..05680e70 100755 --- a/apps/redmine-5.0-offisrc-nginx +++ b/apps/redmine-5.0-offisrc-nginx @@ -46,7 +46,12 @@ EOF echo "Installing Bundle" | log cd $appPath -gem install bundler --no-document +# Components have been updated with time, for the bundler to work, these specific versions are required. +gem install nokogiri -v 1.15.6 +gem install net-imap -v 0.3.7 +gem install rails -v 6.1.7.7 +gem install bundler -v 2.4.22 + bundle install --without development test postgresql sqlite bundle exec rake generate_secret_token RAILS_ENV=production bundle exec rake db:migrate diff --git a/apps/redmine-5.1.1-offisrc-apache-rails-mysql-8.0 b/apps/redmine-5.1.1-offisrc-apache-rails-mysql-8.0 new file mode 100644 index 00000000..6b90f9cb --- /dev/null +++ b/apps/redmine-5.1.1-offisrc-apache-rails-mysql-8.0 @@ -0,0 +1,142 @@ +#!/bin/bash + +# Add this at the begining of all scripts. +if [ -f "include/startup.sh" ]; then + . include/startup.sh +elif [ -f "../include/startup.sh" ]; then + . ../include/startup.sh +fi + +replaceAdPass() { + changePassScript="$REPO_DIR/change_admin_password.rb" + echo "Writing password change script to $changePassScript..." + touch $changePassScript + cat <<_EOF_ > $changePassScript +#!/usr/bin/env ruby + +require_relative 'config/environment' +admin_user = User.where(admin: true).first + +if admin_user.nil? + puts "Admin user not found!" + exit 1 + +else + admin_user.password = ENV['NEW_ADMIN_PASSWORD'] + admin_user.password_confirmation = ENV['NEW_ADMIN_PASSWORD'] + admin_user.must_change_passwd = false + + if admin_user.save + puts "Password updated successfully." + + else + puts "Failed to update password: #{admin_user.errors.full_messages.join(", ")}" + exit 1 + end +end +_EOF_ + + # Replace default admin password + echo "Replacing default admin password..." + RAILS_ENV=production NEW_ADMIN_PASSWORD='${ADMINPASSWORD}' rails runner $changePassScript + + echo "Removing $changePassScript..." + rm -f $changePassScript + +} + +# Variables +DB_REDMINE_PASS="redmine" +REPO_URL="https://www.redmine.org/releases/redmine-5.1.1.tar.gz" +REPO_DIR="/opt/redmine" +WEBAPP_CONF="/etc/apache2/sites-available" + +# Update system and install required packages +apt-get update && apt-get upgrade -y +apt-get install -y libmysqlclient-dev apt-transport-https + +# Secure MySQL and set up Redmine database +mysql --user=root <<_EOF_ +DELETE FROM mysql.user WHERE User=''; +CREATE DATABASE redmine CHARACTER SET utf8mb4; +CREATE USER 'redmine'@'localhost' IDENTIFIED BY '${DB_REDMINE_PASS}'; +GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost'; +FLUSH PRIVILEGES; +_EOF_ + +# Install Redmine +mkdir -p ${REPO_DIR} +curl -s ${REPO_URL} | sudo tar xz -C ${REPO_DIR} --strip-components=1 + +# Configuring permissions +echo "Configuring permissions..." +chown -R www-data:www-data /opt/redmine/ + +cd ${REPO_DIR} +# Configure database connection +cat <<_EOF_ > ${REPO_DIR}/config/database.yml +production: + adapter: mysql2 + database: redmine + host: localhost + username: redmine + password: "${DB_REDMINE_PASS}" + encoding: utf8mb4 +_EOF_ + +# Install gems +gem install bundler +bundle config set --local without 'development test' +bundle install + +# Prepare the database +bundle exec rake generate_secret_token +RAILS_ENV=production bundle exec rake db:migrate +RAILS_ENV=production REDMINE_LANG=en bundle exec rake redmine:load_default_data + +# Install ImageMagic for Redmine +echo "Installing ImageMagic & ghostscript..." +apt update +apt install -y imagemagick libmagickwand-dev +convert -version +apt install -y ghostscript + +#replaceAdPass +echo "Writing apache configuration file..." +cat <<_EOF_ > $WEBAPP_CONF/redmine.conf + + ServerName _ + DocumentRoot ${REPO_DIR}/public + + Allow from all + Options -MultiViews + Require all granted + + + + + + ServerName _ + DocumentRoot ${REPO_DIR}/public + + SSLEngine on + SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt + SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key + + + Allow from all + Options -MultiViews + Require all granted + + + +_EOF_ + + +# Enable Redmine site, disable default site +echo "Enabling redmine site & disabling defaults..." +a2ensite redmine +a2dissite installProgress +systemctl reload apache2 + +echo "Redmine installation is complete." diff --git a/include/Logos/CloudRon_logo.png b/include/Logos/CloudRon_logo.png new file mode 100644 index 00000000..097e6d6b Binary files /dev/null and b/include/Logos/CloudRon_logo.png differ diff --git a/include/Logos/Redmine_icon.png b/include/Logos/Redmine_icon.png new file mode 100644 index 00000000..a674000d Binary files /dev/null and b/include/Logos/Redmine_icon.png differ diff --git a/include/Logos/Redmine_logo.png b/include/Logos/Redmine_logo.png new file mode 100644 index 00000000..1947e28b Binary files /dev/null and b/include/Logos/Redmine_logo.png differ diff --git a/include/OMC_logo.png b/include/OMC_logo.png new file mode 100644 index 00000000..ca1e3b1f Binary files /dev/null and b/include/OMC_logo.png differ diff --git a/include/index.html b/include/index.html new file mode 100644 index 00000000..ac9e680c --- /dev/null +++ b/include/index.html @@ -0,0 +1,167 @@ + + + + + + + + + + +
+
+ Company Logo +
+
+

+
+
+
+
+ + +
+ + + + diff --git a/include/installInProgressHttpd-Redmine b/include/installInProgressHttpd-Redmine new file mode 100644 index 00000000..1f709ec1 --- /dev/null +++ b/include/installInProgressHttpd-Redmine @@ -0,0 +1,39 @@ +#!/bin/bash + +# Add this at the begining of all scripts. +if [ -f "include/startup.sh" ]; then + . include/startup.sh +elif [ -f "../include/startup.sh" ]; then + . ../include/startup.sh +fi + +WEB_PATH="/var/www/html" +if [ ! -d "$WEB_PATH" ]; then + echo "$WEB_PATH does not exists. Creating directory..." + mkdir -p "$WEB_PATH" +fi + +if [ -f "$WEB_PATH/redmine.conf" ]; then + echo "redmine.conf file exists. Skipping." | log + tagScript success + exit 99 +fi + +echo "Updating header..." +updateStatus="include/updateInstallStatus.sh" +html_file="$WEB_PATH/index.html" + +LOGO_IMG_ROOT="include/Logos" +LOGO_IMG_NAME="Redmine_logo.png" +LOGO_IMG_ROOT_PATH="$LOGO_IMG_ROOT/$LOGO_IMG_NAME" + +# Copy CloudRon logo +cp -r "$LOGO_IMG_ROOT_PATH" "$WEB_PATH/$LOGO_IMG_NAME" +chmod 644 "$WEB_PATH/$LOGO_IMG_NAME" + +"$updateStatus" "$html_file" -ui "$LOGO_IMG_NAME" +"$updateStatus" "$html_file" -uh "Please wait. Installing Redmine 5.1.1" +"$updateStatus" "$html_file" -ap "Installing dependencies (this stage takes time)..." + +tagScript success +exit 0 diff --git a/include/installInProgressHttpd-apache b/include/installInProgressHttpd-apache new file mode 100644 index 00000000..5e617929 --- /dev/null +++ b/include/installInProgressHttpd-apache @@ -0,0 +1,47 @@ +#!/bin/bash + +# Add this at the begining of all scripts. +if [ -f "include/startup.sh" ]; then + . include/startup.sh +elif [ -f "../include/startup.sh" ]; then + . ../include/startup.sh +fi + +echo "Installing Figlet..." +apt update && apt install -y figlet + +appPath="/etc/apache2/sites-available" +if [ ! -d "$appPath" ]; then + echo "$appPath does not exists. Creating directory..." + mkdir -p $appPath +fi +touch $appPath/index.html + +figletApp=$(which figlet) + +if [ ! -d "$appPath" ]; then + echo "Web server directory doesn't exist, exiting." | log 1 + exit 1 +fi + +if [ -f "$appPath/redmine.conf" ]; then + echo "redmine.conf file exists. Skipping." | log + tagScript success + exit 99 +fi + +if [ -z "$figletApp" ]; then + echo "Figlet is not installed, please install figlet." | log 1 + exit 1 +fi + +echo "Adding 'Install in Progress' notice to $appPath/index.html" | log +echo "Installation Progress
" > "$appPath/index.html"
+$figletApp "Install in Progress" >> "$appPath/index.html"
+echo "Please Wait. Application and services installation is in progress, the process will take a couple of minutes to complete. Thank you for your patience." >> "$appPath/index.html"
+echo "Installing dependencies..." >> "$appPath/index.html"
+echo "" >> "$appPath/index.html"
+echo "
" >> "$appPath/index.html" + +tagScript success +exit 0 diff --git a/include/updateInstallStatus.sh b/include/updateInstallStatus.sh new file mode 100644 index 00000000..027b2850 --- /dev/null +++ b/include/updateInstallStatus.sh @@ -0,0 +1,189 @@ +#!/bin/bash + +show_help() { + echo "Usage: $0 [html_file] [action] [content]" + echo "Actions:" + echo " -uh, update_heading - Updates the content of the

element in the specified HTML file." + echo " -ap, add_paragraph - Adds new paragraphs to the end of the
. Each new line in 'content' will be a new paragraph." + echo " -rp, replace_paragraphs - Replaces all existing paragraphs in
with new ones. Each new line in 'content' will be a new paragraph." + echo " -cp, clear_paragraphs - Clears all paragraphs from
." + echo " -ui, update_image - Updates the source of the logo image in the specified HTML file." + echo " -ut, update_title - Updates the content of the element in the specified HTML file." + echo " -uf, update_favicon - Updates the href of the <link rel='icon'> tag in the specified HTML file." + echo " -uc, update_credentials - Updates the credentials in the credentials container." + echo " -hc, hide_credentials - Hides the credentials container." + echo " -sc, show_credentials - Shows the credentials container." + echo " -hr, hide_redirect - Hides the redirect container." + echo " -sr, show_redirect - Shows the redirect container." + echo " -ur, update_redirect - Updates the content of the #redirection div." + echo "" + echo "Arguments:" + echo " html_file - Path to the HTML file to be modified." + echo " action - Action to perform (update_heading, add_paragraph, replace_paragraphs, clear_paragraphs, update_image, update_title, update_favicon, update_credentials, hide_credentials, show_credentials, hide_redirect, show_redirect, update_redirect, update_interval)." + echo " content - Content to update in the HTML file, dependent on the action. Not needed for clear_paragraphs, hide_credentials, show_credentials, hide_redirect, show_redirect." + echo "" + echo "Examples:" + echo " $0 /path/to/file.html -uh \"New Page Title\"" + echo " $0 /path/to/file.html -ap \"This is the first paragraph.\nThis is the second paragraph.\"" + echo " $0 /path/to/file.html -rp \"First new paragraph.\nSecond new paragraph.\"" + echo " $0 /path/to/file.html -cp" + echo " $0 /path/to/file.html -ui \"new_logo.png\"" + echo " $0 /path/to/file.html -ut \"New Title\"" + echo " $0 /path/to/file.html -uf \"new_favicon.ico\"" + echo " $0 /path/to/file.html -uc \"Default username: admin\nDefault password: password\"" + echo " $0 /path/to/file.html -hc" + echo " $0 /path/to/file.html -sc" + echo " $0 /path/to/file.html -hr" + echo " $0 /path/to/file.html -sr" + echo " $0 /path/to/file.html -ur \"You will be redirected in 10 seconds.\"" + echo "" + echo "Options:" + echo " -h, --help - Display this help message and exit." +} + +# Check for necessary arguments +if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$#" -lt 3 ] && [ "$2" != "-cp" ] && [ "$2" != "-ui" ] && [ "$2" != "-uf" ] && [ "$2" != "-hc" ] && [ "$2" != "-sc" ] && [ "$2" != "-hr" ] && [ "$2" != "-sr" ]; then + show_help + exit 1 +fi + +HTML_FILE="$1" +ACTION="$2" +CONTENT="${3-}" + +# Function to update the title +update_title() { + sed -i "s|<title>.*|$CONTENT|" "$HTML_FILE" +} + +# Function to update the heading +update_heading() { + sed -i "s|

.*

|

$CONTENT

|" "$HTML_FILE" +} + +# Function to add a new paragraph for each line of the input +add_paragraph() { + while IFS= read -r line; do + if [ -n "$line" ]; then + sed -i "/
/a \

$line

" "$HTML_FILE" + fi + done <<< "$(echo -e "$CONTENT")" +} + +# Function to replace all paragraphs with new ones +replace_paragraphs() { + sed -i "/
/,/<\/div>/ { /

.*<\/p>/d; }" "$HTML_FILE" + while IFS= read -r line; do + if [ -n "$line" ]; then + sed -i "/

/a \

$line

" "$HTML_FILE" + fi + done <<< "$(echo -e "$CONTENT")" +} + +# Function to clear all paragraphs +clear_paragraphs() { + sed -i "/
/,/<\/div>/ { /

.*<\/p>/d; }" "$HTML_FILE" +} + +# Function to update the logo image source +update_logo_img() { + sed -i "/

/,/<\/div>/ s|||" "$HTML_FILE" +} + +# Function to update the credentials +update_credentials() { + sed -i "/
/,/<\/div>/ { /

.*<\/p>/d; }" "$HTML_FILE" + # Reverse the order of lines before adding them + while IFS= read -r line; do + lines="$line"$'\n'"$lines" + done <<< "$(echo -e "$CONTENT")" + while IFS= read -r line; do + if [ -n "$line" ]; then + sed -i "/

/a \

$line

" "$HTML_FILE" + fi + done <<< "$lines" +} + +# Function to hide the credentials container +hide_credentials() { + sed -i 's|
|