From 4b8a72e9341f0c978d372db597b9cd500f97ede6 Mon Sep 17 00:00:00 2001 From: Yann Autissier Date: Wed, 16 Nov 2022 05:11:07 +0000 Subject: [PATCH] add docker files --- .dockerignore | 1 + .env.dist | 1 + .gitignore | 1 + 12345.sh | 4 +- ASTROBOT/FRIENDS.manage.sh | 2 +- ASTROBOT/PLAYER.refresh.sh | 2 +- ASTROBOT/_G1CrowdBunker.sh | 2 +- Makefile | 21 +++++ _12345.sh | 2 +- ajouter_media.sh | 2 +- docker/Dockerfile | 176 +++++++++++++++++++++++++++++++++++++ docker/docker-compose.app.yml | 20 +++++ docker/docker-compose.yml | 36 ++++++++ docker/docker-entrypoint.sh | 37 ++++++++ start.sh | 2 +- tools/Connect_PLAYER_To_Gchange.sh | 2 +- tools/FRIENDS.init.sh | 2 +- tools/VISA.new.sh | 2 +- tools/ipfs_config.sh | 45 ++++++++++ tools/ipfs_setup.sh | 43 +-------- tools/new_file_in_astroport.sh | 2 +- tools/new_mp3_in_astroport.sh | 2 +- tools/vlc_webcam.sh | 2 +- 23 files changed, 354 insertions(+), 55 deletions(-) create mode 100644 .dockerignore create mode 100644 .env.dist create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.app.yml create mode 100644 docker/docker-compose.yml create mode 100755 docker/docker-entrypoint.sh create mode 100644 tools/ipfs_config.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c1c9f4dc --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git* diff --git a/.env.dist b/.env.dist new file mode 100644 index 00000000..b045f572 --- /dev/null +++ b/.env.dist @@ -0,0 +1 @@ +DOCKER_SERVICE_1234_TAGS=urlprefix-astroport.${APP_DOMAIN}/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4c49bd78 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/12345.sh b/12345.sh index c2506866..2c358e2d 100755 --- a/12345.sh +++ b/12345.sh @@ -21,7 +21,7 @@ isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|( PORT=12345 - YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); ## $USER running ipfs + YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); ## $USER running ipfs LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) ## SWARM#0 ENTRANCE URL mkdir -p ~/.zen/tmp/coucou/ @@ -61,7 +61,7 @@ while true; do MOATS=$(date -u +"%Y%m%d%H%M%S%4N") ## CHANGE NEXT PORT (HERE YOU CREATE A SOCKET QUEUE) - [ ${PORT} -le 12345 ] && PORT=$((PORT+${RANDOM:0:3})) || PORT=$((PORT-${RANDOM:0:3})) + [ ${PORT} -le 12345 ] && PORT=$((PORT+${RANDOM:0:2})) || PORT=$((PORT-${RANDOM:0:2})) portinuse=$(ps auxf --sort=+utime | grep -w ${PORT} | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) [[ $portinuse ]] && echo "$portinuse" && continue ## RANDOM PORT SWAPPINESS AVOIDING COLLISION diff --git a/ASTROBOT/FRIENDS.manage.sh b/ASTROBOT/FRIENDS.manage.sh index e977d39a..5007125b 100755 --- a/ASTROBOT/FRIENDS.manage.sh +++ b/ASTROBOT/FRIENDS.manage.sh @@ -11,7 +11,7 @@ countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|gr [[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 0 start=`date +%s` -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1 +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1 G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) && [[ ! $G1PUB ]] && echo "ERREUR G1PUB. EXIT" && exit 1 IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) || ( echo "noipfsid" && exit 1 ) ######################################################################## diff --git a/ASTROBOT/PLAYER.refresh.sh b/ASTROBOT/PLAYER.refresh.sh index f0538c68..b26465b8 100755 --- a/ASTROBOT/PLAYER.refresh.sh +++ b/ASTROBOT/PLAYER.refresh.sh @@ -53,7 +53,7 @@ isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|( [[ ! $myIP || $isLAN ]] && myIP="127.0.1.1" echo "Getting latest online TW..." - YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); + YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) echo "$LIBRA/ipns/$ASTRONAUTENS" echo "http://$myIP:8080/ipns/$ASTRONAUTENS ($YOU)" diff --git a/ASTROBOT/_G1CrowdBunker.sh b/ASTROBOT/_G1CrowdBunker.sh index c1b1dfea..79f3f82b 100755 --- a/ASTROBOT/_G1CrowdBunker.sh +++ b/ASTROBOT/_G1CrowdBunker.sh @@ -13,7 +13,7 @@ MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" TS=$(date -u +%s%N | cut -b1-13) -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || echo " warning ipfs daemon not running" +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || echo " warning ipfs daemon not running" isLAN=$(hostname -I | awk '{print $1}' | head -n 1 | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") IPFSGWESC="https:\/\/tube.copylaradio.com" && IPFSNGW="https://tube.copylaradio.com" diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..31000978 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +MYOS ?= ../myos +MYOS_REPOSITORY ?= https://github.com/aynicos/myos +-include $(MYOS)/make/include.mk +$(MYOS): + -@git clone $(MYOS_REPOSITORY) $(MYOS) + +.PHONY: all install shellcheck shellcheck-% tests +SHELL_FILES ?= $(wildcard .*/*.sh */*.sh */*/*.sh) + +all: install tests + +install: + ./install.sh + +tests: shellcheck + +shellcheck: + shellcheck $(SHELL_FILES) ||: + +shellcheck-%: + shellcheck $*/*.sh diff --git a/_12345.sh b/_12345.sh index f7c74436..eda3de54 100755 --- a/_12345.sh +++ b/_12345.sh @@ -17,7 +17,7 @@ isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|( PORT=12345 - YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); ## $USER running ipfs + YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); ## $USER running ipfs LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) ## SWARM#0 ENTRANCE URL ncrunning=$(ps auxf --sort=+utime | grep -w 'nc -l -p 12345' | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) diff --git a/ajouter_media.sh b/ajouter_media.sh index 6138ecd2..6f39fca3 100755 --- a/ajouter_media.sh +++ b/ajouter_media.sh @@ -106,7 +106,7 @@ if [[ $1 == "on" ]]; then fi ## CHECK IF ASTROPORT/CRON/IPFS IS RUNNING -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) [[ ! $YOU ]] && espeak "I P F S not running - EXIT" && exit 1 ######################################################################## diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..f8f3ace3 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,176 @@ +FROM debian:bullseye as dist +LABEL maintainer aynic.os +ARG DOCKER_BUILD_DIR +ARG DOCKER_MACHINE=x86_64 +ARG DOCKER_SYSTEM=Linux + +RUN apt-get update \ + && apt-get -fy upgrade \ + && apt-get -fy install \ + bash \ + bc \ + cron \ + curl \ + dnsutils \ + detox \ + espeak \ + fail2ban \ + file \ + ffmpeg \ + gawk \ + gettext \ + git \ + gpg \ + gpg-agent \ + html2text \ + httrack \ + imagemagick \ + inotify-tools \ + jq \ + libsodium* \ + make \ + mp3info \ + mpack \ + msmtp \ + musl-dev \ + nano \ + net-tools \ + netcat-traditional \ + nmap \ + npm \ + ntpdate \ + openssh-client \ + openssl* \ + python3 \ + python3-brotli \ + python3-dotenv \ + python3-gpg \ + python3-jwcrypto \ + python3-opencv \ + python3-pip \ + python3-setuptools \ + python3-wheel \ + qrencode \ + screen \ + socat \ + ssmtp \ + sudo \ + tmux \ + v4l-utils \ + vlc \ + vim-nox \ + wget \ + x11-utils \ + xclip \ + xz-utils \ + youtube-dl \ + zenity \ + && sed -i '/PDF/d' /etc/ImageMagick-6/policy.xml \ + && ln -f -s /usr/bin/python3 /usr/bin/python \ + && rm -rf /var/lib/apt/lists/* + +RUN set -x && buildDeps=' \ + build-essential \ + libssl-dev \ + cargo \ + libffi-dev \ + python3-dev \ + swig \ + ' \ + && apt-get update \ + && apt-get install -y $buildDeps --no-install-recommends \ + && mkdir -p /usr/local/src/jaklis \ + && wget -qO - https://git.p2p.legal/axiom-team/jaklis/archive/master.tar.gz \ + |tar --strip-components 1 -C /usr/local/src/jaklis -xzf - \ + && pip3 install -r /usr/local/src/jaklis/requirements.txt \ + && ln -s /usr/local/src/jaklis/jaklis.py /usr/local/bin/jaklis \ + && chmod 0755 /usr/local/bin/jaklis \ + && /usr/local/bin/jaklis --help >/dev/null \ + && mkdir -p /usr/local/src/dpgpid \ + && wget -qO - https://git.p2p.legal/aya/dpgpid/archive/master.tar.gz \ + |tar --strip-components 1 -C /usr/local/src/dpgpid -xzf - \ + && pip3 install -r /usr/local/src/dpgpid/requirements.txt \ + && ln -s /usr/local/src/dpgpid/keygen /usr/local/bin/keygen \ + && chmod 0755 /usr/local/bin/keygen \ + && /usr/local/bin/keygen --help >/dev/null \ + && rm -rf /root/.cache \ + && apt-get clean + +RUN npm install -g tiddlywiki sjcl-cli + +ARG IPFS_VERSION=0.16.0 + +RUN { OS="$(echo ${DOCKER_SYSTEM} |awk '{print tolower($0)}')"; \ + ARCH="$(echo ${DOCKER_MACHINE})"; \ + wget -qO - https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.${OS}.${ARCH}.tar.xz \ + |tar --strip-components 1 -C /usr/local/bin -xJf - shellcheck-stable/shellcheck; } \ + && { OS="$(echo ${DOCKER_SYSTEM} |awk '{print tolower($0)}')"; \ + ARCH="$(echo ${DOCKER_MACHINE} |awk '/x86_64/ {print "amd64"}; /aarch64/ {print "arm64"}')"; \ + wget -qO - https://github.com/ipfs/kubo/releases/download/v${IPFS_VERSION}/kubo_v${IPFS_VERSION}_${OS}-${ARCH}.tar.gz \ + |tar --strip-components 1 -C /usr/local/bin -xzf - kubo/ipfs; } \ + && mkdir -p /usr/local/lib/shellspec \ + && wget -qO - https://github.com/shellspec/shellspec/archive/refs/heads/master.tar.gz \ + |tar --strip-components 1 -C /usr/local/lib/shellspec -xzf - \ + && ln -s /usr/local/lib/shellspec/shellspec /usr/local/bin/shellspec + +ADD https://raw.github.com/kvz/cronlock/master/cronlock /usr/local/bin/cronlock +RUN chmod +rx /usr/local/bin/cronlock + +# config ssmtp +COPY templates/.ssmtprc /etc/ssmtp/ssmtp.conf +RUN chmod 600 /etc/ssmtp/ssmtp.conf + +EXPOSE 1234 12345 + +COPY install.sh /install.sh +COPY ${DOCKER_BUILD_DIR}/docker-entrypoint.sh /docker-entrypoint.sh +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["start"] + +FROM dist as master +ARG DOCKER_BUILD_DIR +ARG DOCKER_GID +ARG SHELL=/bin/bash +ARG UID +ARG USER +ENV UID=${UID} +ENV GID=${UID} +ENV USER=zen + +# If we provide a numeric UID +RUN [ "$UID" -eq "$UID" ] 2>/dev/null \ +# Remove user with $UID if it is not our $USER + && if [ "$(getent passwd $UID |awk -F: '{print $1}')" != "$USER" ]; then \ + sed -i '/^'$(getent passwd $UID |awk -F: '{print $1}')':x:'$UID':/d' /etc/passwd; \ + sed -i '/^'$(getent group $GID |awk -F: '{print $1}')':x:'$GID':/d' /etc/group; \ + fi \ +# Force $UID if our $USER already exists + && sed -i 's/^'$USER':x:[0-9]\+:[0-9]\+:/'$USER':x:'$UID':'$GID':/' /etc/passwd \ + && sed -i 's/^'$USER':x:[0-9]\+:/'$USER':x:'$GID':/' /etc/group \ +# Create $USER if it does not exist + && if [ "$(getent passwd $UID)" = "" ]; then \ + echo "$USER:x:$UID:$GID::/home/$USER:$SHELL" >> /etc/passwd; \ + echo "$USER:\!:$(($(date +%s) / 60 / 60 / 24)):0:99999:7:::" >> /etc/shadow; \ + echo "$USER:x:$GID:" >> /etc/group; \ + fi \ + && mkdir -p /home/$USER \ + && chown $UID:$GID /home/$USER \ + || true + +## sudo +RUN echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" > "/etc/sudoers.d/$USER" + +# config ssmtp +RUN echo "$USER:support@g1sms.fr:mail.asycn.io:587" >> /etc/ssmtp/revaliases + +# config crontab +RUN echo "SHELL=/bin/bash" > /var/spool/cron/crontabs/$USER \ + && echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /var/spool/cron/crontabs/$USER \ + && echo "12 20 * * * /bin/bash /home/zen/.zen/20h12.process.sh > /tmp/20h12.log 2>&1" >> /var/spool/cron/crontabs/$USER \ + && chown $USER /var/spool/cron/crontabs/$USER + +USER $USER +ENV SHELL=${SHELL} +WORKDIR /home/$USER + +RUN mkdir ~/.zen ~/.zen/tmp ~/astroport diff --git a/docker/docker-compose.app.yml b/docker/docker-compose.app.yml new file mode 100644 index 00000000..8a602fa5 --- /dev/null +++ b/docker/docker-compose.app.yml @@ -0,0 +1,20 @@ +version: '3.6' + +services: + docker: + environment: + - ENV=${ENV} + - SHELL=${DOCKER_SHELL} + image: ${DOCKER_REPOSITORY}/docker:${DOCKER_IMAGE_TAG} + labels: + - SERVICE_1234_CHECK_HTTP=/ + - SERVICE_1234_NAME=${COMPOSE_SERVICE_NAME}-docker-1234 + - SERVICE_1234_TAGS=${DOCKER_SERVICE_1234_TAGS} + +networks: + private: + external: true + name: ${DOCKER_NETWORK_PRIVATE} + public: + external: true + name: ${DOCKER_NETWORK_PUBLIC} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..fe1b0ae6 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.6' + +services: + docker: + build: + args: + - DOCKER_BUILD_DIR=docker + - GID=${GID} + - IPFS_VERSION=${IPFS_VERSION:-0.16.0} + - UID=${UID} + context: ../ + dockerfile: docker/Dockerfile + network_mode: host + restart: always + tty: true + user: ${UID}:${GID} + volumes: + - data:/home/zen/astroport:cached + - ipfs:/home/zen/.ipfs:cached,ro + - zen:/home/zen/.zen:delegated + working_dir: /home/zen/.zen + +volumes: + data: + ipfs: + driver: local + driver_opts: + type: none + device: ${HOME}/.ipfs + o: bind + zen: + driver: local + driver_opts: + type: none + device: ${HOME}/.zen + o: bind diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 00000000..dc5d60c3 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env sh +set -euo errexit + +# Print a debug message if debug mode is on ($DEBUG is not empty) +# @param message +debug_msg () +{ + if [ -n "${DEBUG:-}" -a "${DEBUG:-}" != "false" ]; then + echo "$@" + fi +} + +mkdir -p /home/zen/.zen/tmp +SOURCE_DIR="/home/zen/.zen/Astroport.ONE" +[ -d "$SOURCE_DIR" ] && cd "$SOURCE_DIR" && git pull -q || git clone -q https://git.p2p.legal/qo-op/Astroport.ONE.git "$SOURCE_DIR" +cd "$SOURCE_DIR" + +sudo -n /usr/sbin/cron -L/dev/stdout + +case "${1:-${cmd:-start}}" in + + start) + debug_msg "Starting $SOURCE_DIR/start.sh ..." + exec "$SOURCE_DIR"/start.sh + ;; + + install) + debug_msg "Installing..." + exec /install.sh + ;; + + *) + debug_msg "Exec: $@" + exec "$@" + ;; + +esac diff --git a/start.sh b/start.sh index f578e280..5348bf43 100755 --- a/start.sh +++ b/start.sh @@ -38,7 +38,7 @@ echo ## VERIFY SOFTWARE DEPENDENCIES [[ ! $(which ipfs) ]] && echo "EXIT. Vous devez avoir installé ipfs CLI sur votre ordinateur" && echo "https://dist.ipfs.io/#go-ipfs" && exit 1 -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); [[ ! $YOU ]] && echo "Lancez 'ipfs daemon' SVP sudo systemctl start ipfs" && exit 1 IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) diff --git a/tools/Connect_PLAYER_To_Gchange.sh b/tools/Connect_PLAYER_To_Gchange.sh index 8d456924..1e006d94 100755 --- a/tools/Connect_PLAYER_To_Gchange.sh +++ b/tools/Connect_PLAYER_To_Gchange.sh @@ -120,7 +120,7 @@ do ## GET FRIEND TW !! echo "Getting latest online TW..." - YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); + YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) echo "$LIBRA/ipns/$ASTRONAUTENS" echo "http://$myIP:8080/ipns/$ASTRONAUTENS ($YOU)" diff --git a/tools/FRIENDS.init.sh b/tools/FRIENDS.init.sh index ac79d2c9..0e3d1497 100755 --- a/tools/FRIENDS.init.sh +++ b/tools/FRIENDS.init.sh @@ -11,7 +11,7 @@ countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|gr [[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 0 start=`date +%s` -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1 +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1 G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) && [[ ! $G1PUB ]] && echo "ERREUR G1PUB. EXIT" && exit 1 IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) || ( echo "noipfsid" && exit 1 ) ######################################################################## diff --git a/tools/VISA.new.sh b/tools/VISA.new.sh index 55132a00..50792bed 100755 --- a/tools/VISA.new.sh +++ b/tools/VISA.new.sh @@ -16,7 +16,7 @@ PLAYER="$3" PSEUDO="$4" -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) MOATS=$(date -u +"%Y%m%d%H%M%S%4N") diff --git a/tools/ipfs_config.sh b/tools/ipfs_config.sh new file mode 100644 index 00000000..165e1a7d --- /dev/null +++ b/tools/ipfs_config.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +myIP=$(hostname -I | awk '{print $1}') +isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") + +########################################### +### IMPORTANT !!!!!!! IMPORTANT !!!!!! +########################################### +# DHT PUBSUB mode +ipfs config Pubsub.Router gossipsub + +# MAXSTORAGE = 1/2 available +availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}') +diskSize="$((availableDiskSize / 2))" +ipfs config Datastore.StorageMax $diskSize + +## Activate Rapid "ipfs p2p" +ipfs config --json Experimental.Libp2pStreamMounting true +ipfs config --json Experimental.P2pHttpProxy true + +ipfs config --json Swarm.ConnMgr.LowWater 20 +ipfs config --json Swarm.ConnMgr.HighWater 40 + +[[ ! $isLAN ]] && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'$myIP':8080", "http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' \ + || ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' + +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]' +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]' + +## For ipfs.js = https://github.com/ipfs/js-ipfs/blob/master/docs/DELEGATE_ROUTERS.md +ipfs config --json Addresses.Swarm | jq '. += ["/ip4/0.0.0.0/tcp/30215/ws"]' > /tmp/30215.ws +ipfs config --json Addresses.Swarm "$(cat /tmp/30215.ws)" + +ipfs config Addresses.API "/ip4/0.0.0.0/tcp/5001" +ipfs config Addresses.Gateway "/ip4/0.0.0.0/tcp/8080" + +######### CLEAN DEFAULT BOOTSTRAP ADD Astroport.ONE Officials ########### +ipfs bootstrap rm --all + +for bootnode in $(cat ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | grep -Ev "#") # remove comments + do + ipfsnodeid=${bootnode##*/} + ipfs bootstrap add $bootnode + done + diff --git a/tools/ipfs_setup.sh b/tools/ipfs_setup.sh index 8380c891..223e022c 100755 --- a/tools/ipfs_setup.sh +++ b/tools/ipfs_setup.sh @@ -24,7 +24,7 @@ err() { # CHECK node IP isLAN? myIP=$(hostname -I | awk '{print $1}') isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); MACHINE_TYPE=`uname -m` @@ -74,46 +74,7 @@ sudo systemctl enable ipfs ########################################### # ACTIVATE IPFS OPTIONS: #swarm0 INIT ########################################### -### IMPORTANT !!!!!!! IMPORTANT !!!!!! -########################################### -# DHT PUBSUB mode -ipfs config Pubsub.Router gossipsub - -# MAXSTORAGE = 1/2 available -availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}') -diskSize="$((availableDiskSize / 2))" -ipfs config Datastore.StorageMax $diskSize - -## Activate Rapid "ipfs p2p" -ipfs config --json Experimental.Libp2pStreamMounting true -ipfs config --json Experimental.P2pHttpProxy true - -ipfs config --json Swarm.ConnMgr.LowWater 20 -ipfs config --json Swarm.ConnMgr.HighWater 40 - -[[ ! $isLAN ]] && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'$myIP':8080", "http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' \ - || ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' - -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]' -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]' - -## For ipfs.js = https://github.com/ipfs/js-ipfs/blob/master/docs/DELEGATE_ROUTERS.md -ipfs config --json Addresses.Swarm | jq '. += ["/ip4/0.0.0.0/tcp/30215/ws"]' > /tmp/30215.ws -ipfs config --json Addresses.Swarm "$(cat /tmp/30215.ws)" - - -ipfs config Addresses.API "/ip4/0.0.0.0/tcp/5001" -ipfs config Addresses.Gateway "/ip4/0.0.0.0/tcp/8080" - -######### CLEAN DEFAULT BOOTSTRAP ADD Astroport.ONE Officials ########### -ipfs bootstrap rm --all - -for bootnode in $(cat ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | grep -Ev "#") # remove comments - do - ipfsnodeid=${bootnode##*/} - ipfs bootstrap add $bootnode - done - +~/.zen/Astroport.ONE/tools/ipfs_config.sh sudo systemctl restart ipfs ## Add ulimit "open files" (avoid ipfs hang) diff --git a/tools/new_file_in_astroport.sh b/tools/new_file_in_astroport.sh index 6e96a8b8..41110ffc 100755 --- a/tools/new_file_in_astroport.sh +++ b/tools/new_file_in_astroport.sh @@ -14,7 +14,7 @@ countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|gr [[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 0 start=`date +%s` -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) [[ ! $IPFSNODEID ]] && echo 'ERROR missing IPFS Node id !! IPFS is not responding !?' && exit 1 diff --git a/tools/new_mp3_in_astroport.sh b/tools/new_mp3_in_astroport.sh index eaba28ce..e14fd8da 100755 --- a/tools/new_mp3_in_astroport.sh +++ b/tools/new_mp3_in_astroport.sh @@ -9,7 +9,7 @@ MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); IPFSNODEID=$(ipfs id -f='\n') G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) # GET XZUID diff --git a/tools/vlc_webcam.sh b/tools/vlc_webcam.sh index 06c7d976..56683387 100755 --- a/tools/vlc_webcam.sh +++ b/tools/vlc_webcam.sh @@ -20,7 +20,7 @@ ASTRONAUTENS=$(ipfs key list -l | grep -w ${PLAYER} | cut -d ' ' -f1) [[ ! $ASTRONAUTENS ]] && echo "${PLAYER} CLEF IPNS INTROUVABLE - EXIT -" && exit 1 -YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); +YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) MOATS=$(date -u +"%Y%m%d%H%M%S%4N")