This commit is contained in:
Daniel Kukula 2025-08-12 21:39:42 +02:00
parent 4469a6e6df
commit ddf32895dc
5 changed files with 163 additions and 113 deletions

View File

@ -1,17 +1,17 @@
#!/usr/bin/env bash
source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func)
source <(curl -fsSL https://raw.githubusercontent.com/dkuku/ProxmoxVED/refs/heads/livebook/misc/build.func)
# Copyright (c) 2021-2025 community-scripts ORG
# Author: dkuku
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/community-scripts/ProxmoxVE
# Source: https://github.com/livebook-dev/livebook
APP="Livebook"
var_tags="${var_tags:-development}"
var_disk="${var_disk:-4}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-1024}"
var_os="${var_os:-debian}"
var_version="${var_version:-12}"
var_os="${var_os:-ubuntu}"
var_version="${var_version:-24}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
@ -20,24 +20,69 @@ color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /home/livebook ]]; then
msg_error "No ${APP} Installation Found!"
exit
header_info
check_container_storage
check_container_resources
# Check if Livebook is installed
if [[ ! -d /opt/${APP}_version.txt ]]; then
msg_error "No ${APP} Installation Found!"
exit 1
fi
# Get the latest version from GitHub
msg_info "Checking for updates..."
RELEASE=$(curl -fsSL https://api.github.com/repos/livebook-dev/livebook/releases/latest | grep "tag_name" | awk -F'"' '{print $4}')
if [[ -z "$RELEASE" ]]; then
msg_error "Failed to fetch latest version information"
exit 1
fi
# Check if version file exists and compare versions
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt 2>/dev/null)" ]]; then
msg_info "Updating ${APP} to v${RELEASE}"
# Create backup of user data if it exists
if [[ -d /home/livebook ]]; then
msg_info "Creating backup of user data..."
$STD cp -r /home/livebook /home/livebook-backup
fi
msg_info "Updating ${APP} LXC"
sudo -u livebook bash << 'EOF'
export HOME=/home/livebook
cd /home/livebook
source ~/.bashrc
mix local.hex --force >/dev/null 2>&1
mix local.rebar --force >/dev/null 2>&1
mix escript.install hex livebook --force >/dev/null 2>&1
EOF
msg_ok "Updated Successfully"
exit
# Perform the update
msg_info "Installing dependencies and updating Livebook..."
if ! sudo -u livebook bash -c '
export HOME=/home/livebook
cd /home/livebook
mix local.hex --force >/dev/null 2>&1
mix local.rebar --force >/dev/null 2>&1
mix escript.install hex livebook --force >/dev/null 2>&1
'; then
msg_error "Failed to update Livebook"
# Restore from backup if update failed
if [[ -d /home/livebook-backup ]]; then
msg_info "Restoring from backup..."
rm -rf /home/livebook
mv /home/livebook-backup /home/livebook
fi
exit 1
fi
# Save the new version
echo "$RELEASE" | $STD tee /opt/${APP}_version.txt >/dev/null
# Cleanup backup if update was successful
if [[ -d /home/livebook-backup ]]; then
msg_info "Cleaning up backup..."
$STD rm -rf /home/livebook-backup
fi
msg_ok "Successfully updated to v${RELEASE}"
else
msg_ok "No update required. ${APP} is already at v${RELEASE}."
fi
exit
}
start
@ -47,9 +92,7 @@ description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080${CL}"
echo -e "${INFO}${YW} Authentication:${CL}"
echo -e "${TAB}${RD}• Token authentication enabled by default${CL}"
echo -e "${TAB}${RD}• Token will be shown in logs: journalctl -u livebook.service${CL}"
echo -e "${TAB}${RD}• Generated token: /data/token.txt${CL}"
echo -e "${TAB}${RD}• Configuration: /data/.env${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}${CL}"
echo -e "\n${INFO}${YW} To start Livebook, run the following command:${CL}"
echo -e "${TAB}${BGN}sudo -u livebook /root/.mix/escripts/livebook server${CL}"
echo -e "\n${INFO}${YW} To run it as a service, create a systemd service file.${CL}"

View File

@ -22,8 +22,8 @@
"cpu": 2,
"ram": 1024,
"hdd": 4,
"os": "Debian",
"version": "12"
"os": "Ubuntu",
"version": "24"
}
}
],

View File

@ -2,7 +2,8 @@
# Copyright (c) 2021-2025 community-scripts ORG
# Author: dkuku
# License: MIT |
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/livebook-dev/livebook
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
@ -16,34 +17,88 @@ msg_info "Installing Dependencies (matching Livebook Dockerfile)"
$STD apt-get install --no-install-recommends -y \
build-essential \
ca-certificates \
libncurses5-dev \
git \
wget \
cmake \
elixir
curl \
git \
libncurses5-dev
msg_ok "Installed Dependencies"
msg_info "Creating Livebook User and Directories"
useradd -r -s /bin/bash -d /home/livebook livebook
mkdir -p /home/livebook /data
chown livebook:livebook /home/livebook /data
# Make sure user has permissions to home dir (for Mix.install/2 cache)
chmod 777 /home/livebook
useradd -r -s /bin/bash -d /opt livebook
mkdir -p /opt /data
chown livebook:livebook /opt /data
chmod 777 /opt
msg_ok "Created Livebook User and Directories"
msg_info "Installing Livebook"
sudo -u livebook bash << 'EOF'
export HOME=/home/livebook
cd /home/livebook
# Install hex and rebar for Mix.install/2 and Mix runtime (matching Dockerfile)
mix local.hex --force
mix local.rebar --force
# Following official Livebook escript installation instructions
mix escript.install hex livebook
echo 'export PATH="$HOME/.mix/escripts:$PATH"' >> ~/.bashrc
source ~/.bashrc
msg_info "Installing Erlang and Elixir"
# Create a temporary script
cat > /tmp/setup_elixir.sh << 'EOF'
#!/bin/bash
export HOME=/opt
cd /opt
curl -fsSO https://elixir-lang.org/install.sh
sh install.sh elixir@1.18.4 otp@27.3.4 >/dev/null 2>&1
# Create .env if it doesn't exist and set permissions
touch $HOME/.env
chmod 644 $HOME/.env
# Add exports to .env
echo 'export HOME=/opt' >> $HOME/.env
echo 'export PATH="$HOME/.elixir-install/installs/otp/27.3.4/bin:$HOME/.elixir-install/installs/elixir/1.18.4-otp-27/bin:$PATH"' >> $HOME/.env
EOF
msg_ok "Installed Livebook"
# Make it executable and run as livebook user
chmod +x /tmp/setup_elixir.sh
$STD sudo -u livebook -H /tmp/setup_elixir.sh
rm /tmp/setup_elixir.sh
msg_ok "Installed Erlang 27.3.4 and Elixir 1.18.4"
msg_info "Installing Livebook"
cat > /tmp/install_livebook.sh << 'EOF'
#!/bin/bash
RELEASE=$(curl -fsSL https://api.github.com/repos/livebook-dev/livebook/releases/latest | grep "tag_name" | awk -F'"' '{print $4}')
echo "${RELEASE}" >/opt/Livebook_version.txt
set -e # Exit on any error
source /opt/.env
cd $HOME
# Install hex and rebar for Mix.install/2 and Mix runtime (matching Dockerfile)
echo "Installing hex..."
mix local.hex --force
echo "Installing rebar..."
mix local.rebar --force
# Following official Livebook escript installation instructions
echo "Installing Livebook escript..."
MIX_ENV=prod mix escript.install hex livebook --force
# Add escripts to PATH
echo 'export PATH="$HOME/.mix/escripts:$PATH"' >> ~/.env
# Verify livebook was installed and make executable
if [ -f ~/.mix/escripts/livebook ]; then
chmod +x ~/.mix/escripts/livebook
echo "Livebook escript installed successfully"
ls -la ~/.mix/escripts/livebook
else
echo "ERROR: Livebook escript not found after installation"
ls -la ~/.mix/escripts/ || echo "No escripts directory found"
# Try to show what went wrong
echo "Mix environment:"
mix --version
echo "Available packages:"
mix hex.info livebook || echo "Could not get livebook info"
exit 1
fi
EOF
chmod +x /tmp/install_livebook.sh
$STD sudo -u livebook -H /tmp/install_livebook.sh
rm /tmp/install_livebook.sh
msg_info "Creating Livebook Service"
cat <<EOF >/etc/systemd/system/livebook.service
@ -56,12 +111,14 @@ Type=exec
User=livebook
Group=livebook
WorkingDirectory=/data
Environment=HOME=/home/livebook
Environment=PATH=/home/livebook/.mix/escripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Environment=MIX_ENV=prod
Environment=HOME=/opt
Environment=PATH=/opt/.mix/escripts:/opt/.elixir-install/installs/otp/27.3.4/bin:/opt/.elixir-install/installs/elixir/1.18.4-otp-27/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Environment=LIVEBOOK_PORT=8080
Environment=LIVEBOOK_IP="::"
Environment=LIVEBOOK_HOME=/data
ExecStart=/home/livebook/.mix/escripts/livebook server
Environment=LIVEBOOK_TOKEN_ENABLED=false
ExecStart=/bin/bash -c 'cd /opt && livebook server'
Restart=always
RestartSec=5
StandardOutput=journal
@ -71,71 +128,21 @@ StandardError=journal
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable livebook.service
$STD systemctl enable livebook.service
msg_ok "Created Livebook Service"
msg_info "Setting up Authentication"
# Generate a secure token for authentication
TOKEN=$(openssl rand -hex 32)
sudo -u livebook bash << EOF
cd /home/livebook
export HOME=/home/livebook
export PATH="\$HOME/.mix/escripts:\$PATH"
# Create environment file with authentication settings
cat > /data/.env << 'ENVEOF'
# Livebook Authentication Configuration
# Uncomment one of the following options:
# Option 1: Password authentication (recommended for production)
# LIVEBOOK_PASSWORD=$TOKEN
# Option 2: Token authentication (default - token will be shown in logs)
# LIVEBOOK_TOKEN_ENABLED=true
# Option 3: Disable authentication (NOT recommended for production)
# LIVEBOOK_TOKEN_ENABLED=false
# Current setting: Token authentication (default)
LIVEBOOK_TOKEN_ENABLED=true
ENVEOF
# Save the token for easy access
echo "$TOKEN" > /data/token.txt
chmod 600 /data/token.txt
chown livebook:livebook /data/.env /data/token.txt
EOF
msg_ok "Set up Authentication"
msg_info "Starting Livebook Service"
systemctl start livebook.service
msg_ok "Started Livebook Service"
msg_info "Cleaning Up"
rm -f /tmp/erlang-solutions_2.0_all.deb
rm -f /opt/install.sh
$STD apt-get autoremove -y
$STD apt-get autoclean
msg_ok "Cleaned Up"
msg_info "Starting Livebook Service"
$STD systemctl start livebook.service
msg_ok "Started Livebook Service"
motd_ssh
customize
msg_info "Cleaning up"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"
echo -e "\n${CREATING}${GN}Livebook Installation Complete!${CL}\n"
echo -e "${INFO}${YW}Authentication Information:${CL}"
echo -e "${TAB}${RD}• Default: Token authentication (auto-generated)${CL}"
echo -e "${TAB}${RD}• Token will be displayed in Livebook logs on startup${CL}"
echo -e "${TAB}${RD}• Generated token saved to: /data/token.txt${CL}"
echo -e "${TAB}${RD}• Configuration file: /data/.env${CL}\n"
echo -e "${INFO}${YW}To configure authentication:${CL}"
echo -e "${TAB}${RD}1. Password auth: Edit /data/.env and uncomment LIVEBOOK_PASSWORD${CL}"
echo -e "${TAB}${RD}2. No auth: Edit /data/.env and set LIVEBOOK_TOKEN_ENABLED=false${CL}"
echo -e "${TAB}${RD}3. Restart service: systemctl restart livebook.service${CL}\n"
echo -e "${INFO}${YW}Generated Token (for reference):${CL}"
echo -e "${TAB}${GN}$(cat /data/token.txt)${CL}\n"

View File

@ -1438,7 +1438,7 @@ EOF'
fi
msg_ok "Customized LXC Container"
lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/install/${var_install}.sh)"
lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/dkuku/ProxmoxVED/refs/heads/livebook/install/${var_install}.sh)"
}
destroy_lxc() {

View File

@ -31,7 +31,7 @@ catch_errors() {
# This function handles errors
error_handler() {
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/api.func)
source <(curl -fsSL https://raw.githubusercontent.com/dkuku/ProxmoxVED/refs/heads/livebook/misc/api.func)
printf "\e[?25h"
local exit_code="$?"
local line_number="$1"