Skip to content
Merged
37 changes: 7 additions & 30 deletions install_rubikpi3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo '=== Current directory: \$(pwd) ==='
echo '=== Files in current directory: ==='
ls -la

ln -sf libOpenCL.so.1 /usr/lib/aarch64-linux-gnu/libOpenCL.so # Fix for snpe-tools
# Create user pi:raspberry login
echo "creating pi user"
useradd pi -m -b /home -s /bin/bash
Expand All @@ -23,57 +24,33 @@ if id "ubuntu" >/dev/null 2>&1; then
deluser --remove-home ubuntu
fi

REPO_ENTRY="deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main"
HOST_ENTRY="151.106.120.85 apt.rubikpi.ai" # TODO: Remove legacy

# First update the APT
apt-get update -y


# TODO: Remove legacy
sed -i "/$HOST_ENTRY/d" /etc/hosts || true
sed -i '/apt.rubikpi.ai ppa main/d' /etc/apt/sources.list || true

if ! grep -q "^[^#]*$REPO_ENTRY" /etc/apt/sources.list; then
echo "$REPO_ENTRY" | tee -a /etc/apt/sources.list >/dev/null
fi
# This needs to run before install.sh to fix some weird dependency issues
apt-get -y --allow-downgrades install libsqlite3-0=3.45.1-1ubuntu2

# Add the GPG key for the RUBIK Pi PPA
wget -qO - https://thundercomm.s3.dualstack.ap-northeast-1.amazonaws.com/uploads/web/rubik-pi-3/tools/key.asc | tee /etc/apt/trusted.gpg.d/rubikpi3.asc

apt update -y

apt-get -y --allow-downgrades install libsqlite3-0=3.45.1-1ubuntu2
apt-get -y install libqnn1 libsnpe1 tensorflow-lite-qcom-apps qcom-adreno1

ln -sf libOpenCL.so.1 /usr/lib/aarch64-linux-gnu/libOpenCL.so # Fix for snpe-tools

# Run normal photon installer
chmod +x ./install.sh
./install.sh --install-nm=yes --arch=aarch64

# Install packages from the RUBIK Pi PPA, we skip calling apt-get update here because install.sh already does that
apt-get -y install libqnn1 libsnpe1 qcom-adreno1 device-tree-compiler

# Enable ssh
systemctl enable ssh


# Remove extra packages too
echo "Purging extra things"
apt-get purge -y gdb gcc g++ linux-headers* libgcc*-dev perl-modules* git vim-runtime tensorflow-lite-qcom-apps

# get rid of snaps
echo "Purging snaps"
rm -rf /var/lib/snapd/seed/snaps/*
rm -f /var/lib/snapd/seed/seed.yaml
apt-get purge --yes --quiet lxd-installer lxd-agent-loader
apt-get purge --yes --quiet snapd
apt-get purge --yes lxd-installer lxd-agent-loader snapd gdb gcc g++ linux-headers* libgcc*-dev perl-modules* git vim-runtime
apt-get autoremove -y

echo "Installing additional things"

apt-get update -y

apt-get install -y device-tree-compiler

rm -rf /var/lib/apt/lists/*
apt-get clean

Expand Down
22 changes: 13 additions & 9 deletions mount_rubikpi3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if [[ "$base_image" == *.yaml ]]; then
elif [[ "$base_image" == *.tar.xz ]]; then
# Directly download the tar.xz file
wget -nv -O base_image.tar.xz "${base_image}"
tar -xJvf base_image.tar.xz
tar -I 'xz -T0' -xf base_image.tar.xz
else
echo "Error: base_image must be a .yaml manifest or .tar.xz"
exit 1
Expand All @@ -63,7 +63,7 @@ if [[ "$ROOTFS_IMG" == *.img.xz ]]; then
ROOTFS_IMG_XZ="$ROOTFS_IMG"
ROOTFS_IMG="${ROOTFS_IMG_XZ%.xz}"
echo "Extracting rootfs image: $ROOTFS_IMG_XZ"
xz -d "$ROOTFS_IMG_XZ"
xz -T0 -d "$ROOTFS_IMG_XZ"
fi

if [ ! -f "$ROOTFS_IMG" ]; then
Expand Down Expand Up @@ -153,15 +153,19 @@ sudo cp /usr/bin/qemu-aarch64-static rootfs/usr/bin/ || true
sudo mkdir -p rootfs/tmp/build/
sudo mount --bind "$(pwd)" rootfs/tmp/build/

# Install sudo in the chroot environment (needed by install scripts)
echo "=== Installing sudo in chroot ==="
sudo chroot rootfs /usr/bin/qemu-aarch64-static /bin/bash -c "set -exv && DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y sudo"

# Run the installation scripts in chroot with verbose output
echo "=== Running installation scripts in chroot ==="
echo "=== Checking for sudo in chroot and running script ==="
sudo chroot rootfs /usr/bin/qemu-aarch64-static /bin/bash -c "
set -exv
export DEBIAN_FRONTEND=noninteractive
if ! command -v sudo &> /dev/null; then
echo 'sudo not found, installing...'
apt-get update && apt-get install -y sudo
else
echo 'sudo is already installed'
fi

echo '=== Running installation scripts in chroot ==='

echo '=== Making script executable ==='
chmod +x ${script}
echo '=== Running ${script} with arguments: ${@:3} ==='
Expand Down Expand Up @@ -207,4 +211,4 @@ find photonvision_rubikpi3 -mindepth 1 -type d -empty -delete
# Set output for later steps
# Save the rootfs image path for later steps
echo "rootfs_image=$ROOTFS_IMG" >> $GITHUB_ENV
tar -cJf photonvision_rubikpi3.tar.xz -C . photonvision_rubikpi3
tar -I 'xz -T0' -cf photonvision_rubikpi3.tar.xz photonvision_rubikpi3