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

@@ -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"