Skip to content

Commit

Permalink
feat: Add --update and --version option to install.sh (#43)
Browse files Browse the repository at this point in the history
* Fix null keyboard and photo url in notification

* Add --update option to install.sh

* Add --version option to install.sh

* Extract files with overwrite in install.sh

* Update README.md

* Add help to release.yml
  • Loading branch information
eloravpn authored Nov 6, 2024
1 parent dc64fae commit c4d634a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 24 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ jobs:
fi
# Create changelog content with sections
## For features
# git commit -m "feat: Add new feature"
# git commit -m "add: New component"
#
## For bug fixes
# git commit -m "fix: Resolve issue"
# git commit -m "hotfix: Critical fix"
#
## For improvements
# git commit -m "improve: Better performance"
# git commit -m "update: Enhanced feature"
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "### Changelog" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ curl -fsSL https://raw.githubusercontent.com/eloravpn/EloraVPNManager/main/insta
| `--db-user` | PostgreSQL user name | elora |
| `--db-pass` | PostgreSQL password | Random generated |
| `--jwt-secret` | JWT secret key | Random generated |
| `--version` | Specific version to install | Latest version |


### Domain/IP Configuration
Expand Down Expand Up @@ -486,10 +487,15 @@ If you encounter any issues:
- Default database user has limited permissions to only the necessary database

## Updating
To update to the latest version, run the installation script again. It will:
- Backup your existing configuration
- Install the latest version
- Migrate the database
To update the application, use one of these commands:

```bash
# Update to latest version
curl -fsSL https://raw.githubusercontent.com/eloravpn/EloraVPNManager/main/install.sh | sudo bash -s -- --update

# Update to specific version
curl -fsSL https://raw.githubusercontent.com/eloravpn/EloraVPNManager/main/install.sh | sudo bash -s -- --update --version v1.2.3
```
- Restart the service

## Uninstallation
Expand Down
98 changes: 80 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ DB_HOST="localhost"
JWT_SECRET=""
USER_NAME="admin"
PASSWORD=""
IS_UPDATE=false
VERSION_TAG=""

# Log function
log() {
Expand Down Expand Up @@ -97,15 +99,23 @@ get_public_ip() {

# Function to download and extract latest release
download_latest_release() {
log "Downloading latest release..."
log "Downloading release..."

# Create temporary directory
local temp_dir=$(mktemp -d)
cd "$temp_dir"

# Download latest release information
log "Fetching latest release information..."
LATEST_RELEASE=$(curl -s https://api.github.com/repos/eloravpn/EloraVPNManager/releases/latest)
log "Fetching release information..."
if [ -n "$VERSION_TAG" ]; then
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/eloravpn/EloraVPNManager/releases/tags/${VERSION_TAG}")
if [ "$(echo $LATEST_RELEASE | jq -r '.message')" = "Not Found" ]; then
error "Version ${VERSION_TAG} not found"
fi
else
LATEST_RELEASE=$(curl -s https://api.github.com/repos/eloravpn/EloraVPNManager/releases/latest)
fi

DOWNLOAD_URL=$(echo $LATEST_RELEASE | jq -r '.assets[0].browser_download_url')
VERSION=$(echo $LATEST_RELEASE | jq -r '.tag_name')

Expand All @@ -116,9 +126,9 @@ download_latest_release() {
log "Downloading version ${VERSION}..."
curl -L -o release.zip "$DOWNLOAD_URL" || error "Failed to download release"

# Extract files
# Extract files with overwrite
log "Extracting files..."
unzip -q release.zip -d "$INSTALL_DIR" || error "Failed to extract files"
unzip -o -q release.zip -d "$INSTALL_DIR" || error "Failed to extract files"

# Verify required files
log "Verifying installation files..."
Expand Down Expand Up @@ -152,9 +162,15 @@ check_download_tools() {

# Update environment configuration
update_env() {
log "Updating .env configuration..."
log "Checking .env configuration..."
local env_file="$INSTALL_DIR/.env"

# If this is an update and .env exists, skip updating it
if [ "$IS_UPDATE" = true ] && [ -f "$env_file" ]; then
log "Update mode: Preserving existing .env configuration"
return
fi

# Generate JWT secret if not provided
JWT_SECRET=${JWT_SECRET:-$(generate_jwt_secret)}
PASSWORD=${PASSWORD:-$(generate_password)}
Expand Down Expand Up @@ -374,7 +390,36 @@ backup_existing() {
if [ -d "$INSTALL_DIR" ]; then
local backup_dir="${INSTALL_DIR}_backup_$(date +%Y%m%d_%H%M%S)"
log "Creating backup of existing installation to $backup_dir"
mv "$INSTALL_DIR" "$backup_dir" || error "Failed to create backup"

# Create backup directory
mkdir -p "$backup_dir"

# Backup everything except .env and config.json if this is an update
if [ "$IS_UPDATE" = true ]; then
# Temporarily move .env and config.json
if [ -f "$INSTALL_DIR/.env" ]; then
mv "$INSTALL_DIR/.env" "$INSTALL_DIR/.env.temp"
fi
if [ -f "$INSTALL_DIR/static/config.json" ]; then
mkdir -p "$INSTALL_DIR/static.temp"
mv "$INSTALL_DIR/static/config.json" "$INSTALL_DIR/static.temp/config.json"
fi

# Copy everything to backup
cp -r "$INSTALL_DIR"/* "$backup_dir/" || error "Failed to create backup"

# Move .env and config.json back
if [ -f "$INSTALL_DIR/.env.temp" ]; then
mv "$INSTALL_DIR/.env.temp" "$INSTALL_DIR/.env"
fi
if [ -f "$INSTALL_DIR/static.temp/config.json" ]; then
mv "$INSTALL_DIR/static.temp/config.json" "$INSTALL_DIR/static/config.json"
rm -rf "$INSTALL_DIR/static.temp"
fi
else
# For fresh installation, backup everything
mv "$INSTALL_DIR" "$backup_dir" || error "Failed to create backup"
fi
fi
}

Expand Down Expand Up @@ -473,6 +518,14 @@ main() {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--update)
IS_UPDATE=true
shift
;;
--version)
VERSION_TAG="$2"
shift 2
;;
--domain)
DOMAIN="$2"
shift 2
Expand Down Expand Up @@ -536,7 +589,7 @@ main() {
log "Using specified domain: $DOMAIN"
fi

log "Starting Elora VPN Manager installation..."
log "Starting Elora VPN Manager ${IS_UPDATE:+update } installation..."

# Check system and dependencies
check_dependencies
Expand All @@ -549,7 +602,9 @@ main() {
setup_install_dir

# Setup database
setup_database
if [ "$IS_UPDATE" = false ]; then
setup_database
fi

# Download and extract latest release
check_download_tools
Expand Down Expand Up @@ -579,23 +634,30 @@ main() {
# Final status check
if systemctl is-active --quiet "$SERVICE_NAME"; then
# Print installation summary
log "\nInstallation completed successfully!"

log "\nInstallation Details:"
log "- Panel URL: ${PROTOCOL}://${DOMAIN}:${PORT}"
log "- Admin User Name: ${USER_NAME}"
log "- Admin Password: ${PASSWORD}"
log "\nInstallation ${IS_UPDATE:+update }completed successfully!"

if [ "$IS_UPDATE" = false ]; then
# Only show credentials for fresh installations
log "\nInstallation Details:"
log "- Panel URL: ${PROTOCOL}://${DOMAIN}:${PORT}"
log "- Admin User Name: ${USER_NAME}"
log "- Admin Password: ${PASSWORD}"

log "\nConfigurations:"
log "- Database: ${DB_NAME}"
log "- Database User: ${DB_USER}"
log "- Database Password: ${DB_PASSWORD}"
fi

log "\nConfigurations:"
log "- Database: ${DB_NAME}"
log "- Database User: ${DB_USER}"
log "- Database Password: ${DB_PASSWORD}"

log "- Installation Directory: ${INSTALL_DIR}"
log "- Python Configuration File: ${INSTALL_DIR}/.env"
log "- Front-end Configuration File: ${INSTALL_DIR}/static/config.json"
log "- Service Name: ${SERVICE_NAME}"

log "\nService Management Commands:"

log "- Check status: systemctl status ${SERVICE_NAME}"
log "- View logs: journalctl -u ${SERVICE_NAME} -f"
log "- Restart service: systemctl restart ${SERVICE_NAME}"
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/notification_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def process_pending_notifications():
db_notification.keyboard
)

if db_notification.photo_url is not None:
if db_notification.photo_url:
utils.send_photo_to_user(
chat_id=db_user.telegram_chat_id,
caption=db_notification.message,
Expand Down
2 changes: 1 addition & 1 deletion src/notification/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_notification(
type=notification.type,
keyboard=(
json.loads(notification.keyboard)
if notification.keyboard is not None
if notification.keyboard
else None
),
photo_url=notification.photo_url,
Expand Down

0 comments on commit c4d634a

Please sign in to comment.