update box script to use incus
arnaucube git@arnaucube.com
Sat, 26 Sep 2026 08:59:00 +0200
6 files changed,
62 insertions(+),
31 deletions(-)
M
.tmux.conf
→
.tmux.conf
@@ -8,6 +8,9 @@ # maximize current pane
bind + resize-pane -Z +# force that new tabs (windows) will be opened at the current path +bind c new-window -c "#{pane_current_path}" + # on bind + Ctrl+t open a new window and launch there gotty with a 'random' url
M
backup-configs.sh
→
backup-configs.sh
@@ -14,3 +14,6 @@
mkdir -p alacritty cp ~/.config/alacritty/alacritty.toml ./alacritty/alacritty.toml +mkdir -p bin +cp ~/bin/box ./bin/box +cp ~/bin/box_profiles.sh ./bin/box_profiles.sh
M
bin/box
→
bin/box
@@ -9,7 +9,7 @@ # NOTE: in case the container does not have internet:
# 1) # sudo sysctl -w net.ipv4.ip_forward=1 # -# 2) +# 2) (at the host machine) # # Force iptables to ACCEPT traffic from the LXD bridge # # Docker sets the global policy to DROP; we must explicitly allow lxdbr0 # sudo iptables -I FORWARD -i lxdbr0 -j ACCEPT@@ -22,21 +22,37 @@ # sudo ufw route allow in on lxdbr0
# sudo ufw route allow out on lxdbr0 # # Note: when turning off and on the host machine, might need to set the iptables -# again: step 3). +# again: step 2). +# Incus version: +# +# sudo incus admin init +# +# then download the ubuntu image: +# sudo incus launch images:ubuntu/24.04 test +# +# - create a managed network bridge: +# incus network create incusbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none +# incus profile device set default eth0 network incusbr0 +# +# set -e if [ -z "$1" ]; then echo "Error: no container name provided." - echo "Usage: ./box.sh <container_name>" + echo "Usage: box <container_name> <profile_name(optional)>" exit 1 fi +# Choose which container manager to use: +#MNGR="lxc" +MNGR="sudo incus" + CONTAINER_NAME="$1" HOST_SHARE_DIR="/home/$USER/container_data/$CONTAINER_NAME" CONTAINER_SHARE_DIR="/mnt/shared" -IMAGE="ubuntu:22.04" +IMAGE="images:ubuntu/24.04" PROFILE_NAME=${2:-"default"} # if $2 is empty, use "default" PROFILES_FILE="$HOME/bin/box_profiles.sh"@@ -66,52 +82,56 @@ exit 1
fi echo "profile selected: [$PROFILE_NAME]" -echo "software to install: $SOFTWARE_LIST" +# echo "software to install: $SOFTWARE_LIST" mkdir -p "$HOST_SHARE_DIR" echo "launch LXD container: $CONTAINER_NAME..." # security.nesting=true allows Docker to run inside this container -lxc launch "$IMAGE" "$CONTAINER_NAME" -c security.nesting=true +$MNGR launch "$IMAGE" "$CONTAINER_NAME" -c security.nesting=true +# $MNGR launch "$IMAGE" "$CONTAINER_NAME" -c security.nesting=true sleep 2 # wait for filesystem echo "set dns" HOST_UID=$(id -u) # map Host User to Container Root -lxc config set "$CONTAINER_NAME" raw.idmap "both $HOST_UID 0" +# $MNGR config set "$CONTAINER_NAME" raw.idmap "both $HOST_UID 0" # set dns to bypass host dns -lxc exec "$CONTAINER_NAME" -- rm -f /etc/resolv.conf -lxc exec "$CONTAINER_NAME" -- bash -c "echo 'nameserver 8.8.8.8' | tee /etc/resolv.conf" +#$MNGR exec "$CONTAINER_NAME" -- rm -f /etc/resolv.conf +#$MNGR exec "$CONTAINER_NAME" -- bash -c "echo 'nameserver 8.8.8.8' | tee /etc/resolv.conf" -echo "restart container, sleep 2s" -lxc restart "$CONTAINER_NAME" -sleep 2 +echo "restart container" +$MNGR restart "$CONTAINER_NAME" +$MNGR exec "$CONTAINER_NAME" -- true echo "configure shared directory (between container & host)" -lxc config device add "$CONTAINER_NAME" project_storage disk \ +$MNGR config device add "$CONTAINER_NAME" project_storage disk \ source="$HOST_SHARE_DIR" \ path="$CONTAINER_SHARE_DIR" echo "configure port forwarding" for PORT in $EXPOSE_PORTS; do - lxc config device add "$CONTAINER_NAME" "proxy${PORT}" proxy \ + $MNGR config device add "$CONTAINER_NAME" "proxy${PORT}" proxy \ listen=tcp:0.0.0.0:${PORT} \ connect=tcp:127.0.0.1:${PORT} done + +$MNGR config device set $CONTAINER_NAME project_storage shift true + echo "check internet" -if ! lxc exec "$CONTAINER_NAME" -- ping -c 1 8.8.8.8 > /dev/null; then +if ! $MNGR exec "$CONTAINER_NAME" -- ping -c 1 8.8.8.8 > /dev/null; then echo "error: no internet access inside the container." echo "note: check out the 'NOTE' at the top of the script for instructions." # remove container, since failed the launch - lxc stop $CONTAINER_NAME - lxc delete $CONTAINER_NAME + $MNGR stop $CONTAINER_NAME + $MNGR delete $CONTAINER_NAME exit 1 fi echo "apt update & apt install" -lxc exec "$CONTAINER_NAME" -- bash -c " +$MNGR exec "$CONTAINER_NAME" -- bash -c " $(cat "$PROFILES_FILE") export DEBIAN_FRONTEND=noninteractive@@ -132,6 +152,6 @@ echo "----------------------------------------------------"
echo "Shared Directory (Host): $HOST_SHARE_DIR" echo "Shared Directory (Container): $CONTAINER_SHARE_DIR" echo "----------------------------------------------------" -echo "To enter the container, run: lxc shell $CONTAINER_NAME" -echo "To stop the container, run: lxc stop $CONTAINER_NAME" -echo "To remove the container, run: lxc delete $CONTAINER_NAME" +echo "To enter the container, run: $MNGR shell $CONTAINER_NAME" +echo "To stop the container, run: $MNGR stop $CONTAINER_NAME" +echo "To remove the container, run: $MNGR delete $CONTAINER_NAME"
M
bin/box_profiles.sh
→
bin/box_profiles.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash +#!/bin/bash # # See `box` file for more details.@@ -31,22 +31,24 @@ apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin } +profile_ai() { + npm i -g @openai/codex +} + profile_dev_env() { git clone https://github.com/arnaucube/configs.git # includes rust cd configs yes | bash install-new-server.sh } -profile_latex() { - sudo apt install latexmk - sudo apt install texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended +profile_min_docker() { + profile_minimal + profile_docker } - profile_default() { profile_minimal profile_nodejs profile_docker profile_ai profile_dev_env # includes rust - profile_latex }
M
install-new-server.sh
→
install-new-server.sh
@@ -47,9 +47,9 @@
source .bashrc # # go -# echo "installing go 1.24.3" -# wget https://golang.org/dl/go1.24.3.linux-amd64.tar.gz -# tar -C /usr/local -xzf go1.24.3.linux-amd64.tar.gz +# echo "installing go 1.27.1" +# wget https://golang.org/dl/go1.27.1.linux-amd64.tar.gz +# tar -C /usr/local -xzf go1.27.1.linux-amd64.tar.gz # # # nodejs # echo "installing nodejs v16"
M
sway/status.sh
→
sway/status.sh
@@ -24,6 +24,9 @@ datetime=$(date "+%a %F %H:%M:%S")
interface=$(ip route get 8.8.8.8 | awk -F'dev ' 'NR==1{split($2,a," ");print a[1]}') ip=$(ip addr show dev $interface | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1) +wifi_name=$(nmcli -g GENERAL.CONNECTION dev show "$interface") + + avail_space=$(df -h / | awk 'NR==2 {print $4}')@@ -31,4 +34,4 @@
# 💎 💻 💡 🔌 ⚡ 📁 \| 🐧 🔊 🔋 -echo $avail_space \| $temp°C \| $uptime_formatted \| vol: $volume $muted \| $battery_status $battery_capacity% \| $interface $ip \| $datetime +echo $avail_space \| $temp°C \| $uptime_formatted \| vol: $volume $muted \| $battery_status $battery_capacity% \| $wifi_name \| $interface $ip \| $datetime