Compare commits
24 Commits
0c58e5628e
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 9df8b9cd2e | |||
| a1c4e94cb5 | |||
| 8160861e6b | |||
| edc54b2e85 | |||
| 5278685dff | |||
| 4eb3a9c2c3 | |||
| 3a2d253bcc | |||
| 4d37f159ad | |||
| 2f835e0f74 | |||
| 620dbd7bcc | |||
| b2f703d985 | |||
| 38c3c5b0c7 | |||
| 8c90128f9a | |||
| a2b9b1482b | |||
| 9bb805cb99 | |||
| d65523e429 | |||
| 90e4726a61 | |||
| 65211e7173 | |||
| 60e56e41bf | |||
| 0f5571901f | |||
| f15ac48b12 | |||
| afd8faab62 | |||
| aa6bf06cd7 | |||
| aed40090ef |
@ -32,7 +32,11 @@ function update_script() {
|
||||
fi
|
||||
setup_uv
|
||||
# Crawling the new version and checking whether an update is required
|
||||
RELEASE=$(curl -fsSL https://api.github.com/repos/Dictionarry-Hub/profilarr/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}')
|
||||
RELEASE=$(curl -fsSL https://api.github.com/repos/BiluliB/profilarr/releases/latest | grep "tag_name" | cut -d'"' -f4)
|
||||
if [[ -z "$RELEASE" ]]; then
|
||||
msg_error "Failed to fetch latest release version"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -f /opt/${APP}_version.txt ]] && [[ "${RELEASE}" == "$(cat /opt/${APP}_version.txt)" ]]; then
|
||||
msg_ok "No update required. ${APP} is already at ${RELEASE}"
|
||||
exit
|
||||
@ -53,31 +57,49 @@ function update_script() {
|
||||
msg_ok "Backup Created"
|
||||
|
||||
# Execute Update
|
||||
msg_info "Updating $APP to v${RELEASE}"
|
||||
msg_info "Updating $APP to ${RELEASE}"
|
||||
temp_file=$(mktemp)
|
||||
curl -fsSL -o "$temp_file" "https://github.com/Dictionarry-Hub/profilarr/archive/refs/tags/${RELEASE}.zip"
|
||||
curl -fsSL -o "$temp_file" "https://github.com/BiluliB/profilarr/archive/refs/tags/${RELEASE}.zip"
|
||||
unzip -q -o "$temp_file" -d /tmp
|
||||
|
||||
# Find the actual extracted directory name
|
||||
EXTRACTED_DIR=$(find /tmp -maxdepth 1 -name "profilarr-*" -type d | head -n1)
|
||||
if [[ -z "$EXTRACTED_DIR" ]]; then
|
||||
msg_error "Failed to find extracted directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf /opt/${APP}/backend /opt/${APP}/frontend
|
||||
mv "/tmp/profilarr-${RELEASE}/backend" /opt/${APP}/
|
||||
mv "/tmp/profilarr-${RELEASE}/frontend" /opt/${APP}/
|
||||
mv "${EXTRACTED_DIR}/backend" /opt/${APP}/
|
||||
mv "${EXTRACTED_DIR}/frontend" /opt/${APP}/
|
||||
|
||||
# Update Python dependencies
|
||||
msg_info "Updating Python dependencies"
|
||||
cd /opt/${APP}/backend || exit
|
||||
|
||||
# Create a temporary requirements file excluding the incompatible PyYAML version
|
||||
temp_req_file=$(mktemp)
|
||||
grep -v "^PyYAML" requirements.txt >"$temp_req_file"
|
||||
|
||||
if [[ -f "/opt/${APP}/.requirements_checksum" ]]; then
|
||||
CURRENT_CHECKSUM=$(md5sum requirements.txt | awk '{print $1}')
|
||||
CURRENT_CHECKSUM=$(md5sum "$temp_req_file" | awk '{print $1}')
|
||||
STORED_CHECKSUM=$(cat /opt/${APP}/.requirements_checksum)
|
||||
if [[ "$CURRENT_CHECKSUM" != "$STORED_CHECKSUM" ]]; then
|
||||
msg_info "Requirements have changed. Performing full upgrade."
|
||||
$STD uv pip install -r requirements.txt --python /opt/${APP}/venv/bin/python
|
||||
# Ensure compatible PyYAML is installed
|
||||
$STD uv pip install --python /opt/${APP}/venv/bin/python "PyYAML>=6.0"
|
||||
$STD uv pip install -r "$temp_req_file" --python /opt/${APP}/venv/bin/python
|
||||
else
|
||||
msg_info "Requirements unchanged. Verifying installation."
|
||||
$STD uv pip install -r requirements.txt --python /opt/${APP}/venv/bin/python
|
||||
$STD uv pip install -r "$temp_req_file" --python /opt/${APP}/venv/bin/python
|
||||
fi
|
||||
else
|
||||
$STD uv pip install -r requirements.txt --python /opt/${APP}/venv/bin/python
|
||||
# Ensure compatible PyYAML is installed
|
||||
$STD uv pip install --python /opt/${APP}/venv/bin/python "PyYAML>=6.0"
|
||||
$STD uv pip install -r "$temp_req_file" --python /opt/${APP}/venv/bin/python
|
||||
fi
|
||||
md5sum requirements.txt | awk '{print $1}' >/opt/${APP}/.requirements_checksum
|
||||
md5sum "$temp_req_file" | awk '{print $1}' >/opt/${APP}/.requirements_checksum
|
||||
rm -f "$temp_req_file"
|
||||
msg_ok "Updated Python dependencies"
|
||||
|
||||
# Build frontend
|
||||
@ -85,6 +107,8 @@ function update_script() {
|
||||
cd /opt/${APP}/frontend || exit
|
||||
npm install
|
||||
npm run build
|
||||
# Ensure the static directory exists before copying
|
||||
mkdir -p /opt/${APP}/backend/app/static/
|
||||
cp -r dist/* /opt/${APP}/backend/app/static/
|
||||
msg_ok "Built Frontend"
|
||||
|
||||
@ -96,7 +120,7 @@ function update_script() {
|
||||
# Cleaning up
|
||||
msg_info "Cleaning Up"
|
||||
rm -f "$temp_file"
|
||||
rm -rf "/tmp/profilarr-${RELEASE}"
|
||||
rm -rf "$EXTRACTED_DIR"
|
||||
msg_ok "Cleanup Completed"
|
||||
|
||||
# Last Action
|
||||
|
||||
@ -18,7 +18,10 @@ APPLICATION="profilarr"
|
||||
msg_info "Installing Dependencies"
|
||||
$STD apt-get install -y \
|
||||
unzip \
|
||||
build-essential
|
||||
build-essential \
|
||||
libyaml-dev \
|
||||
python3-dev \
|
||||
git
|
||||
msg_ok "Installed Dependencies"
|
||||
|
||||
msg_info "Installing Python"
|
||||
@ -36,18 +39,44 @@ NODE_VERSION="20" install_node_and_modules
|
||||
msg_ok "Installed Node.js"
|
||||
|
||||
msg_info "Setup ${APPLICATION}"
|
||||
RELEASE=$(curl -fsSL https://api.github.com/repos/Dictionarry-Hub/profilarr/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}')
|
||||
RELEASE=$(curl -fsSL https://api.github.com/repos/BiluliB/profilarr/releases/latest | grep "tag_name" | cut -d'"' -f4)
|
||||
if [[ -z "$RELEASE" ]]; then
|
||||
msg_error "Failed to fetch latest release version"
|
||||
exit 1
|
||||
fi
|
||||
temp_file=$(mktemp)
|
||||
$STD curl -fsSL -o "$temp_file" "https://github.com/Dictionarry-Hub/profilarr/archive/refs/tags/${RELEASE}.zip"
|
||||
$STD curl -fsSL -o "$temp_file" "https://github.com/BiluliB/profilarr/archive/refs/tags/${RELEASE}.zip"
|
||||
$STD unzip -q "$temp_file" -d /tmp
|
||||
$STD mkdir -p /opt/${APPLICATION}
|
||||
$STD mkdir -p /opt/${APPLICATION}_config
|
||||
$STD mv "/tmp/profilarr-${RELEASE}/backend" /opt/${APPLICATION}/
|
||||
$STD mv "/tmp/profilarr-${RELEASE}/frontend" /opt/${APPLICATION}/
|
||||
|
||||
# Find the actual extracted directory name
|
||||
EXTRACTED_DIR=$(find /tmp -maxdepth 1 -name "profilarr-*" -type d | head -n1)
|
||||
if [[ -z "$EXTRACTED_DIR" ]]; then
|
||||
msg_error "Failed to find extracted directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$STD mv "${EXTRACTED_DIR}/backend" /opt/${APPLICATION}/
|
||||
$STD mv "${EXTRACTED_DIR}/frontend" /opt/${APPLICATION}/
|
||||
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
|
||||
$STD uv venv /opt/${APPLICATION}/venv
|
||||
$STD uv pip install --python /opt/${APPLICATION}/venv/bin/python -r /opt/${APPLICATION}/backend/requirements.txt
|
||||
|
||||
# Install compatible PyYAML first, then exclude it from requirements
|
||||
$STD uv pip install --python /opt/${APPLICATION}/venv/bin/python "PyYAML>=6.0"
|
||||
|
||||
# Create modified requirements file
|
||||
temp_req_file=$(mktemp)
|
||||
grep -v "^PyYAML" /opt/${APPLICATION}/backend/requirements.txt >"$temp_req_file"
|
||||
echo "PyYAML>=6.0" >>"$temp_req_file"
|
||||
|
||||
$STD uv pip install --python /opt/${APPLICATION}/venv/bin/python -r "$temp_req_file"
|
||||
$STD uv pip install --python /opt/${APPLICATION}/venv/bin/python gunicorn
|
||||
|
||||
# Store the modified requirements checksum for future updates
|
||||
md5sum "$temp_req_file" | awk '{print $1}' >/opt/${APPLICATION}/.requirements_checksum
|
||||
|
||||
rm -f "$temp_req_file"
|
||||
msg_ok "Setup ${APPLICATION}"
|
||||
|
||||
msg_info "Building Frontend"
|
||||
@ -63,21 +92,140 @@ cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/gunicorn --bind 0.0.0.0:6868 --workers 2 --timeout 120 app.main:create_app()
|
||||
Environment=PYTHONPATH=/opt/${APPLICATION}/backend
|
||||
Environment=GIT_PYTHON_REFRESH=quiet
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python -m gunicorn --bind 0.0.0.0:6868 --workers 2 --timeout 120 --pythonpath /opt/${APPLICATION}/backend "app.main:create_app()"
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
$STD systemctl daemon-reload
|
||||
systemctl enable -q --now ${APPLICATION}
|
||||
|
||||
# Test the application manually first
|
||||
msg_info "Testing Application"
|
||||
cd /opt/${APPLICATION}/backend
|
||||
|
||||
# Check if the main module exists and is importable
|
||||
if ! /opt/${APPLICATION}/venv/bin/python -c "
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, '/opt/${APPLICATION}/backend')
|
||||
os.environ['GIT_PYTHON_REFRESH'] = 'quiet'
|
||||
try:
|
||||
import app.main
|
||||
print('✓ app.main imported successfully')
|
||||
except ImportError as e:
|
||||
print(f'✗ Import error: {e}')
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f'✗ Other error: {e}')
|
||||
sys.exit(1)
|
||||
"; then
|
||||
msg_error "Application import test failed"
|
||||
|
||||
# Try alternative approaches
|
||||
msg_info "Trying alternative startup methods"
|
||||
|
||||
# Check if there's a direct run.py or main.py
|
||||
if [[ -f "/opt/${APPLICATION}/backend/run.py" ]]; then
|
||||
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
Environment=GIT_PYTHON_REFRESH=quiet
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python run.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
elif [[ -f "/opt/${APPLICATION}/backend/main.py" ]]; then
|
||||
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
Environment=GIT_PYTHON_REFRESH=quiet
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python main.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
else
|
||||
# Fallback to Flask development server
|
||||
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
Environment=GIT_PYTHON_REFRESH=quiet
|
||||
Environment=FLASK_APP=app.main:create_app
|
||||
Environment=FLASK_RUN_HOST=0.0.0.0
|
||||
Environment=FLASK_RUN_PORT=6868
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python -m flask run
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
fi
|
||||
|
||||
$STD systemctl daemon-reload
|
||||
fi
|
||||
|
||||
systemctl enable ${APPLICATION}
|
||||
systemctl start ${APPLICATION}
|
||||
|
||||
# Wait and check status
|
||||
sleep 5
|
||||
if systemctl is-active --quiet ${APPLICATION}; then
|
||||
msg_ok "Service started successfully"
|
||||
else
|
||||
msg_error "Service failed to start. Checking logs..."
|
||||
journalctl -u ${APPLICATION} --no-pager -n 20
|
||||
exit 1
|
||||
fi
|
||||
msg_ok "Created Service"
|
||||
|
||||
motd_ssh
|
||||
@ -85,7 +233,7 @@ customize
|
||||
|
||||
msg_info "Cleaning up"
|
||||
rm -f "$temp_file"
|
||||
rm -rf "/tmp/profilarr-${RELEASE}"
|
||||
rm -rf "$EXTRACTED_DIR"
|
||||
$STD apt-get -y autoremove
|
||||
$STD apt-get -y autoclean
|
||||
msg_ok "Cleaned"
|
||||
|
||||
Reference in New Issue
Block a user