From 596b5873e60dae712ee6e8d5fb695dc15de5b959 Mon Sep 17 00:00:00 2001 From: fe5hua Date: Tue, 15 Sep 2026 06:24:20 +0200 Subject: [PATCH] made init hooks script idemptent --- dot_scripts/executable_distrobox-dev-init.sh | 77 +++++++++++++++----- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/dot_scripts/executable_distrobox-dev-init.sh b/dot_scripts/executable_distrobox-dev-init.sh index 5587b01..ed794dd 100644 --- a/dot_scripts/executable_distrobox-dev-init.sh +++ b/dot_scripts/executable_distrobox-dev-init.sh @@ -34,14 +34,18 @@ EOF export RUSTUP_HOME=/opt/rustup export CARGO_HOME=/opt/cargo -echo "Installing rustup..." +if [[ ! -x /opt/cargo/bin/rustup ]]; then + echo "Installing rustup..." -curl \ - --proto '=https' \ - --tlsv1.2 \ - -sSf \ - https://sh.rustup.rs \ - | sh -s -- -y --no-modify-path + curl \ + --proto '=https' \ + --tlsv1.2 \ + -sSf \ + https://sh.rustup.rs \ + | sh -s -- -y --no-modify-path +else + echo "rustup is already installed." +fi # Rust toolchain echo "Installing stable Rust toolchain..." @@ -58,13 +62,27 @@ echo "Installing rustup Fish completion..." # ----------------------------------------------------------------------------- # Aseprite # ----------------------------------------------------------------------------- -echo "Building Aseprite..." -git clone --recursive https://github.com/aseprite/aseprite.git /opt/aseprite -cd /opt/aseprite -./build.sh --auto --norun +if [[ -f /opt/aseprite/aseprite.desktop ]]; then + echo "Aseprite desktop entry already exists; skipping installation." +else + if [[ ! -d /opt/aseprite ]]; then + echo "Cloning Aseprite..." + git clone --recursive https://github.com/aseprite/aseprite.git /opt/aseprite + else + echo "Aseprite source already exists." + fi -echo "Creating Aseprite desktop entry..." -cat > /opt/aseprite/aseprite.desktop <<'EOF' + cd /opt/aseprite + if [[ ! -x /opt/aseprite/build/bin/aseprite ]]; then + git submodule update --init --recursive + echo "Building Aseprite..." + ./build.sh --auto --norun + else + echo "Aseprite is already built." + fi + + echo "Creating Aseprite desktop entry..." + cat > /opt/aseprite/aseprite.desktop <<'EOF' [Desktop Entry] Name=Aseprite Comment=Animated sprite editor @@ -74,9 +92,16 @@ Terminal=false Type=Application Categories=Graphics;2DGraphics; EOF +fi -echo "Exporting Aseprite desktop entry..." -sudo -u "$DEV_USER" env HOME="$DEV_HOME" distrobox-export --app /opt/aseprite/aseprite.desktop +if sudo -u "$DEV_USER" env HOME="$DEV_HOME" distrobox-export --list-apps 2>/dev/null | + grep -Fq "aseprite" +then + echo "Aseprite desktop entry is already exported." +else + echo "Exporting Aseprite desktop entry..." + sudo -u "$DEV_USER" env HOME="$DEV_HOME" distrobox-export --app /opt/aseprite/aseprite.desktop +fi # ----------------------------------------------------------------------------- # Export development tools to the host @@ -87,15 +112,31 @@ echo "Exporting development tools..." export_bin() { local binary="$1" - if command -v "$binary" >/dev/null 2>&1; then + if ! command -v "$binary" >/dev/null 2>&1; then + echo " warning: $binary not found" + elif sudo -u "$DEV_USER" env HOME="$DEV_HOME" \ + distrobox-export \ + --list-binaries \ + --export-path "$DEV_HOME/.local/bin" 2>/dev/null | + awk -F'|' -v binary="$binary" ' + { + name = $1 + gsub(/^[[:space:]]+|[[:space:]]+$/, "", name) + if (name == binary) { + found = 1 + } + } + END { exit !found } + ' + then + echo " $binary is already exported." + else echo " exporting $binary" sudo -u "$DEV_USER" \ env HOME="$DEV_HOME" \ distrobox-export \ --bin "$(command -v "$binary")" \ --export-path "$DEV_HOME/.local/bin" - else - echo " warning: $binary not found" fi }