Skip to content

Commit 68d2736

Browse files
Update IPFS endpoint and enhance logging in installation script
1 parent 174d5e5 commit 68d2736

1 file changed

Lines changed: 135 additions & 42 deletions

File tree

scripts/dappnode_install.sh

Lines changed: 135 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if $IS_LINUX; then
5656
fi
5757
# Get URLs
5858
PROFILE_BRANCH=${PROFILE_BRANCH:-"master"}
59-
IPFS_ENDPOINT=${IPFS_ENDPOINT:-"http://ipfs.io"}
59+
IPFS_ENDPOINT=${IPFS_ENDPOINT:-"https://ipfs-gateway-dev.dappnode.net"}
6060
# PROFILE_URL env is used to fetch the core packages versions that will be used to build the release in script install method
6161
PROFILE_URL=${PROFILE_URL:-"https://github.com/dappnode/DAppNode/releases/latest/download/dappnode_profile.sh"}
6262
DAPPNODE_ACCESS_CREDENTIALS="${DAPPNODE_DIR}/scripts/dappnode_access_credentials.sh"
@@ -72,6 +72,21 @@ else
7272
ARCH=$(dpkg --print-architecture)
7373
fi
7474

75+
# Color output helpers
76+
color_echo() {
77+
local color="$1"; shift
78+
if $IS_LINUX; then
79+
case "$color" in
80+
green) code="\e[32m" ;;
81+
yellow) code="\e[33m" ;;
82+
*) code="" ;;
83+
esac
84+
echo -e "${code}$*\e[0m"
85+
else
86+
echo "$*"
87+
fi
88+
}
89+
7590
##############################
7691
# Cross-platform Helpers #
7792
##############################
@@ -80,6 +95,7 @@ fi
8095
download_file() {
8196
local dest="$1"
8297
local url="$2"
98+
echo "[DEBUG] Downloading from $url to $dest" 2>&1 | tee -a $LOGFILE
8399
if $IS_MACOS; then
84100
curl -sL -o "$dest" "$url"
85101
else
@@ -91,12 +107,66 @@ download_file() {
91107
download_stdout() {
92108
local url="$1"
93109
if $IS_MACOS; then
94-
curl -sL "$url"
110+
curl -fsSL "$url"
95111
else
96112
wget -q -O- "$url"
97113
fi
98114
}
99115

116+
# Normalize IPFS refs and (if needed) infer the missing :<version> from dappnode_package.json
117+
# Accepts:
118+
# - /ipfs/<cid>:<version>
119+
# - /ipfs/<cid> (version inferred)
120+
# - ipfs/<cid>[:<version>] (leading slash normalized)
121+
normalize_ipfs_version_ref() {
122+
local raw_ref="$1"
123+
local comp="$2"
124+
local ref="$raw_ref"
125+
126+
if [[ "$ref" == ipfs/* ]]; then
127+
ref="/$ref"
128+
fi
129+
130+
# If it already has :<version>, we're done
131+
if [[ "$ref" == /ipfs/*:* ]]; then
132+
echo "$ref"
133+
return 0
134+
fi
135+
136+
# If it's an IPFS ref without a :<version>, infer it from the manifest in the CID
137+
if [[ "$ref" == /ipfs/* ]]; then
138+
local cid_path="$ref"
139+
local manifest_url="${IPFS_ENDPOINT%/}${cid_path}/dappnode_package.json"
140+
local manifest
141+
manifest="$(download_stdout "$manifest_url" 2>/dev/null || true)"
142+
if [[ -z "$manifest" ]]; then
143+
echo "[ERROR] Could not fetch IPFS manifest for ${comp} from: $manifest_url" 1>&2
144+
echo "[ERROR] Provide ${comp}_VERSION as /ipfs/<cid>:<version> (example: /ipfs/Qm...:0.2.11)" 1>&2
145+
return 1
146+
fi
147+
148+
local inferred_version
149+
inferred_version="$(
150+
echo "$manifest" |
151+
tr -d '\r' |
152+
grep -m1 '"version"' |
153+
sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^\"]+)".*/\1/'
154+
)"
155+
156+
if [[ -z "$inferred_version" || "$inferred_version" == "$manifest" ]]; then
157+
echo "[ERROR] Could not infer version for ${comp} from IPFS manifest: $manifest_url" 1>&2
158+
echo "[ERROR] Provide ${comp}_VERSION as /ipfs/<cid>:<version>" 1>&2
159+
return 1
160+
fi
161+
162+
echo "${cid_path}:${inferred_version}"
163+
return 0
164+
fi
165+
166+
# Not an IPFS ref; return as-is
167+
echo "$raw_ref"
168+
}
169+
100170
# Cross-platform in-place sed (macOS requires '' after -i)
101171
sed_inplace() {
102172
if $IS_MACOS; then
@@ -196,18 +266,25 @@ determine_packages() {
196266
is_port_used
197267
if [ "$IS_ISO_INSTALL" == "false" ]; then
198268
if [ "$IS_PORT_USED" == "true" ]; then
199-
PKGS=(BIND IPFS VPN WIREGUARD DAPPMANAGER WIFI)
269+
PKGS=(BIND IPFS VPN WIREGUARD DAPPMANAGER)
200270
else
201-
PKGS=(HTTPS BIND IPFS WIREGUARD DAPPMANAGER WIFI)
271+
PKGS=(HTTPS BIND IPFS VPN WIREGUARD DAPPMANAGER)
202272
fi
203273
else
204274
if [ "$IS_PORT_USED" == "true" ]; then
205-
PKGS=(BIND IPFS WIREGUARD DAPPMANAGER WIFI)
275+
PKGS=(BIND IPFS VPN WIREGUARD DAPPMANAGER)
206276
else
207-
PKGS=(HTTPS BIND IPFS WIREGUARD DAPPMANAGER WIFI)
277+
PKGS=(HTTPS BIND IPFS VPN WIREGUARD DAPPMANAGER)
208278
fi
209279
fi
210-
echo -e "\e[32mPackages to be installed: ${PKGS[*]}\e[0m" 2>&1 | tee -a $LOGFILE
280+
color_echo green "Packages to be installed: ${PKGS[*]}" 2>&1 | tee -a $LOGFILE
281+
282+
# Debug: print all PKGS and their version variables
283+
echo "[DEBUG] PKGS: ${PKGS[*]}" 2>&1 | tee -a $LOGFILE
284+
for comp in "${PKGS[@]}"; do
285+
ver_var="${comp}_VERSION"
286+
echo "[DEBUG] $ver_var = ${!ver_var}" 2>&1 | tee -a $LOGFILE
287+
done
211288
}
212289

213290
function valid_ip() {
@@ -235,8 +312,14 @@ if [[ -n "$STATIC_IP" ]]; then
235312
fi
236313
fi
237314

238-
# Loads profile, if not exists it means it is script install so the versions will be fetched from the latest profile
239-
[ -f "$DAPPNODE_PROFILE" ] || download_file "${DAPPNODE_PROFILE}" "${PROFILE_URL}"
315+
316+
# If LOCAL_PROFILE_PATH is set, use it as the profile source instead of downloading
317+
if [ -n "$LOCAL_PROFILE_PATH" ]; then
318+
echo "Using local profile: $LOCAL_PROFILE_PATH" | tee -a $LOGFILE
319+
cp "$LOCAL_PROFILE_PATH" "$DAPPNODE_PROFILE"
320+
elif [ ! -f "$DAPPNODE_PROFILE" ]; then
321+
download_file "${DAPPNODE_PROFILE}" "${PROFILE_URL}"
322+
fi
240323

241324
# Patch profile for macOS compatibility (replace GNU-isms and hardcoded Linux paths)
242325
# TODO: remove once profile macos-compatibility published
@@ -254,16 +337,26 @@ source "${DAPPNODE_PROFILE}"
254337
determine_packages
255338
for comp in "${PKGS[@]}"; do
256339
ver="${comp}_VERSION"
257-
DOWNLOAD_URL="https://github.com/dappnode/DNP_${comp}/releases/download/v${!ver}"
258-
if [[ ${!ver} == /ipfs/* ]]; then
259-
DOWNLOAD_URL="${IPFS_ENDPOINT}/api/v0/cat?arg=${!ver%:*}"
340+
echo "[DEBUG] Processing $comp: ${!ver}" 2>&1 | tee -a $LOGFILE
341+
342+
raw_version_ref="${!ver}"
343+
if [[ "$raw_version_ref" == /ipfs/* || "$raw_version_ref" == ipfs/* ]]; then
344+
resolved_ref="$(normalize_ipfs_version_ref "$raw_version_ref" "$comp")" || exit 1
345+
eval "${comp}_VERSION=\"${resolved_ref}\""
346+
raw_version_ref="$resolved_ref"
347+
echo "[DEBUG] Using IPFS for ${comp}: ${raw_version_ref%:*} (version ${raw_version_ref##*:})" 2>&1 | tee -a $LOGFILE
348+
DOWNLOAD_URL="${IPFS_ENDPOINT%/}${raw_version_ref%:*}"
349+
version_for_filenames="${raw_version_ref##*:}"
350+
else
351+
version_for_filenames="${raw_version_ref##*:}"
352+
DOWNLOAD_URL="https://github.com/dappnode/DNP_${comp}/releases/download/v${version_for_filenames}"
260353
fi
261354
comp_lower=$(echo "$comp" | tr '[:upper:]' '[:lower:]')
262-
eval "${comp}_URL=\"${DOWNLOAD_URL}/${comp_lower}.dnp.dappnode.eth_${!ver##*:}_linux-${ARCH}.txz\""
355+
eval "${comp}_URL=\"${DOWNLOAD_URL}/${comp_lower}.dnp.dappnode.eth_${version_for_filenames}_linux-${ARCH}.txz\""
263356
eval "${comp}_YML=\"${DOWNLOAD_URL}/docker-compose.yml\""
264357
eval "${comp}_MANIFEST=\"${DOWNLOAD_URL}/dappnode_package.json\""
265358
eval "${comp}_YML_FILE=\"${DAPPNODE_CORE_DIR}/docker-compose-${comp_lower}.yml\""
266-
eval "${comp}_FILE=\"${DAPPNODE_CORE_DIR}/${comp_lower}.dnp.dappnode.eth_${!ver##*:}_linux-${ARCH}.txz\""
359+
eval "${comp}_FILE=\"${DAPPNODE_CORE_DIR}/${comp_lower}.dnp.dappnode.eth_${version_for_filenames}_linux-${ARCH}.txz\""
267360
eval "${comp}_MANIFEST_FILE=\"${DAPPNODE_CORE_DIR}/dappnode_package-${comp_lower}.json\""
268361
done
269362

@@ -542,57 +635,57 @@ addUserToDockerGroup() {
542635
#### SCRIPT START ####
543636
##############################################
544637

545-
echo -e "\e[32m\n##############################################\e[0m" 2>&1 | tee -a $LOGFILE
546-
echo -e "\e[32m#### DAPPNODE INSTALLER ####\e[0m" 2>&1 | tee -a $LOGFILE
547-
echo -e "\e[32m##############################################\e[0m" 2>&1 | tee -a $LOGFILE
638+
color_echo green "\n##############################################" 2>&1 | tee -a $LOGFILE
639+
color_echo green "#### DAPPNODE INSTALLER ####" 2>&1 | tee -a $LOGFILE
640+
color_echo green "##############################################" 2>&1 | tee -a $LOGFILE
548641

549642
# --- Linux-only setup steps ---
550643
if $IS_LINUX; then
551-
echo -e "\e[32mCreating swap memory...\e[0m" 2>&1 | tee -a $LOGFILE
644+
color_echo green "Creating swap memory..." 2>&1 | tee -a $LOGFILE
552645
addSwap
553646

554-
echo -e "\e[32mCustomizing login...\e[0m" 2>&1 | tee -a $LOGFILE
647+
color_echo green "Customizing login..." 2>&1 | tee -a $LOGFILE
555648
customMotd
556649

557-
echo -e "\e[32mInstalling extra packages...\e[0m" 2>&1 | tee -a $LOGFILE
650+
color_echo green "Installing extra packages..." 2>&1 | tee -a $LOGFILE
558651
installExtraDpkg
559652

560-
echo -e "\e[32mGrabbing latest content hashes...\e[0m" 2>&1 | tee -a $LOGFILE
653+
color_echo green "Grabbing latest content hashes..." 2>&1 | tee -a $LOGFILE
561654
grabContentHashes
562655

563656
if [ "$ARCH" == "amd64" ]; then
564-
echo -e "\e[32mInstalling SGX modules...\e[0m" 2>&1 | tee -a $LOGFILE
657+
color_echo green "Installing SGX modules..." 2>&1 | tee -a $LOGFILE
565658
installSgx
566659

567-
echo -e "\e[32mInstalling extra packages...\e[0m" 2>&1 | tee -a $LOGFILE
660+
color_echo green "Installing extra packages..." 2>&1 | tee -a $LOGFILE
568661
installExtraDpkg # TODO: Why is this being called twice?
569662
fi
570663

571-
echo -e "\e[32mAdding user to docker group...\e[0m" 2>&1 | tee -a $LOGFILE
664+
color_echo green "Adding user to docker group..." 2>&1 | tee -a $LOGFILE
572665
addUserToDockerGroup
573666
fi
574667

575668
# --- Common steps (Linux and macOS) ---
576-
echo -e "\e[32mCreating dncore_network if needed...\e[0m" 2>&1 | tee -a $LOGFILE
669+
color_echo green "Creating dncore_network if needed..." 2>&1 | tee -a $LOGFILE
577670
docker network create --driver bridge --subnet 172.33.0.0/16 dncore_network 2>&1 | tee -a $LOGFILE || true
578671

579-
echo -e "\e[32mBuilding DAppNode Core if needed...\e[0m" 2>&1 | tee -a $LOGFILE
672+
color_echo green "Building DAppNode Core if needed..." 2>&1 | tee -a $LOGFILE
580673
dappnode_core_build
581674

582-
echo -e "\e[32mDownloading DAppNode Core...\e[0m" 2>&1 | tee -a $LOGFILE
675+
color_echo green "Downloading DAppNode Core..." 2>&1 | tee -a $LOGFILE
583676
dappnode_core_download
584677

585678
# Re-source profile now that compose files exist, so DNCORE_YMLS is populated
586679
# shellcheck disable=SC1090
587680
source "${DAPPNODE_PROFILE}"
588681

589-
echo -e "\e[32mLoading DAppNode Core...\e[0m" 2>&1 | tee -a $LOGFILE
682+
color_echo green "Loading DAppNode Core..." 2>&1 | tee -a $LOGFILE
590683
dappnode_core_load
591684

592685
# --- Start DAppNode ---
593686
if $IS_LINUX; then
594687
if [ ! -f "${DAPPNODE_DIR}/.firstboot" ]; then
595-
echo -e "\e[32mDAppNode installed\e[0m" 2>&1 | tee -a $LOGFILE
688+
color_echo green "DAppNode installed" 2>&1 | tee -a $LOGFILE
596689
dappnode_core_start
597690
fi
598691

@@ -606,28 +699,28 @@ if $IS_LINUX; then
606699
fi
607700

608701
if $IS_MACOS; then
609-
echo -e "\e[32mDAppNode installed\e[0m" 2>&1 | tee -a $LOGFILE
702+
color_echo green "DAppNode installed" 2>&1 | tee -a $LOGFILE
610703
dappnode_core_start
611704

612-
echo -e "\n\e[33mWaiting for VPN initialization...\e[0m"
705+
color_echo yellow "\nWaiting for VPN initialization..."
613706
sleep 10
614707

615-
echo -e "\n\e[32m##############################################\e[0m"
616-
echo -e "\e[32m# DAppNode VPN Access Credentials #\e[0m"
617-
echo -e "\e[32m##############################################\e[0m"
618-
echo -e "\n\e[1mYour DAppNode is ready! Connect using your preferred VPN client.\e[0m"
619-
echo -e "\e[1mChoose either Wireguard (recommended) or OpenVPN and import the\e[0m"
620-
echo -e "\e[1mcredentials below into your VPN app to access your DAppNode.\e[0m\n"
708+
color_echo green "\n##############################################"
709+
color_echo green "# DAppNode VPN Access Credentials #"
710+
color_echo green "##############################################"
711+
echo -e "\nYour DAppNode is ready! Connect using your preferred VPN client."
712+
echo -e "Choose either Wireguard (recommended) or OpenVPN and import the"
713+
echo -e "credentials below into your VPN app to access your DAppNode.\n"
621714

622-
echo -e "\e[1m--- Wireguard ---\e[0m"
715+
echo -e "--- Wireguard ---"
623716
dappnode_wireguard --localhost 2>&1 || \
624-
echo -e "\e[33mWireguard credentials not yet available. Try later with: dappnode_wireguard --localhost\e[0m"
717+
color_echo yellow "Wireguard credentials not yet available. Try later with: dappnode_wireguard --localhost"
625718

626-
echo -e "\n\e[1m--- OpenVPN ---\e[0m"
719+
echo -e "\n--- OpenVPN ---"
627720
dappnode_openvpn_get dappnode_admin --localhost 2>&1 || \
628-
echo -e "\e[33mOpenVPN credentials not yet available. Try later with: dappnode_openvpn_get dappnode_admin --localhost\e[0m"
721+
color_echo yellow "OpenVPN credentials not yet available. Try later with: dappnode_openvpn_get dappnode_admin --localhost"
629722

630-
echo -e "\n\e[32mImport the configuration above into your VPN client of choice to access your DAppNode at http://my.dappnode\e[0m"
723+
echo -e "\nImport the configuration above into your VPN client of choice to access your DAppNode at http://my.dappnode"
631724
fi
632725

633726
exit 0

0 commit comments

Comments
 (0)