Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Upgrade Process... #584

Open
notAreYouScared opened this issue Sep 26, 2024 · 0 comments
Open

Better Upgrade Process... #584

notAreYouScared opened this issue Sep 26, 2024 · 0 comments
Labels
✨ feature New feature 🔴 hard Fairly difficult

Comments

@notAreYouScared
Copy link
Member

Currently, we just extract the update over the existing install, bad, very bad.

The proposed solution, Below is very basic and generated with AI....

#!/bin/sh

read -p "Enter the directory for the panel location [/var/www/pelican]: " install_dir
install_dir=${install_dir:-/var/www/pelican}

if [ ! -d "$install_dir" ]; then
  echo "Directory $install_dir does not exist. Exiting..."
  exit 1
fi

env_file="$install_dir/.env"

if [ ! -f "$env_file" ]; then
  echo "File $env_file does not exist. Exiting..."
  exit 1
fi

cd "$install_dir"
php artisan down
if [ $? -ne 0 ]; then
  echo "Failed to put the panel into maintenance mode."
  exit 1
fi
echo "Panel is now in maintenance mode."

db_connection=$(grep "^DB_CONNECTION=" "$env_file" | cut -d '=' -f 2)

if [ -z "$db_connection" ]; then
  echo "DB_CONNECTION not found in $env_file."
  exit 0
else
  echo "DB_CONNECTION is set to: $db_connection"

  read -p "Do you want to create a backup? (Y/n) [y]: " backup_confirm
  backup_confirm=${backup_confirm:-y}
  if [ "$backup_confirm" != "y" ]; then
    echo "Backup cancelled."
    php artisan up
    echo "Panel is out of maintenance mode."
    exit 0
  fi

  if [ "$db_connection" = "sqlite" ]; then
    db_database=$(grep "^DB_DATABASE=" "$env_file" | cut -d '=' -f 2)

    if [ -z "$db_database" ]; then
      echo "DB_DATABASE not found in $env_file."
      php artisan up
      echo "Panel is out of maintenance mode."
      exit 1
    else
      echo "DB_DATABASE is set to: $db_database"

      backup_dir="$install_dir/backup"
      mkdir -p "$backup_dir"

      cp "$install_dir/database/$db_database" "$backup_dir/$db_database.backup"
    fi
  fi

  backup_dir="$install_dir/backup"
  mkdir -p "$backup_dir"
  cp "$env_file" "$backup_dir/.env.backup"

  echo "Backup completed successfully."
fi

read -p "Do you want to delete all files and folders in $install_dir except the backup folder? (Y/n) [y]: " delete_confirm
delete_confirm=${delete_confirm:-y}
if [ "$delete_confirm" != "y" ]; then
  echo "Deletion cancelled."
  php artisan up
  echo "Panel is out of maintenance mode."
  exit 0
fi

find "$install_dir" -mindepth 1 -maxdepth 1 ! -name 'backup' -exec rm -rf {} +

echo "Deleted all files and folders in $install_dir except the backup folder."

echo "Downloading Files..."
curl -L https://github.com/pelican-dev/panel/releases/latest/download/panel.tar.gz | sudo tar -xzv -C "$install_dir"

echo "Setting Permissions"
cd $install_dir
chmod -R 755 storage/* bootstrap/cache

echo "Installing Composer"
composer install --no-dev --optimize-autoloader --no-interaction

echo "Restoring .env"
mv "$backup_dir/.env.backup" "$install_dir/.env"
if [ "$db_connection" = "sqlite" ]; then
  echo "Restoring sqlite database"  
  mv "$backup_dir/$db_database.backup" "$install_dir/database/$db_database"
fi

echo "Updating database"
php artisan migrate --seed --force

read -p "Enter the owner of the files (www-data, apache, nginx) [www-data]: " file_owner
file_owner=${file_owner:-www-data}

chown -R $file_owner:$file_owner "$install_dir"

php artisan queue:restart
php artisan up

echo "Panel is now live and out of maintenance mode."
echo "Deleting backup folder..."
rm -rf "$backup_dir"
echo "Panel Updated!"
exit 0
@lancepioch lancepioch added ✨ feature New feature 🔴 hard Fairly difficult and removed 📋Planned labels Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature New feature 🔴 hard Fairly difficult
Projects
None yet
Development

No branches or pull requests

2 participants