diff --git a/.dappnode_profile b/.dappnode_profile index 7c6e7f36..4d4943b8 100755 --- a/.dappnode_profile +++ b/.dappnode_profile @@ -7,40 +7,63 @@ # - `/ipfs/QmRe6...` -> indicates the ipfs hash used to download the content # - `0.2.71` -> indicates the version. It must be the one uploaded to such IPFS hash -export BIND_VERSION="${BIND_VERSION:-0.2.11}" -export IPFS_VERSION="${IPFS_VERSION:-0.2.23}" -export VPN_VERSION="${VPN_VERSION:-0.2.10}" -export DAPPMANAGER_VERSION="${DAPPMANAGER_VERSION:-0.2.88}" -export WIFI_VERSION="${WIFI_VERSION:-0.2.9}" -export WIREGUARD_VERSION="${WIREGUARD_VERSION:-0.1.3}" -export HTTPS_VERSION="${HTTPS:-0.2.1}" +export BIND_VERSION="${BIND_VERSION:-0.2.13}" +export IPFS_VERSION="${IPFS_VERSION:-0.2.27}" +export VPN_VERSION="${VPN_VERSION:-0.2.11}" +export DAPPMANAGER_VERSION="${DAPPMANAGER_VERSION:-0.2.121}" +export WIFI_VERSION="${WIFI_VERSION:-0.2.11}" +export WIREGUARD_VERSION="${WIREGUARD_VERSION:-0.1.4}" +export HTTPS_VERSION="${HTTPS:-0.2.2}" +export NOTIFICATIONS_VERSION="/ipfs/QmW5CSZv8x8ZktiNodJ9P8M6ZSRNX93jmB8oU6RtGermBc" +export PREMIUM_VERSION="/ipfs/QmUEmjt1yXLyGjnqf3BCiVenQtDhFwt4eMkx1sDemeEidM" export DAPPNODE_DIR="/usr/src/dappnode" export DAPPNODE_CORE_DIR="${DAPPNODE_DIR}/DNCORE" +# macOS host-mode helpers (this file is often sourced in a shell) +if [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then + export DISABLE_HOST_SCRIPTS="${DISABLE_HOST_SCRIPTS:-true}" + + for user_home in /Users/*; do + [ -d "$user_home" ] || continue + [ -d "$user_home/dappnode/DNCORE" ] || continue + export DAPPNODE_DIR="$user_home/dappnode" + export DAPPNODE_CORE_DIR="$user_home/dappnode/DNCORE" + break + done +fi + #!ISOBUILD Do not modify, variables above imported for ISO build -DNCORE_YMLS=$(find $DAPPNODE_CORE_DIR -name "docker-compose-*.yml" -printf "-f %p ") -# shellcheck disable=SC2207 -# shellcheck disable=SC2034 -DNCORE_YMLS_ARRAY=($(find /usr/src/dappnode/DNCORE -name "docker-compose-*.yml" | sort)) + +DNCORE_YMLS="" +if [ -d "$DAPPNODE_CORE_DIR" ]; then + DNCORE_YMLS=$(find "$DAPPNODE_CORE_DIR" -name "docker-compose-*.yml" -print | sort | sed 's|^|-f |' | tr '\n' ' ') +fi # Returns docker core containers status -alias dappnode_status='docker compose $DNCORE_YMLS ps' -# Stop docker core containers -alias dappnode_stop='docker compose $DNCORE_YMLS stop && docker stop $(docker container ls -a -q -f name=DAppNode*)' -# Start docker core containers -alias dappnode_start='docker compose $DNCORE_YMLS up -d && docker start $(docker container ls -a -q -f name=DAppNode*)' +# NOTE: zsh does not word-split `$DNCORE_YMLS` by default, so use `${=DNCORE_YMLS}` there. +if [ -n "${ZSH_VERSION:-}" ]; then + alias dappnode_status='docker compose ${=DNCORE_YMLS} ps' + alias dappnode_stop='docker compose ${=DNCORE_YMLS} stop && docker stop $(docker container ls -a -q -f name=DAppNode*)' + alias dappnode_start='docker compose ${=DNCORE_YMLS} up -d && docker start $(docker container ls -a -q -f name=DAppNode*)' + alias dappnode_down='docker compose ${=DNCORE_YMLS} down' +else + alias dappnode_status='docker compose $DNCORE_YMLS ps' + alias dappnode_stop='docker compose $DNCORE_YMLS stop && docker stop $(docker container ls -a -q -f name=DAppNode*)' + alias dappnode_start='docker compose $DNCORE_YMLS up -d && docker start $(docker container ls -a -q -f name=DAppNode*)' + alias dappnode_down='docker compose $DNCORE_YMLS down' +fi # Return open-vpn credentials from a specific user. e.g: dappnode_get dappnode_admin alias dappnode_openvpn_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get' # Return open-vpn admin credentials alias dappnode_openvpn='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials' # Return wifi credentials (ssid and password) -alias dappnode_wifi='cat /usr/src/dappnode/DNCORE/docker-compose-wifi.yml | grep "SSID\|WPA_PASSPHRASE"' +alias dappnode_wifi='cat "$DAPPNODE_CORE_DIR/docker-compose-wifi.yml" | grep "SSID\|WPA_PASSPHRASE"' # Return remote credentials in plain text. OPTIONS: # --qr (QR format). --local (local creds for NAT loopback issues) alias dappnode_wireguard='docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials' # Execute access_credentials.sh script to check for connectivity methods -alias dappnode_connect='/usr/bin/bash /usr/src/dappnode/scripts/dappnode_access_credentials.sh' +alias dappnode_connect='/usr/bin/bash "$DAPPNODE_DIR/scripts/dappnode_access_credentials.sh"' # Return all available commands alias dappnode_help='echo -e "\n\tDAppNode commands available:\n\n\tdappnode_help\t\tprints out this message\n\n\tdappnode_wifi\t\tget wifi credentials (SSID and password)\n\n\tdappnode_openvpn\tget Open VPN credentials\n\n\tdappnode_wireguard\tget Wireguard VPN credentials (dappnode_wireguard --help for more info)\n\n\tdappnode_connect\tcheck connectivity methods available in DAppNode\n\n\tdappnode_status\t\tget status of dappnode containers\n\n\tdappnode_start\t\tstart dappnode containers\n\n\tdappnode_stop\t\tstop dappnode containers\n"' # Compose alias for backward compatibility diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 0aa39464..e48a1e8f 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -68,39 +68,78 @@ jobs: sed -i -e "/HTTPS_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${HTTPS_VERSION}"/" .dappnode_profile cat .dappnode_profile - # ISO ATTENDED - - name: Build attended + # Debian ISO ATTENDED + - name: Build Debian attended run: | - sed -i -e "/UNATTENDED/s/true/false/" docker-compose.yml - docker compose build - docker compose up + export BASE_OS=debian + export UNATTENDED=false + docker compose up --build - # Verify ISO attended created - - name: Check iso attended + - name: Check Debian ISO attended run: | - ls -lrt images/DAppNode-debian-bookworm-amd64.iso + ls -lrt images/Dappnode-debian-*.iso - # Set new name for the release asset - - name: Set DAppNode attended ISO name + - name: Set Debian Dappnode attended ISO name run: | - cp ./images/DAppNode-debian-bookworm-amd64.iso DAppNode-${CORE_VERSION}-debian-bookworm-amd64.iso + file=$(ls images/Dappnode-debian-*.iso) + attended_filename="${file/images\/Dappnode-/Dappnode-${CORE_VERSION}-}" + mv "$file" "$attended_filename" - # ISO UNATTENDED - - name: Build unattended + # Debian ISO UNATTENDED + - name: Build Debian unattended run: | - sed -i -e "/UNATTENDED/s/false/true/" docker-compose.yml - docker compose build - docker compose up + export BASE_OS=debian + export UNATTENDED=true + docker compose up --build - # Verify ISO unattended was created - - name: Check iso unattended + - name: Check Debian ISO unattended run: | - ls -lrt images/DAppNode-debian-bookworm-amd64.iso + ls -lrt images/Dappnode-debian-*.iso # Set new name for the release asset - - name: Set DAppNode unttended ISO name + - name: Set Dappnode unttended ISO name + run: | + file=$(ls images/Dappnode-debian-*.iso) + + core_filename="${file/images\/Dappnode-/Dappnode-${CORE_VERSION}-}" + unattended_filename="${core_filename/%.iso/-unattended.iso}" + + mv "$file" "$unattended_filename" + + # Ubuntu ISO ATTENDED + - name: Build Ubuntu attended + run: | + export BASE_OS=ubuntu + export UNATTENDED=false + docker compose up --build + + - name: Check Ubuntu ISO attended + run: | + ls -lrt images/Dappnode-ubuntu-*.iso + + - name: Set Ubuntu Dappnode attended ISO name + run: | + file=$(ls images/Dappnode-ubuntu-*.iso) + attended_filename="${file/images\/Dappnode-/Dappnode-${CORE_VERSION}-}" + mv "$file" "$attended_filename" + + # Ubuntu ISO UNATTENDED + - name: Build Ubuntu unattended + run: | + export BASE_OS=ubuntu + export UNATTENDED=true + docker compose up --build + + - name: Check Ubuntu ISO unattended + run: | + ls -lrt images/Dappnode-ubuntu-*.iso + + - name: Set Ubuntu Dappnode unattended ISO name run: | - cp ./images/DAppNode-debian-bookworm-amd64.iso DAppNode-${CORE_VERSION}-debian-bookworm-amd64-unattended.iso + file=$(ls images/Dappnode-ubuntu-*.iso) + core_filename="${file/images\/Dappnode-/Dappnode-${CORE_VERSION}-}" + unattended_filename="${core_filename/%.iso/-unattended.iso}" + mv "$file" "$unattended_filename" - name: Create dappnode_profile.sh run: | @@ -112,8 +151,8 @@ jobs: with: name: test-artifact path: | - ./DAppNode-*-amd64.iso - ./DAppNode-*-amd64-unattended.iso + ./Dappnode-debian-*.iso + ./Dappnode-ubuntu-*.iso ./scripts/dappnode_install.sh ./scripts/dappnode_install_pre.sh ./scripts/dappnode_uninstall.sh diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 58b25b85..0307d510 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -21,7 +21,7 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: # Full git history is needed to get a proper list of changed files within `super-linter` fetch-depth: 0 @@ -33,3 +33,33 @@ jobs: FILTER_REGEX_EXCLUDE: .github/* DEFAULT_BRANCH: master GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + shell-compat: + name: Shell compatibility (.dappnode_profile) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + + steps: + - name: Checkout Code + uses: actions/checkout@v6 + + - name: Install zsh (Ubuntu) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y zsh + + - name: Parse check (bash) + run: bash -n .dappnode_profile + + - name: Parse check (zsh) + run: zsh -n .dappnode_profile + + - name: Source check (bash) + run: bash -lc 'set -euo pipefail; source ./.dappnode_profile' + + - name: Source check (zsh) + run: zsh -lc 'set -e; source ./.dappnode_profile; alias dappnode_status >/dev/null' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d289db8..74ad8bf8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,139 +26,293 @@ on: vpn: description: "Version of the OpenVPN Package. Only numbers" required: true - -env: - BIND_VERSION: ${{ github.event.inputs.bind }} - IPFS_VERSION: ${{ github.event.inputs.ipfs }} - DAPPMANAGER_VERSION: ${{ github.event.inputs.dappmanager }} - WIFI_VERSION: ${{ github.event.inputs.wifi }} - WIREGUARD_VERSION: ${{ github.event.inputs.wireguard }} - HTTPS_VERSION: ${{ github.event.inputs.https }} - VPN_VERSION: ${{ github.event.inputs.vpn }} - CORE_VERSION: ${{ github.event.inputs.core }} + notifications: + description: "IPFS hash of the Notifications Package. Must start with /ipfs/" + required: true + premium: + description: "IPFS hash of the Premium Package. Must start with /ipfs/" + required: true jobs: - pre-release: - name: create pre release + set-versions: + name: Set versions and check regex runs-on: ubuntu-latest - defaults: - run: - shell: bash - + outputs: + bind: ${{ steps.set_outputs.outputs.bind }} + ipfs: ${{ steps.set_outputs.outputs.ipfs }} + dappmanager: ${{ steps.set_outputs.outputs.dappmanager }} + wifi: ${{ steps.set_outputs.outputs.wifi }} + wireguard: ${{ steps.set_outputs.outputs.wireguard }} + https: ${{ steps.set_outputs.outputs.https }} + vpn: ${{ steps.set_outputs.outputs.vpn }} + notifications: ${{ steps.set_outputs.outputs.notifications }} + premium: ${{ steps.set_outputs.outputs.premium }} + core: ${{ steps.set_outputs.outputs.core }} steps: - # Regex for versions introduced - name: Check versions regex run: | - [[ $BIND_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $IPFS_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $DAPPMANAGER_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && \ - [[ $WIFI_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $WIREGUARD_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $HTTPS_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && \ - [[ $VPN_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $CORE_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "versions introduced in wrong format"; exit 1; } - + [[ "${{ github.event.inputs.bind }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "${{ github.event.inputs.ipfs }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "${{ github.event.inputs.dappmanager }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && \ + [[ "${{ github.event.inputs.wifi }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "${{ github.event.inputs.wireguard }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "${{ github.event.inputs.https }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && \ + [[ "${{ github.event.inputs.vpn }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "${{ github.event.inputs.core }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] && \ + [[ "${{ github.event.inputs.notifications }}" =~ ^/ipfs/.+$ ]] && [[ "${{ github.event.inputs.premium }}" =~ ^/ipfs/.+$ ]] || { echo "versions introduced in wrong format"; exit 1; } - name: Checkout uses: actions/checkout@v4 - - # Edit the profile with the new versions introduced - name: Set new versions run: | - sed -i -e "/BIND_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${BIND_VERSION}"/" .dappnode_profile - sed -i -e "/IPFS_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${IPFS_VERSION}"/" .dappnode_profile - sed -i -e "/VPN_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${VPN_VERSION}"/" .dappnode_profile - sed -i -e "/DAPPMANAGER_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${DAPPMANAGER_VERSION}"/" .dappnode_profile - sed -i -e "/WIFI_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${WIFI_VERSION}"/" .dappnode_profile - sed -i -e "/WIREGUARD_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${WIREGUARD_VERSION}"/" .dappnode_profile - sed -i -e "/HTTPS_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${HTTPS_VERSION}"/" .dappnode_profile + sed -i -e "/BIND_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${{ github.event.inputs.bind }}"/" .dappnode_profile + sed -i -e "/IPFS_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${{ github.event.inputs.ipfs }}"/" .dappnode_profile + sed -i -e "/VPN_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${{ github.event.inputs.vpn }}"/" .dappnode_profile + sed -i -e "/DAPPMANAGER_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${{ github.event.inputs.dappmanager }}"/" .dappnode_profile + sed -i -e "/WIFI_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${{ github.event.inputs.wifi }}"/" .dappnode_profile + sed -i -e "/WIREGUARD_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/"${{ github.event.inputs.wireguard }}"/" .dappnode_profile + sed -i -e "/HTTPS_VERSION/s/[0-9]*\.[0-9]*\.[0-9]*/${{ github.event.inputs.https }}/" .dappnode_profile + sed -i -e "s|^export NOTIFICATIONS_VERSION=.*|export NOTIFICATIONS_VERSION=\"${{ github.event.inputs.notifications }}\"|" .dappnode_profile + sed -i -e "s|^export PREMIUM_VERSION=.*|export PREMIUM_VERSION=\"${{ github.event.inputs.premium }}\"|" .dappnode_profile cat .dappnode_profile - - # ISO ATTENDED - - name: Build attended + - name: Create dappnode_profile.sh + run: cp .dappnode_profile dappnode_profile.sh + - name: Upload dappnode_profile.sh + uses: actions/upload-artifact@v4 + with: + name: dappnode_profile + path: dappnode_profile.sh + - name: Set outputs + id: set_outputs run: | - sed -i -e "/UNATTENDED/s/true/false/" docker-compose.yml - docker compose build - docker compose up + echo "core=${{ github.event.inputs.core }}" >> $GITHUB_OUTPUT + echo "bind=${{ github.event.inputs.bind }}" >> $GITHUB_OUTPUT + echo "ipfs=${{ github.event.inputs.ipfs }}" >> $GITHUB_OUTPUT + echo "dappmanager=${{ github.event.inputs.dappmanager }}" >> $GITHUB_OUTPUT + echo "wifi=${{ github.event.inputs.wifi }}" >> $GITHUB_OUTPUT + echo "wireguard=${{ github.event.inputs.wireguard }}" >> $GITHUB_OUTPUT + echo "https=${{ github.event.inputs.https }}" >> $GITHUB_OUTPUT + echo "vpn=${{ github.event.inputs.vpn }}" >> $GITHUB_OUTPUT + echo "notifications=${{ github.event.inputs.notifications }}" >> $GITHUB_OUTPUT + echo "premium=${{ github.event.inputs.premium }}" >> $GITHUB_OUTPUT - # Verify ISO attended created - - name: Check iso attended + build-debian-attended: + name: Build Debian attended ISO + runs-on: ubuntu-latest + needs: set-versions + steps: + - uses: actions/checkout@v4 + - name: Download dappnode_profile + uses: actions/download-artifact@v4 + with: + name: dappnode_profile + - name: Rename dappnode_profile.sh to .dappnode_profile + run: mv dappnode_profile.sh .dappnode_profile + - name: Build Debian attended run: | - ls -lrt images/DAppNode-debian-bookworm-amd64.iso - - # Set new name for the release asset - - name: Set DAppNode attended ISO name + export BASE_OS=debian + export UNATTENDED=false + docker compose up --build + - name: Set Debian Dappnode attended ISO name run: | - cp ./images/DAppNode-debian-bookworm-amd64.iso DAppNode-${CORE_VERSION}-debian-bookworm-amd64.iso + file=$(ls images/Dappnode-debian-*.iso) + filename=$(basename "$file") + core_filename="Dappnode-${{ needs.set-versions.outputs.core }}-debian-${filename#Dappnode-debian-}" + attended_filename="${core_filename/%.iso/-attended.iso}" + sudo cp "$file" "images/$attended_filename" + - name: Upload Debian attended ISO + uses: actions/upload-artifact@v4 + with: + name: debian-attended-iso + path: images/*-attended.iso + - name: Get SHA-256 Debian attended + run: | + file=$(find images/ -type f -name '*-attended.iso') + shasum -a 256 $file > SHASUM_DEBIAN_ATTENDED.txt + - name: Upload Debian attended SHA256 + uses: actions/upload-artifact@v4 + with: + name: debian-attended-sha + path: SHASUM_DEBIAN_ATTENDED.txt - # ISO UNATTENDED - - name: Build unattended + build-debian-unattended: + name: Build Debian unattended ISO + runs-on: ubuntu-latest + needs: set-versions + steps: + - uses: actions/checkout@v4 + - name: Download dappnode_profile + uses: actions/download-artifact@v4 + with: + name: dappnode_profile + - name: Rename dappnode_profile.sh to .dappnode_profile + run: mv dappnode_profile.sh .dappnode_profile + - name: Build Debian unattended run: | - sed -i -e "/UNATTENDED/s/false/true/" docker-compose.yml + export BASE_OS=debian + export UNATTENDED=true docker compose build docker compose up - - # Verify ISO unattended was created - - name: Check iso unattended + - name: Set Debian Dappnode unattended ISO name run: | - ls -lrt images/DAppNode-debian-bookworm-amd64.iso - - # Set new name for the release asset - - name: Set DAppNode unttended ISO name + file=$(ls images/Dappnode-debian-*.iso) + filename=$(basename "$file") + core_filename="Dappnode-${{ needs.set-versions.outputs.core }}-debian-${filename#Dappnode-debian-}" + unattended_filename="${core_filename/%.iso/-unattended.iso}" + sudo cp "$file" "images/$unattended_filename" + - name: Upload Debian unattended ISO + uses: actions/upload-artifact@v4 + with: + name: debian-unattended-iso + path: images/*-unattended.iso + - name: Get SHA-256 Debian unattended run: | - cp ./images/DAppNode-debian-bookworm-amd64.iso DAppNode-${CORE_VERSION}-debian-bookworm-amd64-unattended.iso + file=$(find images/ -type f -name '*-unattended.iso') + shasum -a 256 $file > SHASUM_DEBIAN_UNATTENDED.txt + - name: Upload Debian unattended SHA256 + uses: actions/upload-artifact@v4 + with: + name: debian-unattended-sha + path: SHASUM_DEBIAN_UNATTENDED.txt - # Create profile.sh script (not able to set dot (.) before the name in the gh release asset) - - name: Create dappnode_profile.sh + build-ubuntu-unattended: + name: Build Ubuntu unattended ISO + runs-on: ubuntu-latest + needs: set-versions + steps: + - uses: actions/checkout@v4 + - name: Download dappnode_profile + uses: actions/download-artifact@v4 + with: + name: dappnode_profile + - name: Rename dappnode_profile.sh to .dappnode_profile + run: mv dappnode_profile.sh .dappnode_profile + - name: Build Ubuntu unattended run: | - cp .dappnode_profile dappnode_profile.sh - - # SHASUMs - - name: Get SHA-256 attended - id: shasum-attended + export BASE_OS=ubuntu + export UNATTENDED=true + docker compose up --build + - name: Set Ubuntu Dappnode unattended ISO name run: | - SHASUM_ATTENDED=$(shasum -a 256 DAppNode-${CORE_VERSION}-debian-bookworm-amd64.iso) - echo "::set-output name=SHASUM_ATTENDED::$SHASUM_ATTENDED" - - - name: Get SHA-256 unattended - id: shasum-unattended + file=$(ls images/Dappnode-ubuntu-*.iso) + filename=$(basename "$file") + core_filename="Dappnode-${{ needs.set-versions.outputs.core }}-ubuntu-${filename#Dappnode-ubuntu-}" + unattended_filename="${core_filename/%.iso/-unattended.iso}" + sudo cp "$file" "images/$unattended_filename" + - name: Get SHA-256 Ubuntu unattended run: | - SHASUM_UNATTENDED=$(shasum -a 256 DAppNode-${CORE_VERSION}-debian-bookworm-amd64-unattended.iso) - echo "::set-output name=SHASUM_UNATTENDED::$SHASUM_UNATTENDED" + file=$(find images/ -type f -name '*-ubuntu-*-unattended.iso') + shasum -a 256 $file > SHASUM_UBUNTU_UNATTENDED.txt + - name: Upload Ubuntu unattended ISO and SHA256 to SSH + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.ISO_SSH_HOST }} + username: ${{ secrets.ISO_SSH_USER }} + key: ${{ secrets.ISO_SSH_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT }} + source: SHASUM_UBUNTU_UNATTENDED.txt,images/*-ubuntu-*-unattended.iso + target: ${{ secrets.ISO_SSH_PATH }} + overwrite: true + - name: Upload Ubuntu unattended SHA256 as artifact + uses: actions/upload-artifact@v4 + with: + name: ubuntu-unattended-sha + path: SHASUM_UBUNTU_UNATTENDED.txt - # Release body + release: + name: Combine, release, and upload + runs-on: ubuntu-latest + needs: + - set-versions + - build-debian-attended + - build-debian-unattended + - build-ubuntu-unattended + steps: + - uses: actions/checkout@v4 + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: ./artifacts + - name: Move ISOs and SHAs + run: | + mkdir -p images + mv artifacts/debian-attended-iso/* images/ + mv artifacts/debian-unattended-iso/* images/ + mv artifacts/debian-attended-sha/* . + mv artifacts/debian-unattended-sha/* . + mv artifacts/ubuntu-unattended-sha/* . + mv artifacts/dappnode_profile/* . - name: Write release content run: | - echo -en "# Versions\n| Package | Version |\n|---|---|\nbind.dnp.dappnode.eth|${BIND_VERSION}|\n|ipfs.dnp.dappnode.eth|${IPFS_VERSION}|\n|vpn.dnp.dappnode.eth |${VPN_VERSION}|\n|dappmanager.dnp.dappnode.eth|${DAPPMANAGER_VERSION}|\n|wifi.dnp.dappnode.eth|${WIFI_VERSION}|\n|https.dnp.dappnode.eth|${HTTPS_VERSION}|\n|wireguard.dnp.dappnode.eth|${WIREGUARD_VERSION}|\n# Changes\nChanges implemented in release ${CORE_VERSION}\n# Attended version\nInstall and customize DAppNode using the attended ISO: **DAppNode-${CORE_VERSION}-debian-bookworm-amd64.iso**\n\n## ISO SHA-256 Checksum\n\`\`\`\nshasum -a 256 DAppNode-${CORE_VERSION}-debian-bookworm-amd64.iso\n${SHASUM_ATTENDED}\n\`\`\`\n# Unattended version\nInstall DAppNode easily using the unattended ISO: **DAppNode-${CORE_VERSION}-debian-bookworm-amd64-unattended.iso**\nDo a reboot right after the installation\n:warning: **Warning**: This ISO will install Dappnode automatically, deleting all existing partitions on the disk\n\ndefault login data:\n - **__user__**: dappnode\n - **__password__**: dappnode.s0\n## ISO SHA-256 Checksum\n\`\`\`\nshasum -a 256 DAppNode-${CORE_VERSION}-debian-bookworm-amd64-unattended.iso\n${SHASUM_UNATTENDED}\n\`\`\`\n# DAppNode for Raspberry Pi 4 64bit\n[Instructions](https://github.com/dappnode/DAppNode/wiki/DAppNodeARM-Installation-Guide)\n\ndefault login data:\n - **__user__**: dappnode\n - **__password__**: dappnodepi" > CHANGELOG.md - cat CHANGELOG.md - env: - SHASUM_ATTENDED: ${{ steps.shasum-attended.outputs.SHASUM_ATTENDED }} - SHASUM_UNATTENDED: ${{ steps.shasum-unattended.outputs.SHASUM_UNATTENDED }} + DEBIAN_ATTENDED_ISO=$(basename "$(find images/ -type f -name '*-debian-*-attended.iso' -print -quit)") + DEBIAN_UNATTENDED_ISO=$(basename "$(find images/ -type f -name '*-debian-*-unattended.iso' -print -quit)") + UBUNTU_UNATTENDED_ISO=$(basename "$(awk '{print $2}' SHASUM_UBUNTU_UNATTENDED.txt)") + SHASUM_DEBIAN_ATTENDED=$(sed "s#images/##g" SHASUM_DEBIAN_ATTENDED.txt) + SHASUM_DEBIAN_UNATTENDED=$(sed "s#images/##g" SHASUM_DEBIAN_UNATTENDED.txt) + SHASUM_UBUNTU_UNATTENDED=$(sed "s#images/##g" SHASUM_UBUNTU_UNATTENDED.txt) + cat > CHANGELOG.md <> "$GITHUB_OUTPUT" + exit 0 + fi + + # Update the script + sed -i "s|${CURRENT_ISO}|${LATEST_ISO}|g" "$SCRIPT" + sed -i "s|${CURRENT_SHA}|${LATEST_SHA}|" "$SCRIPT" + + echo "updated=true" >> "$GITHUB_OUTPUT" + echo "current_iso=$CURRENT_ISO" >> "$GITHUB_OUTPUT" + echo "latest_iso=$LATEST_ISO" >> "$GITHUB_OUTPUT" + + - name: Create or update Pull Request for Ubuntu ISO + if: steps.ubuntu.outputs.updated == 'true' + id: ubuntu-pr + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ steps.app-token.outputs.token }} + commit-message: "Update Ubuntu base ISO to ${{ steps.ubuntu.outputs.latest_iso }}" + branch: auto/update-ubuntu-iso + title: "Update Ubuntu base ISO to ${{ steps.ubuntu.outputs.latest_iso }}" + body: | + Automated update of the Ubuntu base ISO. + + - **Previous**: `${{ steps.ubuntu.outputs.current_iso }}` + - **New**: `${{ steps.ubuntu.outputs.latest_iso }}` + + This PR was created automatically by the `update-base-isos` workflow. + labels: automated + + - name: Sync PR title and body on subsequent runs + if: steps.ubuntu-pr.outputs.pull-request-operation == 'updated' + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR_NUMBER: ${{ steps.ubuntu-pr.outputs.pull-request-number }} + CURRENT_ISO: ${{ steps.ubuntu.outputs.current_iso }} + LATEST_ISO: ${{ steps.ubuntu.outputs.latest_iso }} + run: | + BODY=$(printf 'Automated update of the Ubuntu base ISO.\n\n- **Previous**: `%s`\n- **New**: `%s`\n\nThis PR was created automatically by the `update-base-isos` workflow.' "$CURRENT_ISO" "$LATEST_ISO") + gh pr edit "$PR_NUMBER" \ + --title "Update Ubuntu base ISO to $LATEST_ISO" \ + --body "$BODY" + + update-debian-iso: + name: Check for Debian ISO updates + runs-on: ubuntu-latest + steps: + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ vars.TROPI_APP_ID }} + private-key: ${{ secrets.TROPI_APP_PRIVATE_KEY }} + + - name: Checkout Code + uses: actions/checkout@v6 + + - name: Check for new Debian ISO version + id: debian + run: | + SCRIPT="iso/scripts/generate_dappnode_iso_debian.sh" + + # Get the current ISO and checksum from the script + CURRENT_ISO=$(grep -oP 'BASE_ISO_NAME="\K[^"]*' "$SCRIPT") + CURRENT_SHA=$(grep -oP 'BASE_ISO_SHASUM="\K[^" ]*' "$SCRIPT") + echo "Current Debian ISO: $CURRENT_ISO" + + # Fetch the SHA256SUMS file from Debian current release + SHA256SUMS=$(curl -fsSL "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA256SUMS") + + # Find the standard netinst ISO, excluding the Edu and Mac variants + LATEST_LINE=$(echo "$SHA256SUMS" | + grep -E '[[:space:]]\*?debian-[0-9]+\.[0-9]+\.[0-9]+-amd64-netinst\.iso$' | + sort -V -k2 | tail -1 || true) + if [ -z "$LATEST_LINE" ]; then + echo "Could not find netinst ISO in SHA256SUMS" + exit 1 + fi + + LATEST_SHA=$(echo "$LATEST_LINE" | awk '{print $1}') + LATEST_ISO=$(echo "$LATEST_LINE" | awk '{print $2}' | sed 's|^\*||') + LATEST_ISO=$(basename "$LATEST_ISO") + + if [[ ! "$LATEST_SHA" =~ ^[0-9a-f]{64}$ ]] || + [[ ! "$LATEST_ISO" =~ ^debian-[0-9]+\.[0-9]+\.[0-9]+-amd64-netinst\.iso$ ]]; then + echo "Debian SHA256SUMS contains an invalid ISO entry" + exit 1 + fi + + echo "Latest Debian ISO: $LATEST_ISO (sha256: $LATEST_SHA)" + + # Nothing to do only when both the filename and checksum match + if [ "$CURRENT_ISO" = "$LATEST_ISO" ] && [ "$CURRENT_SHA" = "$LATEST_SHA" ]; then + echo "Debian ISO is already up to date." + echo "updated=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + # Update the script + sed -i "s|${CURRENT_ISO}|${LATEST_ISO}|g" "$SCRIPT" + sed -i "s|${CURRENT_SHA}|${LATEST_SHA}|" "$SCRIPT" + + echo "updated=true" >> "$GITHUB_OUTPUT" + echo "current_iso=$CURRENT_ISO" >> "$GITHUB_OUTPUT" + echo "latest_iso=$LATEST_ISO" >> "$GITHUB_OUTPUT" + + - name: Create or update Pull Request for Debian ISO + if: steps.debian.outputs.updated == 'true' + id: debian-pr + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ steps.app-token.outputs.token }} + commit-message: "Update Debian base ISO to ${{ steps.debian.outputs.latest_iso }}" + branch: auto/update-debian-iso + title: "Update Debian base ISO to ${{ steps.debian.outputs.latest_iso }}" + body: | + Automated update of the Debian base ISO. + + - **Previous**: `${{ steps.debian.outputs.current_iso }}` + - **New**: `${{ steps.debian.outputs.latest_iso }}` + + This PR was created automatically by the `update-base-isos` workflow. + labels: automated + + - name: Sync PR title and body on subsequent runs + if: steps.debian-pr.outputs.pull-request-operation == 'updated' + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR_NUMBER: ${{ steps.debian-pr.outputs.pull-request-number }} + CURRENT_ISO: ${{ steps.debian.outputs.current_iso }} + LATEST_ISO: ${{ steps.debian.outputs.latest_iso }} + run: | + BODY=$(printf 'Automated update of the Debian base ISO.\n\n- **Previous**: `%s`\n- **New**: `%s`\n\nThis PR was created automatically by the `update-base-isos` workflow.' "$CURRENT_ISO" "$LATEST_ISO") + gh pr edit "$PR_NUMBER" \ + --title "Update Debian base ISO to $LATEST_ISO" \ + --body "$BODY" diff --git a/.github/workflows/validate_autoinstall.yml b/.github/workflows/validate_autoinstall.yml new file mode 100644 index 00000000..45b71ac0 --- /dev/null +++ b/.github/workflows/validate_autoinstall.yml @@ -0,0 +1,42 @@ +name: Validate Ubuntu autoinstall YAML Files + +on: + push: + pull_request: + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install check-jsonschema yamllint yq + + - name: Lint attended autoinstall.yaml + run: yamllint -c .yamllint iso/preseeds/ubuntu/autoinstall.yaml + + - name: Lint unattended autoinstall.yaml + run: yamllint -c .yamllint iso/preseeds/ubuntu/autoinstall_unattended.yaml + + - name: Download JSON schema + run: curl -o schema.json https://raw.githubusercontent.com/canonical/subiquity/main/autoinstall-schema.json + + - name: Extract autoinstall properties from YAML files + run: | + yq '.autoinstall' iso/preseeds/ubuntu/autoinstall.yaml > attended.yaml + yq '.autoinstall' iso/preseeds/ubuntu/autoinstall_unattended.yaml > unattended.yaml + + - name: Validate attended autoinstall.yaml + run: | + check-jsonschema --schemafile schema.json attended.yaml + + - name: Validate unattended autoinstall.yaml + run: | + check-jsonschema --schemafile schema.json unattended.yaml diff --git a/.yamllint b/.yamllint new file mode 100644 index 00000000..c9b624e1 --- /dev/null +++ b/.yamllint @@ -0,0 +1,6 @@ +# .yamllint +extends: default + +rules: + line-length: + max: 150 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e5ef57e6..a09836ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,10 @@ FROM docker:dind -# hadolint ignore=DL3018 -RUN apk update && \ - apk add --no-cache xorriso git xz curl ca-certificates iptables cpio bash perl-utils \ - rm -rf /var/cache/apk/* - -#RUN apk add -U --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing aufs-util -# RUN addgroup -g 2999 docker +# Install required packages +RUN apk update && \ + apk add --no-cache xorriso git xz curl ca-certificates iptables cpio bash perl-utils -# Create app directory WORKDIR /usr/src/app COPY . . -CMD ["/usr/src/app/iso/scripts/generate_ISO.sh"] +CMD ["/usr/src/app/iso/scripts/generate_ISO.sh"] diff --git a/README.md b/README.md index 89817f1c..6b13682a 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ The release will contain: - Assets: - Scripts: `dappnode_access_credentials.sh`, `dappnode_install.sh`, `dappnode_uninstall.sh`, `dappnode_install_pre.sh`, `dappnode_profile.sh` - - ISOs: `DAppNode-vX-debian-bullseye-amd64-unattended.iso`, `DAppNode-vX-debian-bullseye-amd64-unattended.iso` + - ISOs: `Dappnode-vX-debian-VERSION-amd64-netinst-attended.iso`, `Dappnode-vX-debian-VERSION-amd64-netinst-unattended.iso` - Release body: - Table with core packages versions - Changes section diff --git a/docker-compose.yml b/docker-compose.yml index 7eddc984..b358db40 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,8 @@ services: environment: - BUILD=false # In case you want to re-generate a all the images, not recommended - CLEAN=true # it remove the images directory - - UNATTENDED=false # UNATTENDED version + - UNATTENDED=${UNATTENDED} # UNATTENDED version + - BASE_OS=${BASE_OS} # Base OS version (debian or ubuntu) volumes: - ./images:/images - "/var/run/docker.sock:/var/run/docker.sock" diff --git a/iso/boot/splash.png b/iso/boot/splash.png index 835dc493..a6f4196e 100644 Binary files a/iso/boot/splash.png and b/iso/boot/splash.png differ diff --git a/iso/boot/ubuntu/grub.cfg b/iso/boot/ubuntu/grub.cfg new file mode 100644 index 00000000..88c8305b --- /dev/null +++ b/iso/boot/ubuntu/grub.cfg @@ -0,0 +1,21 @@ +if loadfont unicode ; then + set gfxmode=800x600 + insmod efi_gop + insmod efi_uga + insmod video_bochs + insmod video_cirrus + insmod gfxterm + insmod png + terminal_output gfxterm +fi + +set timeout=6 + +set theme=/boot/grub/themes/dappnode/theme.txt + +menuentry "Install Dappnode (over Ubuntu Server)" { + set background_color=black + set gfxpayload=keep # Maintain the graphical resolution through the booting + linux /casper/vmlinuz autoinstall vga=788 FRONTEND_BACKGROUND=dark --- # Added autoinstall to make it unattended + initrd /casper/initrd +} \ No newline at end of file diff --git a/iso/boot/ubuntu/themes/dappnode/splash.png b/iso/boot/ubuntu/themes/dappnode/splash.png new file mode 100644 index 00000000..236fa034 Binary files /dev/null and b/iso/boot/ubuntu/themes/dappnode/splash.png differ diff --git a/iso/boot/ubuntu/themes/dappnode/theme.txt b/iso/boot/ubuntu/themes/dappnode/theme.txt new file mode 100644 index 00000000..f096526d --- /dev/null +++ b/iso/boot/ubuntu/themes/dappnode/theme.txt @@ -0,0 +1,41 @@ +title-color: "white" +title-text: "Dappnode Installer" +title-font: "Sans Regular 16" +desktop-color: "black" +desktop-image: "/boot/grub/themes/dappnode/splash.png" +message-color: "white" +message-bg-color: "black" +terminal-font: "Sans Regular 12" + ++ boot_menu { + left = 18% + width = 50% + top = 200 + height = 200 + item_font = "Sans Regular 12" + item_color = #d3d3d3 + selected_item_color = "white" + item_height = 20 + item_padding = 15 + item_spacing = 5 +} + ++ vbox { + top = 100%-60 + left = 10% + + hbox { + top = 0 + left = 20% + + label {text = "Enter: " font = "Sans 10" color = "white" align = "left"} + + label {text = "Select " font = "Sans 10" color = "#d3d3d3" align = "left"} + } + + hbox { + top = 0 + left = 20% + + label {text = "E: " font = "Sans 10" color = "white" align = "left"} + + label {text = "Edit Selection " font = "Sans 10" color = "#d3d3d3" align = "left"} + + label {text = " " font = "Sans 10" color = "white" align = "left"} + + label {text = "C: " font = "Sans 10" color = "white" align = "left"} + + label {text = "GRUB Command line" font = "Sans 10" color = "#d3d3d3" align = "left"} + } +} diff --git a/iso/preseeds/preseed.cfg b/iso/preseeds/preseed.cfg index 761f5075..1bd38005 100644 --- a/iso/preseeds/preseed.cfg +++ b/iso/preseeds/preseed.cfg @@ -1,7 +1,7 @@ # Preseed-example: https://www.debian.org/releases/stable/example-preseed.txt # Buster preseed example: https://www.debian.org/releases/buster/example-preseed.txt # Bullseye preseed example: https://www.debian.org/releases/testing/example-preseed.txt -# Bookworm preseed example: https://www.debian.org/releases/bookworm/example-preseed.txt +# Trixie preseed example: https://www.debian.org/releases/trixie/example-preseed.txt ### Network configuration d-i hw-detect/load_firmware boolean true d-i netcfg/choose_interface select auto @@ -25,7 +25,7 @@ d-i mirror/country string manual d-i mirror/http/hostname string deb.debian.org d-i mirror/http/directory string /debian d-i mirror/http/proxy string -d-i apt-setup/local0/repository string http://deb.debian.org/debian/ bookworm main contrib non-free-firmware +d-i apt-setup/local0/repository string http://deb.debian.org/debian/ trixie main contrib non-free-firmware d-i apt-setup/cdrom/set-first boolean false d-i apt-setup/cdrom/set-next boolean false d-i apt-setup/cdrom/set-failed boolean false diff --git a/iso/preseeds/preseed_unattended.cfg b/iso/preseeds/preseed_unattended.cfg index be31dba6..8316fd7c 100644 --- a/iso/preseeds/preseed_unattended.cfg +++ b/iso/preseeds/preseed_unattended.cfg @@ -1,7 +1,7 @@ # Preseed-example: https://www.debian.org/releases/stable/example-preseed.txt # Buster preseed example: https://www.debian.org/releases/buster/example-preseed.txt # Bullseye preseed example: https://www.debian.org/releases/testing/example-preseed.txt -# Bookworm preseed example: https://www.debian.org/releases/bookworm/example-preseed.txt +# Trixie preseed example: https://www.debian.org/releases/trixie/example-preseed.txt ### Localization d-i debian-installer/locale string en_US.UTF-8 d-i debian-installer/keymap select us @@ -57,12 +57,12 @@ d-i grub-installer/bootdev string default ### Package selection tasksel tasksel/first multiselect standard d-i pkgsel/include string openssh-server vim sudo build-essential linux-headers-$(uname -r) iw iwd wpasupplicant intel-microcode iucode-tool firmware-misc-nonfree firmware-iwlwifi avahi-utils iptables -d-i apt-setup/use_mirror boolean false +d-i apt-setup/use_mirror boolean true d-i mirror/country string manual d-i mirror/http/hostname string deb.debian.org d-i mirror/http/directory string /debian d-i mirror/http/proxy string -d-i apt-setup/local0/repository string http://deb.debian.org/debian/ bookworm main contrib non-free-firmware +d-i apt-setup/local0/repository string http://deb.debian.org/debian/ trixie main contrib non-free-firmware d-i apt-setup/cdrom/set-first boolean false d-i apt-setup/cdrom/set-next boolean false d-i apt-setup/cdrom/set-failed boolean false diff --git a/iso/preseeds/ubuntu/autoinstall.yaml b/iso/preseeds/ubuntu/autoinstall.yaml new file mode 100644 index 00000000..4fb3eadc --- /dev/null +++ b/iso/preseeds/ubuntu/autoinstall.yaml @@ -0,0 +1,30 @@ +# cloud-config +--- +autoinstall: + version: 1 + interactive-sections: + - identity + - keyboard + - locale + - network + - storage + - timezone + - ssh + + packages: + - linux-generic + - wpasupplicant + - intel-microcode + - iucode-tool + - iptables + + late-commands: + - "curtin in-target --target=/target -- apt-get update" + - "curtin in-target --target=/target -- apt-get install -y chrony build-essential iw iwd avahi-utils" + - "mkdir -p /target/usr/src/dappnode" + - "cp -ar /cdrom/dappnode/* /target/usr/src/dappnode/" + - "cp -a /cdrom/dappnode/scripts/rc.local /target/etc/rc.local" + - "chmod +x /target/usr/src/dappnode/scripts/dappnode_install_pre.sh" + - "touch /target/usr/src/dappnode/.firstboot" + - "cp -ar /etc/netplan/* /target/etc/netplan/" # Necessary for prerequisites + - "curtin in-target --target=/target -- /usr/src/dappnode/scripts/dappnode_install_pre.sh UPDATE" diff --git a/iso/preseeds/ubuntu/autoinstall_unattended.yaml b/iso/preseeds/ubuntu/autoinstall_unattended.yaml new file mode 100644 index 00000000..0e4fd24e --- /dev/null +++ b/iso/preseeds/ubuntu/autoinstall_unattended.yaml @@ -0,0 +1,45 @@ +# cloud-config +--- +autoinstall: + version: 1 + + locale: en_US.UTF-8 + + keyboard: + layout: us + + # network left as default (DHCP in interfaces named en* or eth*) + storage: + layout: + name: lvm + sizing-policy: all + + identity: + hostname: dappnode + username: dappnode + password: "$6$insecur3$rnEv9Amdjn3ctXxPYOlzj/cwvLT43GjWzkPECIHNqd8Vvza5bMG8QqMwEIBKYqnj609D.4ngi4qlmt29dLE.71" + + ssh: + install-server: true + # By default, the password is allowed if no authorized keys are provided + + packages: + - linux-generic + - wpasupplicant + - intel-microcode + - iucode-tool + - iptables + + timezone: UTC + + late-commands: + - "curtin in-target --target=/target -- apt-get update" + - "curtin in-target --target=/target -- apt-get install -y chrony build-essential iw iwd avahi-utils" + - "mkdir -p /target/usr/src/dappnode" + - "cp -ar /cdrom/dappnode/* /target/usr/src/dappnode/" + - "cp -a /cdrom/dappnode/scripts/rc.local /target/etc/rc.local" + - "chmod +x /target/usr/src/dappnode/scripts/dappnode_install_pre.sh" + - "touch /target/usr/src/dappnode/.firstboot" + - "cp -ar /etc/netplan/* /target/etc/netplan/" # Necessary for prerequisites + - "curtin in-target --target=/target -- /usr/src/dappnode/scripts/dappnode_install_pre.sh UPDATE" + # TODO: Handle /etc/network/interfaces and /etc/network/devhotplug diff --git a/iso/scripts/common_iso_generation.sh b/iso/scripts/common_iso_generation.sh new file mode 100644 index 00000000..1cd65a0c --- /dev/null +++ b/iso/scripts/common_iso_generation.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +WORKDIR="/usr/src/app" +ISO_BUILD_PATH="${WORKDIR}/dappnode-iso" +DAPPNODE_ISO_PREFIX="Dappnode-" + +download_iso() { + local iso_path=$1 + local iso_name=$2 + local iso_url=$3 + + echo "[INFO] Downloading base ISO image: ${iso_name}..." + if [ ! -f "${iso_path}" ]; then + wget "${iso_url}" -O "${iso_path}" + fi + echo "[INFO] Download complete!" +} + +verify_download() { + local iso_path=$1 + local expected_shasum=$2 + + echo "[INFO] Verifying download..." + [[ "$(shasum -a 256 ${iso_path})" != "$expected_shasum" ]] && { + echo "[ERROR] Wrong shasum for ${iso_path}" + exit 1 + } + echo "[INFO] Verification complete!" +} + +clean_old_files() { + local iso_extraction_dir=$1 + local base_iso_prefix=$2 + + echo "[INFO] Cleaning old files..." + rm -rf "${iso_extraction_dir}º" + rm -rf "${base_iso_prefix}*" +} + +extract_iso() { + local iso_path=$1 + local extraction_target_dir=$2 + + echo "[INFO] Extracting the ISO..." + osirrox -indev "${iso_path}" -extract / "${extraction_target_dir}" +} + +# Using a 512-byte block size to ensure the entire Master Boot Record (MBR) is captured. +# The MBR contains boot code, the partition table, and a boot signature, all essential for creating bootable media. +# This ensures that the new ISO being created is bootable under different system setups +prepare_boot_process() { + local iso_path=$1 + local mbr_output_path=$2 + local block_size=512 + + echo "[INFO] Obtaining the MBR for hybrid ISO..." + dd if="${iso_path}" bs=${block_size} count=1 of="${mbr_output_path}" +} + +add_dappnode_files_to_iso_build() { + local iso_build_path=$1 + local workdir=$2 + + echo "[INFO] Creating necessary directories and copying files..." + mkdir -p ${iso_build_path}/dappnode + cp -r ${workdir}/scripts ${iso_build_path}/dappnode + cp -r ${workdir}/dappnode/* ${iso_build_path}/dappnode +} + +# TODO: Is this ok for Ubuntu? Check what this is for +handle_checksums() { + echo "Fix md5 sum..." + # shellcheck disable=SC2046 + md5sum $(find ! -name "md5sum.txt" ! -path "./isolinux/*" -type f) >md5sum.txt +} diff --git a/iso/scripts/generate_ISO.sh b/iso/scripts/generate_ISO.sh index 024e5397..bf241775 100755 --- a/iso/scripts/generate_ISO.sh +++ b/iso/scripts/generate_ISO.sh @@ -22,4 +22,8 @@ fi mkdir -p /usr/src/app/dappnode touch /usr/src/app/dappnode/iso_install.log -/usr/src/app/iso/scripts/generate_dappnode_iso_debian.sh +if [ "$BASE_OS" = "ubuntu" ]; then + /usr/src/app/iso/scripts/generate_dappnode_iso_ubuntu.sh +else + /usr/src/app/iso/scripts/generate_dappnode_iso_debian.sh +fi diff --git a/iso/scripts/generate_dappnode_iso_debian.sh b/iso/scripts/generate_dappnode_iso_debian.sh index c1c9b132..4ec4a93d 100755 --- a/iso/scripts/generate_dappnode_iso_debian.sh +++ b/iso/scripts/generate_dappnode_iso_debian.sh @@ -1,85 +1,99 @@ #!/bin/bash set -e -# Source = https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.10.0-amd64-netinst.iso -ISO_NAME=debian-12.10.0-amd64-netinst.iso -ISO_PATH="/images/${ISO_NAME}" -ISO_URL=https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/ -SHASUM="ee8d8579128977d7dc39d48f43aec5ab06b7f09e1f40a9d98f2a9d149221704a ${ISO_PATH}" - -echo "Downloading debian ISO image: ${ISO_NAME}..." -if [ ! -f ${ISO_PATH} ]; then - wget ${ISO_URL}/${ISO_NAME} \ - -O ${ISO_PATH} -fi -echo "Done!" - -echo "Verifying download..." -[[ "$(shasum -a 256 ${ISO_PATH})" != "$SHASUM" ]] && { - echo "ERROR: wrong shasum" - exit 1 +SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") + +source ${SCRIPTS_DIR}/common_iso_generation.sh + +BASE_ISO_NAME="debian-13.5.0-amd64-netinst.iso" +BASE_ISO_VERSION="${BASE_ISO_NAME#debian-}" +BASE_ISO_VERSION="${BASE_ISO_VERSION%-amd64-netinst.iso}" +BASE_ISO_PATH="/images/${BASE_ISO_NAME}" +BASE_ISO_URL="https://cdimage.debian.org/mirror/cdimage/archive/${BASE_ISO_VERSION}/amd64/iso-cd/${BASE_ISO_NAME}" +BASE_ISO_SHASUM="95838884f5ea6c82421dfe6baaa5a639dbbe6756c1e380f9fe7a7cb0c1949d2a ${BASE_ISO_PATH}" + +DAPPNODE_ISO_NAME="${DAPPNODE_ISO_PREFIX}${BASE_ISO_NAME}" +DAPPNODE_ISO_PATH="/images/${DAPPNODE_ISO_NAME}" + +customize_debian_preseed() { + local iso_build_path=$1 + local workdir=$2 + + echo "[INFO] Customizing preseed..." + + local tmp_initrd="/tmp/makeinitrd" + local install_dir="${iso_build_path}/install.amd" + local preseeds_dir="${workdir}/iso/preseeds" + + rm -rf "${tmp_initrd}" + mkdir -p "${tmp_initrd}" + + local preseed_name="preseed.cfg" + [[ $UNATTENDED == *"true"* ]] && preseed_name="preseed_unattended.cfg" + + local preseed_file="${preseeds_dir}/${preseed_name}" + + if [ ! -f "${preseed_file}" ]; then + echo "[ERROR] Preseed file not found: ${preseed_file}" + exit 1 + fi + + # Extract the initrd into a temporary directory + gunzip -c "${install_dir}/initrd.gz" | cpio -idum -D "${tmp_initrd}" || { + echo "[ERROR] Could not decompress and extract initrd" + exit 1 + } + + # Add the preseed file to the initrd + cp "${preseed_file}" "${tmp_initrd}/preseed.cfg" || { + echo "[ERROR] Could not copy preseed file" + exit 1 + } + + # Recreate (and recompress) the initrd + (cd "${tmp_initrd}" && find . -print0 | cpio -0 -ov -H newc | gzip >"${install_dir}/initrd.gz") || { + echo "[ERROR] Could not create new initrd" + exit 1 + } + + echo "[INFO] Preseed customization complete." +} + +configure_boot_menu() { + local iso_build_path=$1 + local workdir=$2 + + local boot_dir="${workdir}/iso/boot" + + echo "[INFO] Configuring the boot menu for Dappnode..." + cp ${boot_dir}/grub.cfg ${iso_build_path}/boot/grub/grub.cfg + cp ${boot_dir}/theme_1 ${iso_build_path}/boot/grub/theme/1 + cp ${boot_dir}/isolinux.cfg ${iso_build_path}/isolinux/isolinux.cfg + cp ${boot_dir}/menu.cfg ${iso_build_path}/isolinux/menu.cfg + cp ${boot_dir}/txt.cfg ${iso_build_path}/isolinux/txt.cfg + cp ${boot_dir}/splash.png ${iso_build_path}/isolinux/splash.png +} + +generate_debian_iso() { + local mbr_path=$1 + local iso_output_path=$2 + local iso_build_path=$3 + + echo "[INFO] Generating new ISO..." + + xorriso -as mkisofs -isohybrid-mbr ${mbr_path} \ + -c /isolinux/boot.cat -b /isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 \ + -boot-info-table -eltorito-alt-boot -e /boot/grub/efi.img -no-emul-boot \ + -isohybrid-gpt-basdat -o "${iso_output_path}" ${iso_build_path} } -echo "Clean old files..." -rm -rf dappnode-isoº -rm -rf DappNode-debian-* - -echo "Extracting the iso..." -xorriso -osirrox on -indev /images/${ISO_NAME} \ - -extract / dappnode-iso - -echo "Obtaining the isohdpfx.bin for hybrid ISO..." -dd if=/images/${ISO_NAME} bs=432 count=1 \ - of=dappnode-iso/isolinux/isohdpfx.bin - -cd /usr/src/app/dappnode-iso # /usr/src/app/dappnode-iso - -echo "Downloading third-party packages..." -sed '1,/^\#\!ISOBUILD/!d' /usr/src/app/scripts/dappnode_install_pre.sh >/tmp/vars.sh -# shellcheck disable=SC1091 -source /tmp/vars.sh - -echo "Creating necessary directories and copying files..." -mkdir -p /usr/src/app/dappnode-iso/dappnode -cp -r /usr/src/app/scripts /usr/src/app/dappnode-iso/dappnode -cp -r /usr/src/app/dappnode/* /usr/src/app/dappnode-iso/dappnode - -echo "Customizing preseed..." -mkdir -p /tmp/makeinitrd -cd install.amd -cp initrd.gz /tmp/makeinitrd/ -if [[ $UNATTENDED == *"true"* ]]; then - cp /usr/src/app/iso/preseeds/preseed_unattended.cfg /tmp/makeinitrd/preseed.cfg -else - cp /usr/src/app/iso/preseeds/preseed.cfg /tmp/makeinitrd/preseed.cfg -fi -cd /tmp/makeinitrd -gunzip initrd.gz -cpio -id -H newc /tmp/list -echo "preseed.cfg" >>/tmp/list -rm initrd -cpio -o -H newc initrd -gzip initrd -cd - -mv /tmp/makeinitrd/initrd.gz ./initrd.gz -cd .. - -echo "Configuring the boot menu for DappNode..." -cp /usr/src/app/iso/boot/grub.cfg boot/grub/grub.cfg -cp /usr/src/app/iso/boot/theme_1 boot/grub/theme/1 -cp /usr/src/app/iso/boot/isolinux.cfg isolinux/isolinux.cfg -cp /usr/src/app/iso/boot/menu.cfg isolinux/menu.cfg -cp /usr/src/app/iso/boot/txt.cfg isolinux/txt.cfg -cp /usr/src/app/iso/boot/splash.png isolinux/splash.png - -echo "Fix md5 sum..." -# shellcheck disable=SC2046 -md5sum $(find ! -name "md5sum.txt" ! -path "./isolinux/*" -type f) >md5sum.txt - -echo "Generating new iso..." -xorriso -as mkisofs -isohybrid-mbr isolinux/isohdpfx.bin \ - -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 \ - -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \ - -isohybrid-gpt-basdat -o /images/DAppNode-debian-bookworm-amd64.iso . +download_iso "${BASE_ISO_PATH}" "${BASE_ISO_NAME}" "${BASE_ISO_URL}" +verify_download "${BASE_ISO_PATH}" "${BASE_ISO_SHASUM}" +clean_old_files "${ISO_BUILD_PATH}" "${DAPPNODE_ISO_PREFIX}" +extract_iso "${BASE_ISO_PATH}" "${ISO_BUILD_PATH}" +prepare_boot_process "${BASE_ISO_PATH}" "${ISO_BUILD_PATH}/isolinux/isohdpfx.bin" +add_dappnode_files_to_iso_build "${ISO_BUILD_PATH}" "${WORKDIR}" +customize_debian_preseed "${ISO_BUILD_PATH}" "${WORKDIR}" +configure_boot_menu "${ISO_BUILD_PATH}" "${WORKDIR}" +handle_checksums # TODO: Check if it fits both ubuntu and debian +generate_debian_iso "${ISO_BUILD_PATH}/isolinux/isohdpfx.bin" "${DAPPNODE_ISO_PATH}" "${ISO_BUILD_PATH}" diff --git a/iso/scripts/generate_dappnode_iso_ubuntu.sh b/iso/scripts/generate_dappnode_iso_ubuntu.sh new file mode 100755 index 00000000..efd0f3fa --- /dev/null +++ b/iso/scripts/generate_dappnode_iso_ubuntu.sh @@ -0,0 +1,77 @@ +#!/bin/bash +set -e + +SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}") + +source ${SCRIPTS_DIR}/common_iso_generation.sh + +BASE_ISO_NAME=ubuntu-24.04.3-live-server-amd64.iso +BASE_ISO_VERSION="${BASE_ISO_NAME#ubuntu-}" +BASE_ISO_VERSION="${BASE_ISO_VERSION%-live-server-amd64.iso}" +BASE_ISO_SERIES=$(echo "$BASE_ISO_VERSION" | cut -d. -f1,2) +BASE_ISO_PATH="/images/${BASE_ISO_NAME}" +BASE_ISO_URL="https://releases.ubuntu.com/${BASE_ISO_SERIES}/${BASE_ISO_NAME}" +BASE_ISO_SHASUM="c3514bf0056180d09376462a7a1b4f213c1d6e8ea67fae5c25099c6fd3d8274b ${BASE_ISO_PATH}" + +DAPPNODE_ISO_NAME="${DAPPNODE_ISO_PREFIX}${BASE_ISO_NAME}" +DAPPNODE_ISO_PATH="/images/${DAPPNODE_ISO_NAME}" + +get_efi_partition() { + local base_iso_path=$1 + local dest_efi_path=$2 + local block_size=512 + + local efi_start=$(fdisk -l ${base_iso_path} | grep 'Appended2' | awk '{print $2}') + local efi_end=$(fdisk -l ${base_iso_path} | grep 'Appended2' | awk '{print $3}') + local efi_size=$(expr ${efi_end} - ${efi_start} + 1) + + echo "[INFO] Obtaining the EFI partition image from ${efi_start} with size ${efi_size}..." + dd if=${base_iso_path} bs=${block_size} skip="$efi_start" count="$efi_size" of=${dest_efi_path} +} + +add_ubuntu_autoinstall() { + local preseeds_dir=$1 + local iso_build_path=$2 + + echo "[INFO] Adding preseed..." + if [[ $UNATTENDED == *"true"* ]]; then + cp ${preseeds_dir}/autoinstall_unattended.yaml ${iso_build_path}/autoinstall.yaml + else + cp ${preseeds_dir}/autoinstall.yaml ${iso_build_path}/autoinstall.yaml + fi +} + +configure_boot_menu() { + echo "[INFO] Configuring the boot menu for Dappnode..." + cp -r /usr/src/app/iso/boot/ubuntu/* ${ISO_BUILD_PATH}/boot/grub/ +} + +generate_ubuntu_iso() { + local mbr_path=$1 + local efi_path=$2 + local iso_output_path=$3 + local iso_build_path=$4 + + echo "[INFO] Creating the new Ubuntu ISO..." + mkisofs \ + -rational-rock -joliet -joliet-long -full-iso9660-filenames \ + -iso-level 3 -partition_offset 16 --grub2-mbr ${mbr_path} \ + --mbr-force-bootable -append_partition 2 0xEF ${efi_path} \ + -appended_part_as_gpt \ + -eltorito-catalog /boot.catalog \ + -eltorito-boot /boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-load-size 4 \ + -boot-info-table --grub2-boot-info -eltorito-alt-boot --efi-boot '--interval:appended_partition_2:all::' -no-emul-boot \ + -o ${iso_output_path} ${iso_build_path} +} + +download_iso "${BASE_ISO_PATH}" "${BASE_ISO_NAME}" "${BASE_ISO_URL}" +verify_download "${BASE_ISO_PATH}" "${BASE_ISO_SHASUM}" +clean_old_files "${ISO_BUILD_PATH}" "${DAPPNODE_ISO_PREFIX}" +extract_iso "${BASE_ISO_PATH}" "${ISO_BUILD_PATH}" +prepare_boot_process "${BASE_ISO_PATH}" "${ISO_BUILD_PATH}/mbr" +get_efi_partition "${BASE_ISO_PATH}" "${ISO_BUILD_PATH}/efi" +add_dappnode_files_to_iso_build "${ISO_BUILD_PATH}" "${WORKDIR}" +add_ubuntu_autoinstall "/usr/src/app/iso/preseeds/ubuntu" "${ISO_BUILD_PATH}" +configure_boot_menu +handle_checksums +generate_ubuntu_iso "${ISO_BUILD_PATH}/mbr" "${ISO_BUILD_PATH}/efi" "${DAPPNODE_ISO_PATH}" "${ISO_BUILD_PATH}" diff --git a/scripts/dappnode_install.sh b/scripts/dappnode_install.sh index 331a252f..49ecf3f2 100755 --- a/scripts/dappnode_install.sh +++ b/scripts/dappnode_install.sh @@ -1,160 +1,873 @@ #!/bin/bash +# This installer is written for bash. It's safe to *run it from zsh* (it will execute via bash +# thanks to the shebang), but users sometimes invoke it as `zsh ./script.sh` or `source ./script.sh`. +# - If sourced, bail out (sourcing would pollute the current shell and can break it). +# - If invoked by a non-bash shell, re-exec with bash before hitting bash-specific builtins. + +############################## +# Logging / Errors # +############################## +# Note: LOGFILE and LOGS_DIR are set during bootstrap_filesystem based on DAPPNODE_DIR +# Early definition allows these functions to be used throughout the script. + +log() { + # LOGFILE is created after dir bootstrap; until then we just print to stdout. + if [[ -n "${LOGFILE:-}" && -d "${LOGS_DIR:-}" ]]; then + printf '%s\n' "[INFO] $*" | tee -a "$LOGFILE" + else + printf '%s\n' "[INFO] $*" + fi +} + +warn() { + # LOGFILE is created after dir bootstrap; until then we just print to stdout. + if [[ -n "${LOGFILE:-}" && -d "${LOGS_DIR:-}" ]]; then + printf '%s\n' "[WARN] $*" | tee -a "$LOGFILE" + else + printf '%s\n' "[WARN] $*" + fi +} + +error() { + # LOGFILE is created after dir bootstrap; until then we just print to stdout. + if [[ -n "${LOGFILE:-}" && -d "${LOGS_DIR:-}" ]]; then + printf '%s\n' "[ERROR] $*" | tee -a "$LOGFILE" + else + printf '%s\n' "[ERROR] $*" + fi +} + +die() { + # LOGFILE is created after dir bootstrap; until then we just print to stdout. + if [[ -n "${LOGFILE:-}" && -d "${LOGS_DIR:-}" ]]; then + printf '%s\n' "[ERROR] $*" | tee -a "$LOGFILE" + else + printf '%s\n' "[ERROR] $*" + fi + exit 1 +} + +############################## +# Script Guards # +############################## + +if (return 0 2>/dev/null); then + die "This script must be executed, not sourced. Run: bash $0" +fi + +if [ -z "${BASH_VERSION:-}" ]; then + exec /usr/bin/env bash "$0" "$@" +fi + +set -Eeuo pipefail + +# Optional env inputs (avoid unbound-variable errors under `set -u`) +: "${UPDATE:=false}" +: "${STATIC_IP:=}" +: "${LOCAL_PROFILE_PATH:=}" +: "${MINIMAL:=false}" +: "${LITE:=false}" +: "${PACKAGES:=}" + +# Enable alias expansion in non-interactive bash scripts. +# Required so commands like `dappnode_wireguard` (defined as aliases in `.dappnode_profile`) work. +shopt -s expand_aliases + +# Ensure array is always defined (avoid `set -u` edge cases) +DNCORE_COMPOSE_ARGS=() + +usage() { + cat <<'EOF' +Usage: dappnode_install.sh [options] + +Options: + --update Clean existing downloaded artifacts before installing (equivalent: UPDATE=true) + --static-ip Set a static IP (equivalent: STATIC_IP=...) + --local-profile-path Use a local .dappnode_profile instead of downloading (equivalent: LOCAL_PROFILE_PATH=...) + --ipfs-endpoint Override IPFS gateway endpoint (equivalent: IPFS_ENDPOINT=...) + --profile-url Override profile download URL (equivalent: PROFILE_URL=...) + --minimal Install only BIND DAPPMANAGER NOTIFICATIONS PREMIUM (equivalent: MINIMAL=true) + --lite Install reduced package set: BIND VPN WIREGUARD DAPPMANAGER NOTIFICATIONS PREMIUM (equivalent: LITE=true) + --packages Override package selection (comma or space separated), e.g. BIND,IPFS,VPN + -h, --help Show this help + +Environment variables (also supported): + UPDATE, STATIC_IP, LOCAL_PROFILE_PATH, IPFS_ENDPOINT, PROFILE_URL, MINIMAL, LITE, PACKAGES +EOF +} + +parse_args() { + while [[ $# -gt 0 ]]; do + case "$1" in + --update) + UPDATE=true + shift + ;; + --static-ip) + [[ $# -ge 2 ]] || die "--static-ip requires an IPv4 argument" + STATIC_IP="$2" + shift 2 + ;; + --local-profile-path) + [[ $# -ge 2 ]] || die "--local-profile-path requires a path argument" + LOCAL_PROFILE_PATH="$2" + shift 2 + ;; + --ipfs-endpoint) + [[ $# -ge 2 ]] || die "--ipfs-endpoint requires a URL argument" + IPFS_ENDPOINT="$2" + shift 2 + ;; + --profile-url) + [[ $# -ge 2 ]] || die "--profile-url requires a URL argument" + PROFILE_URL="$2" + shift 2 + ;; + --minimal) + MINIMAL=true + shift + ;; + --lite) + LITE=true + shift + ;; + --packages) + [[ $# -ge 2 ]] || die "--packages requires a package list argument" + PACKAGES="$2" + shift 2 + ;; + --packages=*) + PACKAGES="${1#*=}" + shift + ;; + -h|--help) + usage + exit 0 + ;; + --) + shift + break + ;; + *) + die "Unknown option: $1 (use --help)" + ;; + esac + done +} + +validate_install_mode() { + if [[ "${MINIMAL}" == "true" && "${LITE}" == "true" ]]; then + die "--minimal and --lite are mutually exclusive" + fi +} + +require_cmd() { + local cmd="$1" + command -v "$cmd" >/dev/null 2>&1 || die "Missing required command: $cmd" +} + +require_downloader() { + if command -v curl >/dev/null 2>&1; then + return 0 + fi + if command -v wget >/dev/null 2>&1; then + return 0 + fi + die "Missing required downloader: install curl or wget" +} + +check_prereqs() { + if ! command -v docker >/dev/null 2>&1; then + die "Docker is not installed. Install Docker first, then re-run this installer." + fi + + # Docker CLI may exist while the daemon is stopped/unreachable. + if ! docker info >/dev/null 2>&1; then + die "Docker is installed but not running (or not reachable). Start Docker and try again." + fi + + require_downloader + + # Ensure compose is available (Docker Desktop / modern docker engine) + if ! docker compose version >/dev/null 2>&1; then + die "Docker Compose not available (expected: 'docker compose'). Update Docker or install the compose plugin." + fi +} + +# Wait until dappmanager publishes INTERNAL_IP via its local HTTP endpoint. +# Runs the curl inside the provided container and exits with error on timeout. +# Usage: wait_for_internal_ip [timeout_seconds] [initial_sleep_seconds] [final_sleep_seconds] +wait_for_internal_ip() { + local container_name="$1" + local timeout_seconds="${2:-120}" + local initial_sleep_seconds="${3:-10}" + local final_sleep_seconds="${4:-2}" + local internal_ip_url="http://127.0.0.1/global-envs/INTERNAL_IP" + local hostname_url="http://127.0.0.1/global-envs/HOSTNAME" + + log "Waiting for dappmanager to publish INTERNAL_IP and HOSTNAME..." + sleep "$initial_sleep_seconds" + + local start_seconds internal_http_code internal_value internal_result + local hostname_http_code hostname_value hostname_result + start_seconds=$SECONDS + internal_http_code="" + internal_value="" + hostname_http_code="" + hostname_value="" + local retry_count=0 + + while true; do + if (( SECONDS - start_seconds >= timeout_seconds )); then + die "Timed out after ${timeout_seconds}s waiting for INTERNAL_IP and HOSTNAME from dappmanager (expected HTTP 200 with non-empty values). Last seen: INTERNAL_IP code=${internal_http_code:-?} value=${internal_value:-}; HOSTNAME code=${hostname_http_code:-?} value=${hostname_value:-}" + fi + + # Must be executed inside the dappmanager container. + # Return format is: + # \n + # Parse in bash (not inside container sh) to avoid shell portability issues. + + internal_result="$( + docker exec -i "$container_name" sh -lc "curl -sS -w '\n%{http_code}' '$internal_ip_url' 2>/dev/null || true" 2>/dev/null || true + )" + internal_http_code="$(printf '%s\n' "$internal_result" | tail -n 1 | tr -d '\r')" + internal_value="$(printf '%s\n' "$internal_result" | head -n 1 | tr -d '\r' | xargs)" + + hostname_result="$( + docker exec -i "$container_name" sh -lc "curl -sS -w '\n%{http_code}' '$hostname_url' 2>/dev/null || true" 2>/dev/null || true + )" + hostname_http_code="$(printf '%s\n' "$hostname_result" | tail -n 1 | tr -d '\r')" + hostname_value="$(printf '%s\n' "$hostname_result" | head -n 1 | tr -d '\r' | xargs)" + + if [[ "$internal_http_code" == "200" && -n "$internal_value" && "$internal_value" != "null" && "$hostname_http_code" == "200" && -n "$hostname_value" && "$hostname_value" != "null" ]]; then + sleep "$final_sleep_seconds" # Extra buffer to ensure values are fully propagated before we proceed + log "INTERNAL_IP is ready: $internal_value" + log "HOSTNAME is ready: $hostname_value" + return 0 + fi + + retry_count=$((retry_count + 1)) + if (( retry_count % 5 == 1 )); then + log "INTERNAL_IP/HOSTNAME not ready yet (INTERNAL_IP code=${internal_http_code:-?}, HOSTNAME code=${hostname_http_code:-?}). Retrying..." + fi + sleep 2 + done +} + +# Print VPN access credentials (Wireguard + OpenVPN) after core has started. +# Works on both Linux and macOS as long as the relevant containers are running. +print_vpn_access_credentials() { + local localhost_flag=() + local has_wireguard=false + local has_vpn=false + local pkg + + if $IS_MACOS; then + localhost_flag=(--localhost) + fi + + for pkg in "${PKGS[@]}"; do + if [[ "$pkg" == "WIREGUARD" ]]; then + has_wireguard=true + elif [[ "$pkg" == "VPN" ]]; then + has_vpn=true + fi + done + + if [[ "$has_wireguard" != "true" && "$has_vpn" != "true" ]]; then + log "No VPN package selected (VPN/WIREGUARD). Skipping credentials output." + return 0 + fi + + log "" + log "Waiting for VPN initialization..." + wait_for_internal_ip "DAppNodeCore-dappmanager.dnp.dappnode.eth" 120 20 10 + + log "" + log "##############################################" + log "# DAppNode VPN Access Credentials #" + log "##############################################" + log "" + log "Your DAppNode is ready! Connect using your preferred VPN client." + log "Choose either Wireguard (recommended) or OpenVPN and import the" + log "credentials below into your VPN app to access your DAppNode." + log "" + + if [[ "$has_wireguard" == "true" ]]; then + log "--- Wireguard ---" + docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials "${localhost_flag[@]}" 2>&1 || \ + warn "Wireguard credentials not yet available. Try later with: dappnode_wireguard${localhost_flag:+ ${localhost_flag[*]}}" + fi + + if [[ "$has_wireguard" == "true" && "$has_vpn" == "true" ]]; then + log "" + fi + + if [[ "$has_vpn" == "true" ]]; then + log "--- OpenVPN ---" + docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get dappnode_admin "${localhost_flag[@]}" 2>&1 || \ + warn "OpenVPN credentials not yet available. Try later with: dappnode_openvpn_get dappnode_admin${localhost_flag:+ ${localhost_flag[*]}}" + fi + + log "" + log "Import the configuration above into your VPN client of choice to access your DAppNode at http://my.dappnode" +} + +# Build docker compose "-f " args from downloaded compose files. +# This avoids depending on alias expansion or profile-generated strings. +build_dncore_compose_args() { + DNCORE_COMPOSE_ARGS=() + local file + while IFS= read -r file; do + [[ -n "$file" ]] || continue + DNCORE_COMPOSE_ARGS+=( -f "$file" ) + done < <(find "${DAPPNODE_CORE_DIR}" -name 'docker-compose-*.yml' -print 2>/dev/null | sort) +} + +################## +# OS DETECTION # +################## +OS_TYPE="$(uname -s)" +IS_MACOS=false +IS_LINUX=false +if [[ "$OS_TYPE" == "Darwin" ]]; then + IS_MACOS=true +elif [[ "$OS_TYPE" == "Linux" ]]; then + IS_LINUX=true +else + die "Unsupported operating system: $OS_TYPE" +fi + ############# # VARIABLES # ############# -# Dirs -DAPPNODE_DIR="/usr/src/dappnode" +# Dirs - macOS uses $HOME/dappnode, Linux uses /usr/src/dappnode +if $IS_MACOS; then + DAPPNODE_DIR="$HOME/dappnode" +else + DAPPNODE_DIR="/usr/src/dappnode" +fi DAPPNODE_CORE_DIR="${DAPPNODE_DIR}/DNCORE" LOGS_DIR="$DAPPNODE_DIR/logs" # Files CONTENT_HASH_FILE="${DAPPNODE_CORE_DIR}/packages-content-hash.csv" LOGFILE="${LOGS_DIR}/dappnode_install.log" -MOTD_FILE="/etc/motd" DAPPNODE_PROFILE="${DAPPNODE_CORE_DIR}/.dappnode_profile" +# Linux-only paths +if $IS_LINUX; then + MOTD_FILE="/etc/motd" + UPDATE_MOTD_DIR="/etc/update-motd.d" +fi # Get URLs -PROFILE_BRANCH=${PROFILE_BRANCH:-"master"} -IPFS_ENDPOINT=${IPFS_ENDPOINT:-"http://ipfs.io"} +IPFS_ENDPOINT=${IPFS_ENDPOINT:-"https://ipfs-gateway.dappnode.net"} # PROFILE_URL env is used to fetch the core packages versions that will be used to build the release in script install method PROFILE_URL=${PROFILE_URL:-"https://github.com/dappnode/DAppNode/releases/latest/download/dappnode_profile.sh"} DAPPNODE_ACCESS_CREDENTIALS="${DAPPNODE_DIR}/scripts/dappnode_access_credentials.sh" DAPPNODE_ACCESS_CREDENTIALS_URL="https://github.com/dappnode/DAppNode/releases/latest/download/dappnode_access_credentials.sh" -WGET="wget -q --show-progress --progress=bar:force" -SWGET="wget -q -O-" # Other -CONTENT_HASH_PKGS=(geth besu nethermind erigon prysm teku lighthouse nimbus lodestar) -ARCH=$(dpkg --print-architecture) -WELCOME_MESSAGE="\nChoose a way to connect to your DAppNode, then go to \e[1mhttp://my.dappnode\e[0m\n\n\e[1m- Wifi\e[0m\t\tScan and connect to DAppNodeWIFI. Get wifi credentials with \e[32mdappnode_wifi\e[0m\n\n\e[1m- Local Proxy\e[0m\tConnect to the same router as your DAppNode. Then go to \e[1mhttp://dappnode.local\e[0m\n\n\e[1m- Wireguard\e[0m\tDownload Wireguard app on your device. Get your dappnode wireguard credentials with \e[32mdappnode_wireguard\e[0m\n\n\e[1m- Open VPN\e[0m\tDownload OPen VPN app on your device. Get your openVPN creds with \e[32mdappnode_openvpn\e[0m\n\n\nTo see a full list of commands available execute \e[32mdappnode_help\e[0m\n" - -# Clean if update -if [ "$UPDATE" = true ]; then - echo "Cleaning for update..." - rm -rf $LOGFILE - rm -rf ${DAPPNODE_CORE_DIR}/docker-compose-*.yml - rm -rf ${DAPPNODE_CORE_DIR}/dappnode_package-*.json - rm -rf ${DAPPNODE_CORE_DIR}/*.tar.xz - rm -rf ${DAPPNODE_CORE_DIR}/*.txz - rm -rf ${DAPPNODE_CORE_DIR}/.dappnode_profile - rm -rf ${CONTENT_HASH_FILE} + +# Architecture detection (cross-platform) +if $IS_MACOS; then + ARCH="$(uname -m)" + [[ "$ARCH" == "x86_64" ]] && ARCH="amd64" + # arm64 is already correct for Apple Silicon +else + ARCH="$(dpkg --print-architecture)" fi -# Create necessary directories -mkdir -p $DAPPNODE_DIR -mkdir -p $DAPPNODE_CORE_DIR -mkdir -p "${DAPPNODE_DIR}/scripts" -mkdir -p "${DAPPNODE_CORE_DIR}/scripts" -mkdir -p "${DAPPNODE_DIR}/config" -mkdir -p $LOGS_DIR - -# TEMPORARY: think a way to integrate flags instead of use files to detect installation type -is_iso_install() { - # Check old and new location of iso_install.log - if [ -f "${DAPPNODE_DIR}/iso_install.log" ] || [ -f "${DAPPNODE_DIR}/logs/iso_install.log" ]; then - IS_ISO_INSTALL=true +############################## +# Cross-platform Helpers # +############################## + +# Download a file: download_file +download_file() { + local dest="$1" + local url="$2" + log "Downloading from $url to $dest" + mkdir -p "$(dirname "$dest")" + if command -v curl >/dev/null 2>&1; then + curl -fsSL -o "$dest" "$url" + return + fi + wget -q --show-progress --progress=bar:force -O "$dest" "$url" +} + +# Download content to stdout: download_stdout +download_stdout() { + local url="$1" + if command -v curl >/dev/null 2>&1; then + curl -fsSL "$url" + return + fi + wget -q -O- "$url" +} + +# Normalize IPFS refs and (if needed) infer the missing : from dappnode_package.json +# Accepts: +# - /ipfs/: +# - /ipfs/ (version inferred) +# - ipfs/[:] (leading slash normalized) +normalize_ipfs_version_ref() { + local raw_ref="$1" + local comp="$2" + local ref="$raw_ref" + + if [[ "$ref" == ipfs/* ]]; then + ref="/$ref" + fi + + # If it already has :, we're done + if [[ "$ref" == /ipfs/*:* ]]; then + echo "$ref" + return 0 + fi + + # If it's an IPFS ref without a :, infer it from the manifest in the CID + if [[ "$ref" == /ipfs/* ]]; then + local cid_path="$ref" + local manifest_url="${IPFS_ENDPOINT%/}${cid_path}/dappnode_package.json" + local manifest + manifest="$(download_stdout "$manifest_url" 2>/dev/null || true)" + if [[ -z "$manifest" ]]; then + error "Could not fetch IPFS manifest for ${comp} from: $manifest_url" + error "Provide ${comp}_VERSION as /ipfs/: (example: /ipfs/Qm...:0.2.11)" + return 1 + fi + + local inferred_version + inferred_version="$( + echo "$manifest" | + tr -d '\r' | + grep -m1 '"version"' | + sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^\"]+)".*/\1/' + )" + + if [[ -z "$inferred_version" || "$inferred_version" == "$manifest" ]]; then + error "Could not infer version for ${comp} from IPFS manifest: $manifest_url" + error "Provide ${comp}_VERSION as /ipfs/:" + return 1 + fi + + echo "${cid_path}:${inferred_version}" + return 0 + fi + + # Not an IPFS ref; return as-is + echo "$raw_ref" +} + +# Cross-platform in-place sed (macOS requires '' after -i) +sed_inplace() { + if $IS_MACOS; then + sed -i '' "$@" else - IS_ISO_INSTALL=false + sed -i "$@" fi } -# Check is port 80 in used (necessary for HTTPS) -is_port_used() { - lsof -i -P -n | grep ":80 (LISTEN)" &>/dev/null && IS_PORT_USED=true || IS_PORT_USED=false +############################## +# Compose Patching Helpers # +############################## + +# Remove journald logging from compose files (not supported on macOS Docker Desktop) +remove_logging_section() { + local file="$1" + sed_inplace '/logging/d;/journald/d' "$file" +} + +# Replace Linux paths with macOS paths in compose files +patch_compose_paths() { + local file="$1" + sed_inplace "s|/usr/src/dappnode|${DAPPNODE_DIR}|g" "$file" +} + +# Patch dappmanager compose for macOS: inject env vars the container needs +# to know the host core-dir path and to skip host-only operations, +# and fix the DNCORE volume mount to use the macOS host path. +patch_dappmanager_compose_for_macos() { + local file="$1" + + # Replace the host side of the DNCORE volume mount with the actual DAPPNODE_CORE_DIR value + # e.g. /usr/src/dappnode/DNCORE/:/usr/src/app/DNCORE/ -> $HOME/dappnode/DNCORE/:/usr/src/app/DNCORE/ + sed_inplace "s|[^[:space:]]*:/usr/src/app/DNCORE/|${DAPPNODE_CORE_DIR}/:/usr/src/app/DNCORE/|" "$file" + + local envs_to_add=() + + # DAPPNODE_CORE_DIR: lets the container know the host's DNCORE path + if ! grep -q "DAPPNODE_CORE_DIR" "$file"; then + envs_to_add+=(" - DAPPNODE_CORE_DIR=${DAPPNODE_CORE_DIR}") + fi + + # DISABLE_HOST_SCRIPTS: tells the container to skip host-only scripts + if ! grep -q "DISABLE_HOST_SCRIPTS" "$file"; then + envs_to_add+=(" - DISABLE_HOST_SCRIPTS=${DISABLE_HOST_SCRIPTS}") + fi + + [[ ${#envs_to_add[@]} -gt 0 ]] || return 0 + + local tmp="${file}.tmp" + local insert_file="${file}.envinsert" + + # macOS ships BSD awk, which can error with "newline in string" if a -v argument contains + # literal newlines. Write the insertion block to a temp file and have awk read it. + printf '%s\n' "${envs_to_add[@]}" >"$insert_file" + + awk -v insfile="$insert_file" ' + /^[[:space:]]*environment:[[:space:]]*$/ { + print + while ((getline line < insfile) > 0) print line + close(insfile) + next + } + { print } + ' "$file" >"$tmp" && mv "$tmp" "$file" + + rm -f "$insert_file" || true +} + +bootstrap_filesystem() { + # Clean if update — only the logfile and profile are removed here. + # Removing the profile early forces ensure_profile_loaded to re-download + # the latest one (so resolved package versions match the new release). + # Composes/manifests/archives are removed later by clean_for_update, + # AFTER preflight passes — see comment in main(). + if [[ "${UPDATE}" == "true" ]]; then + rm -f "${LOGFILE}" || true + rm -f "${DAPPNODE_CORE_DIR}/.dappnode_profile" || true + fi + + # Create necessary directories + mkdir -p "${DAPPNODE_DIR}" + mkdir -p "${DAPPNODE_CORE_DIR}" + mkdir -p "${DAPPNODE_DIR}/scripts" + mkdir -p "${DAPPNODE_CORE_DIR}/scripts" + mkdir -p "${DAPPNODE_DIR}/config" + mkdir -p "${LOGS_DIR}" + + # Ensure the log file path exists before first use by helpers. + touch "${LOGFILE}" || true +} + +# Destructive: remove on-disk artifacts from the previous install so fresh +# downloads take their place. Must only run AFTER preflight checks have passed — +# otherwise a failing preflight (e.g. port conflict) leaves the host with no +# compose files on disk while running containers continue to hold the ports. +clean_for_update() { + if [[ "${UPDATE}" != "true" ]]; then + return 0 + fi + log "Cleaning for update..." + rm -f "${DAPPNODE_CORE_DIR}"/docker-compose-*.yml || true + rm -f "${DAPPNODE_CORE_DIR}"/dappnode_package-*.json || true + rm -f "${DAPPNODE_CORE_DIR}"/*.tar.xz || true + rm -f "${DAPPNODE_CORE_DIR}"/*.txz || true + rm -f "${CONTENT_HASH_FILE}" || true +} + +# Generic helper: returns 0 if a process is bound to the given port, 1 if not. +# Usage: is_port_listening [tcp|udp] +# tcp (default): matches TCP sockets in LISTEN state +# udp: matches any process bound to the UDP port +is_port_listening() { + local port="$1" + local proto="${2:-tcp}" + if [[ "$proto" == "udp" ]]; then + lsof -i "udp:${port}" -P -n 2>/dev/null | grep -q . + else + lsof -i "tcp:${port}" -P -n 2>/dev/null | grep -q "(LISTEN)" + fi +} + +# Check if ports 80/443 are occupied by something other than our own HTTPS container. +# Sets HTTPS_PORTS_BLOCKED=true/false. +check_https_ports_conflict() { + if ! command -v lsof >/dev/null 2>&1; then + warn "lsof not found; assuming ports 80/443 are in use (HTTPS will be skipped)" + HTTPS_PORTS_BLOCKED=true + return + fi + + if ! is_port_listening 80 && ! is_port_listening 443; then + HTTPS_PORTS_BLOCKED=false + return + fi + + # Port 80 or 443 is in use; check if it's our own HTTPS container + if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^DAppNodeCore-https.dnp.dappnode.eth$"; then + # Our own HTTPS container already holds the port — not a conflict + HTTPS_PORTS_BLOCKED=false + else + # Port 80 or 443 is used by something else + HTTPS_PORTS_BLOCKED=true + fi +} + +# Check that ports required by VPN/Wireguard are not already in use by another process. +# Must be called after PKGS is populated. Exits with a helpful error on conflict. +# Ports held by our own dappnode core VPN/Wireguard containers are not conflicts — +# the upcoming compose-up will replace them. +check_vpn_ports_conflict() { + if ! command -v lsof >/dev/null 2>&1; then + return # cannot check; proceed and let the container report a bind error + fi + + local pkg + for pkg in "${PKGS[@]}"; do + case "$pkg" in + WIREGUARD) + if is_port_listening 51820 udp; then + # Port 51820 is in use; check if it's our own Wireguard container + if docker ps --format '{{.Names}}' 2>/dev/null | grep -qE "^DAppNodeCore-.*wireguard.*\.dnp\.dappnode\.eth$"; then + log "Port 51820/UDP is held by the existing DAppNode Wireguard container; it will be replaced." + else + error "Port 51820/UDP is already in use on this host." + error "This port is required by the Wireguard package and must be free before installing." + error "Free up port 51820 and re-run the installer, or — if you do not need VPN" + error "connectivity — consider using --minimal instead (advanced users only)." + exit 1 + fi + fi + ;; + VPN) + local vpn_blocked=() + is_port_listening 1194 udp && vpn_blocked+=(1194/UDP) + is_port_listening 8092 tcp && vpn_blocked+=(8092/TCP) + if [[ ${#vpn_blocked[@]} -gt 0 ]]; then + # Port(s) in use; check if held by our own OpenVPN container + if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^DAppNodeCore-vpn.dnp.dappnode.eth$"; then + log "Port(s) ${vpn_blocked[*]} are held by the existing DAppNode VPN container; it will be replaced." + else + error "Port(s) ${vpn_blocked[*]} are already in use on this host." + error "These ports are required by the OpenVPN package and must be free before installing." + error "Free up the port(s) and re-run the installer, or — if you do not need VPN" + error "connectivity — consider using --minimal instead (advanced users only)." + exit 1 + fi + fi + ;; + esac + done } # Determine packages to be installed determine_packages() { - is_iso_install - is_port_used - if [ "$IS_ISO_INSTALL" == "false" ]; then - if [ "$IS_PORT_USED" == "true" ]; then - PKGS=(BIND IPFS VPN WIREGUARD DAPPMANAGER WIFI) - else - PKGS=(HTTPS BIND IPFS WIREGUARD DAPPMANAGER WIFI) + # Explicit package list override from flag/env always has top priority. + # It supersedes MINIMAL/LITE and any OS/port-based package determination. + if [[ -n "${PACKAGES//[[:space:],]/}" ]]; then + local raw token normalized + local custom_pkgs=() + + raw="${PACKAGES//,/ }" + for token in $raw; do + normalized="$(echo "$token" | tr '[:lower:]' '[:upper:]')" + case "$normalized" in + HTTPS|BIND|IPFS|VPN|WIREGUARD|DAPPMANAGER|WIFI|NOTIFICATIONS|PREMIUM) + ;; + *) + die "Unknown package in --packages/PACKAGES: '$token'. Allowed: HTTPS,BIND,IPFS,VPN,WIREGUARD,DAPPMANAGER,WIFI,NOTIFICATIONS,PREMIUM" + ;; + esac + + local exists=false + local pkg + for pkg in "${custom_pkgs[@]}"; do + if [[ "$pkg" == "$normalized" ]]; then + exists=true + break + fi + done + + if [[ "$exists" == "false" ]]; then + custom_pkgs+=("$normalized") + fi + done + + [[ ${#custom_pkgs[@]} -gt 0 ]] || die "--packages/PACKAGES was provided but no valid packages were found" + + # DAPPMANAGER is required for a functional install; ensure it's present on explicit overrides. + local has_dappmanager=false + local pkg + for pkg in "${custom_pkgs[@]}"; do + if [[ "$pkg" == "DAPPMANAGER" ]]; then + has_dappmanager=true + break + fi + done + if [[ "$has_dappmanager" == "false" ]]; then + custom_pkgs+=("DAPPMANAGER") + log "--packages/PACKAGES did not include DAPPMANAGER; appending it automatically" fi - else - if [ "$IS_PORT_USED" == "true" ]; then - PKGS=(BIND IPFS WIREGUARD DAPPMANAGER WIFI) - else - PKGS=(HTTPS BIND IPFS WIREGUARD DAPPMANAGER WIFI) + + if [[ "${MINIMAL}" == "true" || "${LITE}" == "true" ]]; then + log "Custom packages provided; overriding --minimal/--lite and MINIMAL/LITE" fi + MINIMAL=false + LITE=false + PKGS=("${custom_pkgs[@]}") + + log "Packages override enabled via --packages/PACKAGES" + log "Packages to be installed: ${PKGS[*]}" + log "PKGS: ${PKGS[*]}" + for comp in "${PKGS[@]}"; do + local ver_var + ver_var="${comp}_VERSION" + log "$ver_var = ${!ver_var-}" + done + return 0 + fi + + # Global override: new minimal install, regardless of OS. + if [[ "${MINIMAL}" == "true" ]]; then + PKGS=(BIND DAPPMANAGER NOTIFICATIONS PREMIUM) + log "Minimal mode enabled; overriding packages" + log "Packages to be installed: ${PKGS[*]}" + log "PKGS: ${PKGS[*]}" + for comp in "${PKGS[@]}"; do + local ver_var + ver_var="${comp}_VERSION" + log "$ver_var = ${!ver_var-}" + done + return 0 fi - echo -e "\e[32mPackages to be installed: ${PKGS[*]}\e[0m" 2>&1 | tee -a $LOGFILE -} -function valid_ip() { - local ip=$1 - local stat=1 + # Global override: lite install (former minimal behavior), regardless of OS. + if [[ "${LITE}" == "true" ]]; then + PKGS=(BIND VPN WIREGUARD DAPPMANAGER NOTIFICATIONS PREMIUM) + log "Lite mode enabled; overriding packages" + log "Packages to be installed: ${PKGS[*]}" + log "PKGS: ${PKGS[*]}" + for comp in "${PKGS[@]}"; do + local ver_var + ver_var="${comp}_VERSION" + log "$ver_var = ${!ver_var-}" + done + return 0 + fi + + # Default mode (no --packages/--minimal/--lite): install full package set. + # HTTPS is included only when ports 80/443 are available. + check_https_ports_conflict + if [ "$HTTPS_PORTS_BLOCKED" == "true" ]; then + PKGS=(BIND IPFS VPN WIREGUARD DAPPMANAGER WIFI NOTIFICATIONS PREMIUM) + else + PKGS=(HTTPS BIND IPFS VPN WIREGUARD DAPPMANAGER WIFI NOTIFICATIONS PREMIUM) + fi + + log "Packages to be installed: ${PKGS[*]}" + + # Debug: print all PKGS and their version variables + log "PKGS: ${PKGS[*]}" + for comp in "${PKGS[@]}"; do + local ver_var + ver_var="${comp}_VERSION" + log "$ver_var = ${!ver_var-}" + done +} - if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - OIFS=$IFS - IFS='.' - ip=("$ip") - IFS=$OIFS - [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && - ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] - stat=$? +valid_ip() { + local ip="$1" + if [[ ! "$ip" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then + return 1 fi - return $stat + + local IFS='.' + # shellcheck disable=SC2206 + local octets=( $ip ) + [[ ${#octets[@]} -eq 4 ]] || return 1 + [[ ${octets[0]} -le 255 && ${octets[1]} -le 255 && ${octets[2]} -le 255 && ${octets[3]} -le 255 ]] } -if [[ -n "$STATIC_IP" ]]; then +configure_static_ip() { + if [[ -z "${STATIC_IP}" ]]; then + return 0 + fi + if valid_ip "$STATIC_IP"; then - echo "$STATIC_IP" >${DAPPNODE_DIR}/config/static_ip + echo "$STATIC_IP" >"${DAPPNODE_DIR}/config/static_ip" else - echo "The static IP provided: ${STATIC_IP} is not valid." - exit 1 + die "The static IP provided (${STATIC_IP}) is not valid." fi -fi +} + +ensure_profile_loaded() { + # If LOCAL_PROFILE_PATH is set, use it as the profile source instead of downloading + if [[ -n "${LOCAL_PROFILE_PATH}" ]]; then + log "Using local profile: ${LOCAL_PROFILE_PATH}" + cp "$LOCAL_PROFILE_PATH" "$DAPPNODE_PROFILE" + elif [[ ! -f "$DAPPNODE_PROFILE" ]]; then + download_file "${DAPPNODE_PROFILE}" "${PROFILE_URL}" + fi + + # shellcheck disable=SC1090 + source "${DAPPNODE_PROFILE}" +} -# Loads profile, if not exists it means it is script install so the versions will be fetched from the latest profile -[ -f $DAPPNODE_PROFILE ] || ${WGET} -O ${DAPPNODE_PROFILE} ${PROFILE_URL} -# shellcheck disable=SC1090 -source "${DAPPNODE_PROFILE}" - -# The indirect variable expansion used in ${!ver##*:} allows us to use versions like 'dev:development' -# If such variable with 'dev:'' suffix is used, then the component is built from specified branch or commit. -# you can also specify an IPFS version like /ipfs/QmWg8P2b9JKQ8thAVz49J8SbJbCoi2MwkHnUqMtpzDTtxR:0.2.7, it's important -# to include the exact version also in the IPFS hash format since it's needed to be able to download it -determine_packages -for comp in "${PKGS[@]}"; do - ver="${comp}_VERSION" - DOWNLOAD_URL="https://github.com/dappnode/DNP_${comp}/releases/download/v${!ver}" - if [[ ${!ver} == /ipfs/* ]]; then - DOWNLOAD_URL="${IPFS_ENDPOINT}/api/v0/cat?arg=${!ver%:*}" - fi - eval "${comp}_URL=\"${DOWNLOAD_URL}/${comp,,}.dnp.dappnode.eth_${!ver##*:}_linux-${ARCH}.txz\"" - eval "${comp}_YML=\"${DOWNLOAD_URL}/docker-compose.yml\"" - eval "${comp}_MANIFEST=\"${DOWNLOAD_URL}/dappnode_package.json\"" - eval "${comp}_YML_FILE=\"${DAPPNODE_CORE_DIR}/docker-compose-${comp,,}.yml\"" - eval "${comp}_FILE=\"${DAPPNODE_CORE_DIR}/${comp,,}.dnp.dappnode.eth_${!ver##*:}_linux-${ARCH}.txz\"" - eval "${comp}_MANIFEST_FILE=\"${DAPPNODE_CORE_DIR}/dappnode_package-${comp,,}.json\"" -done +resolve_packages() { + # The indirect variable expansion used in ${!ver##*:} allows us to use versions like 'dev:development' + # If such variable with 'dev:'' suffix is used, then the component is built from specified branch or commit. + # you can also specify an IPFS version like /ipfs/: (the exact version is required). + determine_packages + check_vpn_ports_conflict + for comp in "${PKGS[@]}"; do + ver="${comp}_VERSION" + log "Processing $comp: ${!ver-}" + + raw_version_ref="${!ver-}" + if [[ "$raw_version_ref" == /ipfs/* || "$raw_version_ref" == ipfs/* ]]; then + resolved_ref="$(normalize_ipfs_version_ref "$raw_version_ref" "$comp")" || exit 1 + printf -v "${comp}_VERSION" '%s' "$resolved_ref" + raw_version_ref="$resolved_ref" + log "Using IPFS for ${comp}: ${raw_version_ref%:*} (version ${raw_version_ref##*:})" + DOWNLOAD_URL="${IPFS_ENDPOINT%/}${raw_version_ref%:*}" + version_for_filenames="${raw_version_ref##*:}" + else + version_for_filenames="${raw_version_ref##*:}" + DOWNLOAD_URL="https://github.com/dappnode/DNP_${comp}/releases/download/v${version_for_filenames}" + fi + comp_lower="$(echo "$comp" | tr '[:upper:]' '[:lower:]')" + printf -v "${comp}_URL" '%s' "${DOWNLOAD_URL}/${comp_lower}.dnp.dappnode.eth_${version_for_filenames}_linux-${ARCH}.txz" + printf -v "${comp}_YML" '%s' "${DOWNLOAD_URL}/docker-compose.yml" + printf -v "${comp}_MANIFEST" '%s' "${DOWNLOAD_URL}/dappnode_package.json" + printf -v "${comp}_YML_FILE" '%s' "${DAPPNODE_CORE_DIR}/docker-compose-${comp_lower}.yml" + printf -v "${comp}_FILE" '%s' "${DAPPNODE_CORE_DIR}/${comp_lower}.dnp.dappnode.eth_${version_for_filenames}_linux-${ARCH}.txz" + printf -v "${comp}_MANIFEST_FILE" '%s' "${DAPPNODE_CORE_DIR}/dappnode_package-${comp_lower}.json" + done +} dappnode_core_build() { for comp in "${PKGS[@]}"; do ver="${comp}_VERSION" if [[ ${!ver} == dev:* ]]; then - echo "Cloning & building DNP_${comp}..." + if $IS_MACOS; then + error "Development builds (dev:*) are not supported on macOS." + exit 1 + fi + log "Cloning & building DNP_${comp}..." if ! dpkg -s git >/dev/null 2>&1; then apt-get install -y git fi - TMPDIR=$(mktemp -d) - pushd "$TMPDIR" || { - echo "Error on pushd" + local tmpdir + tmpdir="$(mktemp -d)" + pushd "$tmpdir" >/dev/null || { + error "Error on pushd" exit 1 } git clone -b "${!ver##*:}" https://github.com/dappnode/DNP_"${comp}" # Change version in YAML to the custom one - DOCKER_VER=$(echo "${!ver##*:}" | sed 's/\//_/g') - sed -i "s~^\(\s*image\s*:\s*\).*~\1${comp,,}.dnp.dappnode.eth:${DOCKER_VER}~" DNP_"${comp}"/docker-compose.yml + local docker_ver comp_lower + docker_ver="$(echo "${!ver##*:}" | sed 's/\//_/g')" + comp_lower="$(echo "$comp" | tr '[:upper:]' '[:lower:]')" + sed_inplace "s~^\(\s*image\s*:\s*\).*~\1${comp_lower}.dnp.dappnode.eth:${docker_ver}~" "DNP_${comp}/docker-compose.yml" docker compose -f ./DNP_"${comp}"/docker-compose.yml build - cp ./DNP_"${comp}"/docker-compose.yml "${DAPPNODE_CORE_DIR}"/docker-compose-"${comp,,}".yml - cp ./DNP_"${comp}"/dappnode_package.json "${DAPPNODE_CORE_DIR}"/dappnode_package-"${comp,,}".json - rm -r ./DNP_"${comp}" - popd || { - echo "Error on popd" + cp "./DNP_${comp}/docker-compose.yml" "${DAPPNODE_CORE_DIR}/docker-compose-${comp_lower}.yml" + cp "./DNP_${comp}/dappnode_package.json" "${DAPPNODE_CORE_DIR}/dappnode_package-${comp_lower}.json" + rm -rf "./DNP_${comp}" + popd >/dev/null || { + error "Error on popd" exit 1 } + rm -rf "$tmpdir" fi done } @@ -163,15 +876,32 @@ dappnode_core_download() { for comp in "${PKGS[@]}"; do ver="${comp}_VERSION" if [[ ${!ver} != dev:* ]]; then - # Download DAppNode Core Images if it's needed - echo "Downloading ${comp} tar..." - eval "[ -f \$${comp}_FILE ] || $WGET -O \$${comp}_FILE \$${comp}_URL || exit 1" - # Download DAppNode Core docker-compose yml files if it's needed - echo "Downloading ${comp} yml..." - eval "[ -f \$${comp}_YML_FILE ] || $WGET -O \$${comp}_YML_FILE \$${comp}_YML || exit 1" - # Download DAppNode Core manifest files if it's needed - echo "Downloading ${comp} manifest..." - eval "[ -f \$${comp}_MANIFEST_FILE ] || $WGET -O \$${comp}_MANIFEST_FILE \$${comp}_MANIFEST || exit 1" + local file_var="${comp}_FILE" + local url_var="${comp}_URL" + local yml_file_var="${comp}_YML_FILE" + local yml_var="${comp}_YML" + local manifest_file_var="${comp}_MANIFEST_FILE" + local manifest_var="${comp}_MANIFEST" + + # Download DAppNode Core Images if needed + log "Downloading ${comp} tar..." + [ -f "${!file_var}" ] || download_file "${!file_var}" "${!url_var}" || exit 1 + # Download DAppNode Core docker-compose yml files if needed + log "Downloading ${comp} yml..." + [ -f "${!yml_file_var}" ] || download_file "${!yml_file_var}" "${!yml_var}" || exit 1 + # Download DAppNode Core manifest files if needed + log "Downloading ${comp} manifest..." + [ -f "${!manifest_file_var}" ] || download_file "${!manifest_file_var}" "${!manifest_var}" || exit 1 + + # macOS: patch compose files for Docker Desktop compatibility + if $IS_MACOS; then + remove_logging_section "${!yml_file_var}" + patch_compose_paths "${!yml_file_var}" + # Inject macOS-specific env vars into the dappmanager compose + if [[ "$comp" == "DAPPMANAGER" ]]; then + patch_dappmanager_compose_for_macos "${!yml_file_var}" + fi + fi fi done } @@ -180,22 +910,64 @@ dappnode_core_load() { for comp in "${PKGS[@]}"; do ver="${comp}_VERSION" if [[ ${!ver} != dev:* ]]; then - eval "[ ! -z \$(docker images -q ${comp,,}.dnp.dappnode.eth:${!ver##*:}) ] || docker load -i \$${comp}_FILE 2>&1 | tee -a \$LOGFILE" + local comp_lower image file_var + comp_lower="$(echo "$comp" | tr '[:upper:]' '[:lower:]')" + image="${comp_lower}.dnp.dappnode.eth:${!ver##*:}" + file_var="${comp}_FILE" + if [[ -z "$(docker images -q "$image" 2>/dev/null)" ]]; then + docker load -i "${!file_var}" 2>&1 | tee -a "$LOGFILE" + fi fi done } customMotd() { - if [ -f ${MOTD_FILE} ]; then - cat <${MOTD_FILE} - ___ _ _ _ _ -| \ /_\ _ __ _ __| \| |___ __| |___ -| |) / _ \| '_ \ '_ \ . / _ \/ _ / -_) -|___/_/ \_\ .__/ .__/_|\_\___/\__,_\___| - |_| |_| -EOF - echo -e "$WELCOME_MESSAGE" >>"$MOTD_FILE" + generateMotdText + + if [ -d "${UPDATE_MOTD_DIR}" ]; then + # Ubuntu configuration + modifyMotdGeneration + fi +} + +# Debian distros use /etc/motd plain text file +generateMotdText() { + local welcome_message + + # Check and create the MOTD file if it does not exist + if [ ! -f "${MOTD_FILE}" ]; then + touch "${MOTD_FILE}" fi + + # Write the ASCII art and welcome message as plain text + cat <<'EOF' >"${MOTD_FILE}" + ___ _ + | \ __ _ _ __ _ __ _ _ ___ __| |___ + | |) / _` | '_ \ '_ \ ' \/ _ \/ _` / -_) + |___/\__,_| .__/ .__/_||_\___/\__,_\___| + |_| |_| +EOF + welcome_message="\nChoose a way to connect to your DAppNode, then go to http://my.dappnode\n\n- Wifi\t\tScan and connect to DAppNodeWIFI. Get wifi credentials with dappnode_wifi\n\n- Local Proxy\tConnect to the same router as your DAppNode. Then go to http://dappnode.local\n\n- Wireguard\tDownload Wireguard app on your device. Get your dappnode wireguard credentials with dappnode_wireguard\n\n- Open VPN\tDownload Open VPN app on your device. Get your openVPN creds with dappnode_openvpn\n\n\nTo see a full list of commands available execute dappnode_help\n" + printf "%b" "$welcome_message" >>"${MOTD_FILE}" +} + +# Ubuntu distros use /etc/update-motd.d/ to generate the motd +modifyMotdGeneration() { + local disabled_motd_dir + disabled_motd_dir="${UPDATE_MOTD_DIR}/disabled" + + mkdir -p "${disabled_motd_dir}" + + # Move all the files in /etc/update-motd.d/ to /etc/update-motd.d/disabled/ + # Except for the files listed in "files_to_keep" + files_to_keep="00-header 50-landscape-sysinfo 98-reboot-required" + local file base_file + for file in "${UPDATE_MOTD_DIR}"/*; do + base_file="$(basename "${file}")" + if [ -f "${file}" ] && ! echo "${files_to_keep}" | grep -qw "${base_file}"; then + mv "${file}" "${disabled_motd_dir}/" + fi + done } addSwap() { @@ -204,72 +976,105 @@ addSwap() { # if not then create it if [ "$IS_SWAP" -eq 0 ]; then - echo -e '\e[32mSwap not found. Adding swapfile.\e[0m' + log 'Swap not found. Adding swapfile.' #RAM=$(awk '/MemTotal/ {print $2}' /proc/meminfo) #SWAP=$(($RAM * 2)) SWAP=8388608 - fallocate -l ${SWAP}k /swapfile + fallocate -l "${SWAP}k" /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile echo '/swapfile none swap defaults 0 0' >>/etc/fstab else - echo -e '\e[32mSwap found. No changes made.\e[0m' + log 'Swap found. No changes made.' fi } -dappnode_start() { - echo -e "\e[32mDAppNode starting...\e[0m" 2>&1 | tee -a $LOGFILE - # shellcheck disable=SC1090 - source "${DAPPNODE_PROFILE}" >/dev/null 2>&1 +# Add .dappnode_profile sourcing to the user's default shell configuration +add_profile_to_shell() { + local user_home + local shell_configs + + if $IS_MACOS; then + user_home="$HOME" + # macOS defaults to zsh, but some users still run bash. + shell_configs=(".zshrc" ".zprofile" ".bashrc" ".bash_profile") + else + # Linux: determine user home from /etc/passwd + local user_name + user_name=$(grep 1000 /etc/passwd | cut -f 1 -d:) + if [ -n "$user_name" ]; then + user_home="/home/$user_name" + else + user_home="/root" + fi + shell_configs=(".profile" ".bashrc") + fi + + for config_file in "${shell_configs[@]}"; do + local config_path="${user_home}/${config_file}" + local source_line + + # .profile may be evaluated by /bin/sh (dash on Debian/Ubuntu) where `source` is not valid. + # Use POSIX '.' there; use `source` elsewhere (bash/zsh). + if [ "$config_file" = ".profile" ]; then + source_line="[ -f \"${DAPPNODE_PROFILE}\" ] && . \"${DAPPNODE_PROFILE}\"" + else + source_line="[ -f \"${DAPPNODE_PROFILE}\" ] && source \"${DAPPNODE_PROFILE}\"" + fi - # Execute `compose-up` independently - # To execute `compose-up` against more than 1 compose, composes files must share compose file version (e.g 3.5) - for comp in "${DNCORE_YMLS_ARRAY[@]}"; do - docker compose -f "$comp" up -d 2>&1 | tee -a $LOGFILE - echo "${comp} started" 2>&1 | tee -a $LOGFILE + # Create config file if it doesn't exist + [ ! -f "$config_path" ] && touch "$config_path" + # Add profile sourcing if not already present + if ! grep -q "${DAPPNODE_PROFILE}" "$config_path"; then + echo "######## DAPPNODE PROFILE ########" >> "$config_path" + echo "$source_line" >> "$config_path" + echo "" >> "$config_path" + fi done - echo -e "\e[32mDAppNode started\e[0m" 2>&1 | tee -a $LOGFILE +} - # Show credentials to the user on login - USER=$(grep 1000 /etc/passwd | cut -f 1 -d:) - [ -n "$USER" ] && PROFILE=/home/$USER/.profile || PROFILE=/root/.profile +dappnode_core_start() { + log "DAppNode starting..." - if ! grep -q "${DAPPNODE_PROFILE}" "$PROFILE"; then - echo "######## DAPPNODE PROFILE ########" >>$PROFILE - echo -e "source ${DAPPNODE_PROFILE}\n" >>$PROFILE + if [[ ${#DNCORE_COMPOSE_ARGS[@]} -eq 0 ]]; then + build_dncore_compose_args fi + [[ ${#DNCORE_COMPOSE_ARGS[@]} -gt 0 ]] || die "No docker-compose-*.yml files found in ${DAPPNODE_CORE_DIR}" + + docker compose "${DNCORE_COMPOSE_ARGS[@]}" up -d 2>&1 | tee -a "$LOGFILE" + log "DAppNode started" + + # Add profile sourcing to user's shell configuration + add_profile_to_shell - # Remove return from profile - sed -i '/return/d' $DAPPNODE_PROFILE | tee -a $LOGFILE + # Remove return from profile so it can be sourced in login shells + sed_inplace '/return/d' "$DAPPNODE_PROFILE" # Download access_credentials script - [ -f $DAPPNODE_ACCESS_CREDENTIALS ] || ${WGET} -O ${DAPPNODE_ACCESS_CREDENTIALS} ${DAPPNODE_ACCESS_CREDENTIALS_URL} + [ -f "$DAPPNODE_ACCESS_CREDENTIALS" ] || download_file "${DAPPNODE_ACCESS_CREDENTIALS}" "${DAPPNODE_ACCESS_CREDENTIALS_URL}" - # Delete dappnode_install.sh execution from rc.local if exists, and is not the unattended firstboot - if [ -f "/etc/rc.local" ] && [ ! -f "/usr/src/dappnode/.firstboot" ]; then - sed -i '/\/usr\/src\/dappnode\/scripts\/dappnode_install.sh/d' /etc/rc.local 2>&1 | tee -a $LOGFILE + # Linux-only: clean up rc.local + if $IS_LINUX; then + if [ -f "/etc/rc.local" ] && [ ! -f "${DAPPNODE_DIR}/.firstboot" ]; then + sed_inplace '/\/usr\/src\/dappnode\/scripts\/dappnode_install.sh/d' /etc/rc.local 2>&1 | tee -a "$LOGFILE" + fi fi # Display help message to the user - echo -e "Execute \e[32mdappnode_help\e[0m to see a full list with commands available" -} - -installExtraDpkg() { - if [ -d "/usr/src/dappnode/extra_dpkg" ]; then - dpkg -i /usr/src/dappnode/iso/extra_dpkg/*.deb 2>&1 | tee -a $LOGFILE - fi + log "Execute dappnode_help to see a full list with commands available" } grabContentHashes() { if [ ! -f "${CONTENT_HASH_FILE}" ]; then - for comp in "${CONTENT_HASH_PKGS[@]}"; do - CONTENT_HASH=$(eval "${SWGET}" https://github.com/dappnode/DAppNodePackage-"${comp}"/releases/latest/download/content-hash) + local content_hash_pkgs=(geth besu nethermind erigon prysm teku lighthouse nimbus lodestar) + for comp in "${content_hash_pkgs[@]}"; do + CONTENT_HASH=$(download_stdout "https://github.com/dappnode/DAppNodePackage-${comp}/releases/latest/download/content-hash") if [ -z "$CONTENT_HASH" ]; then - echo "ERROR! Failed to find content hash of ${comp}." 2>&1 | tee -a $LOGFILE + error "Failed to find content hash of ${comp}." exit 1 fi - echo "${comp}.dnp.dappnode.eth,${CONTENT_HASH}" >>${CONTENT_HASH_FILE} + echo "${comp}.dnp.dappnode.eth,${CONTENT_HASH}" >>"${CONTENT_HASH_FILE}" done fi } @@ -278,70 +1083,132 @@ grabContentHashes() { installSgx() { if [ -d "/usr/src/dappnode/iso/sgx" ]; then # from sgx_linux_x64_driver_2.5.0_2605efa.bin - /usr/src/dappnode/iso/sgx/sgx_linux_x64_driver.bin 2>&1 | tee -a $LOGFILE - /usr/src/dappnode/iso/sgx/enable_sgx 2>&1 | tee -a $LOGFILE + /usr/src/dappnode/iso/sgx/sgx_linux_x64_driver.bin 2>&1 | tee -a "$LOGFILE" + /usr/src/dappnode/iso/sgx/enable_sgx 2>&1 | tee -a "$LOGFILE" fi } # /extra_dpkg will only be installed on ISO's dappnode not on standalone script installExtraDpkg() { if [ -d "/usr/src/dappnode/iso/extra_dpkg" ]; then - dpkg -i /usr/src/dappnode/extra_dpkg/*.deb 2>&1 | tee -a $LOGFILE + dpkg -i /usr/src/dappnode/iso/extra_dpkg/*.deb 2>&1 | tee -a "$LOGFILE" + fi +} + +# The main user needs to be added to the docker group to be able to run docker commands without sudo +# Explained in: https://docs.docker.com/engine/install/linux-postinstall/ +addUserToDockerGroup() { + # UID is provided to the first regular user created in the system + local user + user=$(grep 1000 "/etc/passwd" | cut -f 1 -d:) + + # If USER is not found, warn the user and return + if [ -z "$user" ]; then + warn "Default user not found. Could not add it to the docker group." + return + fi + + if groups "$user" | grep &>/dev/null '\bdocker\b'; then + log "User $user is already in the docker group" + return fi + + # This step is already done in the dappnode_install_pre.sh script, + # but it's not working in the Ubuntu ISO because the late-commands in the autoinstall.yaml + # file are executed before the user is created. + usermod -aG docker "$user" + log "User $user added to the docker group" } ############################################## #### SCRIPT START #### ############################################## -echo -e "\e[32m\n##############################################\e[0m" 2>&1 | tee -a $LOGFILE -echo -e "\e[32m#### DAPPNODE INSTALLER ####\e[0m" 2>&1 | tee -a $LOGFILE -echo -e "\e[32m##############################################\e[0m" 2>&1 | tee -a $LOGFILE +main() { + parse_args "$@" + validate_install_mode -echo -e "\e[32mCreating swap memory...\e[0m" 2>&1 | tee -a $LOGFILE -addSwap + bootstrap_filesystem + check_prereqs + configure_static_ip + ensure_profile_loaded + resolve_packages + # Destructive cleanup runs only after preflight (resolve_packages -> check_vpn_ports_conflict) + # has passed; otherwise a failing port check would wipe the on-disk composes while the + # running containers still hold the ports, leaving the node un-restartable. + clean_for_update -echo -e "\e[32mCustomizing login...\e[0m" 2>&1 | tee -a $LOGFILE -customMotd + echo "" 2>&1 | tee -a "$LOGFILE" + log "##############################################" + log "#### DAPPNODE INSTALLER ####" + log "##############################################" -echo -e "\e[32mInstalling extra packages...\e[0m" 2>&1 | tee -a $LOGFILE -installExtraDpkg + # --- Linux-only setup steps --- + if $IS_LINUX; then + if [[ "${MINIMAL}" != "true" && "${LITE}" != "true" ]]; then + log "Creating swap memory..." + addSwap -echo -e "\e[32mGrabbing latest content hashes...\e[0m" 2>&1 | tee -a $LOGFILE -grabContentHashes + log "Customizing login..." + customMotd -if [ "$ARCH" == "amd64" ]; then - echo -e "\e[32mInstalling SGX modules...\e[0m" 2>&1 | tee -a $LOGFILE - installSgx + log "Installing extra packages..." + installExtraDpkg - echo -e "\e[32mInstalling extra packages...\e[0m" 2>&1 | tee -a $LOGFILE - installExtraDpkg -fi + log "Grabbing latest content hashes..." + grabContentHashes + + if [ "$ARCH" == "amd64" ]; then + log "Installing SGX modules..." + installSgx + + log "Installing extra packages..." + installExtraDpkg # TODO: Why is this being called twice? + fi + fi -echo -e "\e[32mCreating dncore_network if needed...\e[0m" 2>&1 | tee -a $LOGFILE -docker network create --driver bridge --subnet 172.33.0.0/16 dncore_network 2>&1 | tee -a $LOGFILE + log "Adding user to docker group..." + addUserToDockerGroup + fi -echo -e "\e[32mBuilding DAppNode Core if needed...\e[0m" 2>&1 | tee -a $LOGFILE -dappnode_core_build + # --- Common steps (Linux and macOS) --- + log "Creating dncore_network if needed..." + docker network create --driver bridge --subnet 172.33.0.0/16 dncore_network 2>&1 | tee -a "$LOGFILE" || true -echo -e "\e[32mDownloading DAppNode Core...\e[0m" 2>&1 | tee -a $LOGFILE -dappnode_core_download + log "Building DAppNode Core if needed..." + dappnode_core_build -echo -e "\e[32mLoading DAppNode Core...\e[0m" 2>&1 | tee -a $LOGFILE -dappnode_core_load + log "Downloading DAppNode Core..." + dappnode_core_download -if [ ! -f "/usr/src/dappnode/.firstboot" ]; then - echo -e "\e[32mDAppNode installed\e[0m" 2>&1 | tee -a $LOGFILE - dappnode_start -fi + # Build compose args now that compose files exist + build_dncore_compose_args -# Run test in interactive terminal -if [ -f "/usr/src/dappnode/.firstboot" ]; then - # ensure openvt is installed prior to using it - apt-get update - apt-get install -y kbd - openvt -s -w -- sudo -u root /usr/src/dappnode/scripts/dappnode_test_install.sh - exit 0 -fi + log "Loading DAppNode Core..." + dappnode_core_load + + # --- Start DAppNode --- + if $IS_LINUX; then + if [ ! -f "${DAPPNODE_DIR}/.firstboot" ]; then + log "DAppNode installed" + dappnode_core_start + print_vpn_access_credentials + fi + + # Run test in interactive terminal (first boot only) + if [ -f "${DAPPNODE_DIR}/.firstboot" ]; then + apt-get update + apt-get install -y kbd + openvt -s -w -- sudo -u root "${DAPPNODE_DIR}/scripts/dappnode_test_install.sh" + exit 0 + fi + fi + + if $IS_MACOS; then + log "DAppNode installed" + dappnode_core_start + print_vpn_access_credentials + fi +} -exit 0 +main "$@" diff --git a/scripts/dappnode_install_pre.sh b/scripts/dappnode_install_pre.sh index e09ae685..d6cf4739 100755 --- a/scripts/dappnode_install_pre.sh +++ b/scripts/dappnode_install_pre.sh @@ -6,8 +6,6 @@ DAPPNODE_DIR="/usr/src/dappnode" LOGS_DIR="$DAPPNODE_DIR/logs" lsb_dist="$(. /etc/os-release && echo "$ID")" -#!ISOBUILD Do not modify, variables above imported for ISO build - detect_installation_type() { if [ -f "${DAPPNODE_DIR}/iso_install.log" ]; then LOG_FILE="${LOGS_DIR}/iso_install.log" @@ -22,21 +20,30 @@ detect_installation_type() { add_docker_repo() { apt-get update -y apt-get remove -y docker docker-engine docker.io containerd runc | tee -a $LOG_FILE - apt-get install -y ca-certificates curl gnupg lsb-release | tee -a $LOG_FILE - mkdir -p /etc/apt/keyrings && chmod -R 0755 /etc/apt/keyrings - curl -fsSL "https://download.docker.com/linux/${lsb_dist}/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg + + # Add Docker GPG key + apt-get install -y ca-certificates curl lsb-release | tee -a $LOG_FILE + install -m 0755 -d /etc/apt/keyrings + curl -fsSL "https://download.docker.com/linux/${lsb_dist}/gpg" -o /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.gpg - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$lsb_dist $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list >/dev/null + + # Add the repository to APT sources + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/$lsb_dist $(lsb_release -cs) stable" | + tee /etc/apt/sources.list.d/docker.list >/dev/null + + apt-get update -y } # DOCKER INSTALLATION install_docker() { apt-get update -y - apt-get install -y docker-ce docker-ce-cli containerd.io | tee -a $LOG_FILE + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | tee -a $LOG_FILE # Ensure xz is installed [ -f "/usr/bin/xz" ] || (apt-get install -y xz-utils) + # Not working in Ubuntu ISO because the user is not created before executing late-commands USER=$(grep 1000 "/etc/passwd" | cut -f 1 -d:) [ -z "$USER" ] || usermod -aG docker "$USER" @@ -102,6 +109,34 @@ host_update() { apt-get -y upgrade 2>&1 | tee -a $LOG_FILE } +check_ubuntu_connectivity() { + { netplan get | grep "dhcp4: true" &>/dev/null; } || { + echo "Interfaces not found" + exit 1 + } +} + +check_debian_connectivity() { + { [ -f /etc/network/interfaces ] && grep "iface en.* inet dhcp" /etc/network/interfaces &>/dev/null; } || { + echo "Interfaces not found" + exit 1 + } +} + +add_debian_missing_interfaces() { + # shellcheck disable=SC2013 + for IFACE in $(grep "en.*" /usr/src/dappnode/hotplug); do + # shellcheck disable=SC2143 + if [[ $(grep -L "$IFACE" /etc/network/interfaces) ]]; then + { + echo "# $IFACE" + echo "allow-hotplug $IFACE" + echo "iface $IFACE inet dhcp" + } >>/etc/network/interfaces + fi + done +} + ############################################## #### SCRIPT START #### ############################################## @@ -147,17 +182,10 @@ else install_lsof 2>&1 | tee -a $LOG_FILE fi -## Add missing interfaces -if [ -f /usr/src/dappnode/hotplug ]; then - # shellcheck disable=SC2013 - for IFACE in $(grep "en.*" /usr/src/dappnode/hotplug); do - # shellcheck disable=SC2143 - if [[ $(grep -L "$IFACE" /etc/network/interfaces) ]]; then - { - echo "# $IFACE" - echo "allow-hotplug $IFACE" - echo "iface $IFACE inet dhcp" - } >>/etc/network/interfaces - fi - done +## Add or Update Network Configuration Based on OS +if [ "$lsb_dist" = "ubuntu" ]; then + check_ubuntu_connectivity +else + check_debian_connectivity + add_debian_missing_interfaces fi diff --git a/scripts/dappnode_uninstall.sh b/scripts/dappnode_uninstall.sh index 9f9c68b7..29da4a5e 100755 --- a/scripts/dappnode_uninstall.sh +++ b/scripts/dappnode_uninstall.sh @@ -1,21 +1,72 @@ #!/usr/bin/env bash -DAPPNODE_DIR="/usr/src/dappnode" + +# This uninstaller is written for bash. It's safe to *run it from zsh* (it will execute via bash +# thanks to the shebang), but users sometimes invoke it as `zsh ./script.sh` or `source ./script.sh`. +# - If sourced, bail out (sourcing would pollute the current shell and can break it). +# - If invoked by a non-bash shell, re-exec with bash before hitting bash-specific builtins. +if (return 0 2>/dev/null); then + echo "This script must be executed, not sourced. Run: bash $0" + return 1 +fi + +if [ -z "${BASH_VERSION:-}" ]; then + exec /usr/bin/env bash "$0" "$@" +fi + +################## +# OS DETECTION # +################## +OS_TYPE="$(uname -s)" +IS_MACOS=false +IS_LINUX=false +if [[ "$OS_TYPE" == "Darwin" ]]; then + IS_MACOS=true +elif [[ "$OS_TYPE" == "Linux" ]]; then + IS_LINUX=true +else + echo "Unsupported operating system: $OS_TYPE" + exit 1 +fi + +############# +# VARIABLES # +############# +# Dirs — macOS uses $HOME/dappnode, Linux uses /usr/src/dappnode (mirrors install script) +if $IS_MACOS; then + DAPPNODE_DIR="$HOME/dappnode" +else + DAPPNODE_DIR="/usr/src/dappnode" +fi DAPPNODE_CORE_DIR="${DAPPNODE_DIR}/DNCORE" PROFILE_FILE="${DAPPNODE_CORE_DIR}/.dappnode_profile" input=$1 # Allow to call script with argument (must be Y/N) -[ -f $PROFILE_FILE ] || ( - echo "Error: DAppNode profile does not exist." +############################## +# Cross-platform Helpers # +############################## + +# Cross-platform in-place sed (macOS requires '' after -i) +sed_inplace() { + if $IS_MACOS; then + sed -i '' "$@" + else + sed -i "$@" + fi +} + +[ -f "$PROFILE_FILE" ] || { + echo "Error: DAppNode profile does not exist at ${PROFILE_FILE}." exit 1 -) +} uninstall() { - echo -e "\e[32mUninstalling DAppNode\e[0m" + echo "Uninstalling DAppNode" # shellcheck disable=SC1090 source "${PROFILE_FILE}" &>/dev/null DAPPNODE_CONTAINERS="$(docker ps -a --format '{{.Names}}' | grep DAppNode)" - echo -e "\e[32mRemoving DAppNode containers: \e[0m\n${DAPPNODE_CONTAINERS}" + echo "Removing DAppNode containers: " + echo "${DAPPNODE_CONTAINERS}" for container in $DAPPNODE_CONTAINERS; do # Stop DAppNode container docker stop "$container" &>/dev/null @@ -24,34 +75,58 @@ uninstall() { done DAPPNODE_IMAGES="$(docker image ls -a | grep "dappnode")" - echo -e "\e[32mRemoving DAppNode images: \e[0m\n${DAPPNODE_IMAGES}" + echo "Removing DAppNode images: " + echo "${DAPPNODE_IMAGES}" for image in $DAPPNODE_IMAGES; do # Remove DAppNode images docker image rm "$image" &>/dev/null done DAPPNODE_VOLUMES="$(docker volume ls | grep "dappnode\|dncore")" - echo -e "\e[32mRemoving DAppNode volumes: \e[0m\n${DAPPNODE_VOLUMES}" + echo "Removing DAppNode volumes: " + echo "${DAPPNODE_VOLUMES}" for volume in $DAPPNODE_VOLUMES; do # Remove DAppNode volumes docker volume rm "$volume" &>/dev/null done # Remove dncore_network - echo -e "\e[32mRemoving docker dncore_network\e[0m" + echo "Removing docker dncore_network" docker network remove dncore_network || echo "dncore_network already removed" - # Remove dir - echo -e "\e[32mRemoving DAppNode directory\e[0m" - rm -rf /usr/src/dappnode + # Remove DAppNode directory + echo "Removing DAppNode directory: ${DAPPNODE_DIR}" + rm -rf "${DAPPNODE_DIR}" + + # Remove profile file references from shell config files + local user_home + local shell_configs - # Remove profile file - USER=$(grep 1000 /etc/passwd | cut -f 1 -d:) - [ -n "$USER" ] && PROFILE=/home/$USER/.profile || PROFILE=/root/.profile - sed -i '/######## DAPPNODE PROFILE ########/g' $PROFILE - sed -i '/.*dappnode_profile/g' $PROFILE + if $IS_MACOS; then + user_home="$HOME" + # macOS defaults to zsh — matches install script + shell_configs=(".zshrc" ".zprofile") + else + local user_name + user_name=$(grep 1000 /etc/passwd | cut -f 1 -d:) + if [ -n "$user_name" ]; then + user_home="/home/$user_name" + else + user_home="/root" + fi + shell_configs=(".profile" ".bashrc") + fi + + # Remove Dappnode profile references from shell config files + for config_file in "${shell_configs[@]}"; do + local config_path="${user_home}/${config_file}" + if [ -f "$config_path" ]; then + sed_inplace '/######## DAPPNODE PROFILE ########/d' "$config_path" + sed_inplace '/.*dappnode_profile/d' "$config_path" + fi + done - echo -e "\e[32mDAppNode uninstalled!\e[0m" + echo "DAppNode uninstalled!" } if [ $# -eq 0 ]; then