From 4ef62b87dbabcca07feff307a4387d719c445676 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Mon, 1 Oct 2018 15:12:11 -0700 Subject: [PATCH] change dirs --- README.md | 6 +++--- ipfsd.run | 8 +++++--- sync.run | 30 +++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6067c08..53a52a8 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ based on sync_mirror.sh from JáquerEspeis or -(image uses /mirror /and /home/ipfs/.ipfs) +(image uses /var/lib/ubuntumirror and /var/lib/ipfs) ``` docker run \ - -v /host/dir/path/to/mirror:/mirror \ - -v /host/dir/path/to/ipfsrepo:/home/ipfs/.ipfs \ + -v /host/dir/path/to/mirror:/var/lib/ubuntumirror \ + -v /host/dir/path/to/ipfsrepo:/var/lib/ipfs \ -d sneak/ipfs-ubuntu-mirror ``` diff --git a/ipfsd.run b/ipfsd.run index 56a0aa2..74338a0 100644 --- a/ipfsd.run +++ b/ipfsd.run @@ -4,12 +4,14 @@ sleep 1 # prevent cpu spike on looping export IPFS="/usr/local/bin/ipfs" export HOME="/home/ipfs" - chown ipfs:ipfs $HOME - cd $HOME -if [[ ! -d $HOME/.ipfs ]]; then +export IPFS_DIR=/var/lib/ipfs + +if [[ ! -d $IPFS_DIR ]]; then + mkdir -p $IPFS_DIR + chown ipfs:ipfs $IPFS_DIR chpst -u ipfs $IPFS init fi diff --git a/sync.run b/sync.run index 0989307..08876fb 100644 --- a/sync.run +++ b/sync.run @@ -19,15 +19,20 @@ sleep 1 # prevent cpu spike on looping -chown ipfs:ipfs /mirror +export MIRROR_DIR=/var/lib/ubuntumirror +export IPFS_DIR=/var/lib/ipfs + + +if [[ ! -d $MIRROR_DIR ]]; then + mkdir -p $MIRROR_DIR + chown ipfs:ipfs $MIRROR_DIR +fi chpst -u ipfs /bin/bash << '__EOF__' export IPFS=/usr/local/bin/ipfs export HOME=/home/ipfs -export MIRRORDIR=/mirror export IPFS_FD_MAX=4096 -mkdir -p "$MIRRORDIR" $IPFS config --json Experimental.FilestoreEnabled true @@ -37,23 +42,30 @@ echo "Synchronizing with the main Ubuntu mirror, stage 1." rsync --recursive --times --links --safe-links --hard-links --stats \ --exclude "Packages*" --exclude "Sources*" --exclude "Release*" \ --exclude "InRelease" -v \ - rsync://archive.ubuntu.com/ubuntu "$MIRRORDIR" + rsync://archive.ubuntu.com/ubuntu "$MIRROR_DIR" echo "Adding the mirror files to IPFS." -hash="$($IPFS add --progress --local --nocopy --fscache --quieter --recursive "$MIRRORDIR" | tail -n1)" +hash="$( + $IPFS add --progress --local --nocopy --fscache --quieter + --recursive "$MIRROR_DIR" | tail -n1)" echo "Published IPFS hash ${hash}." +echo "Updating IPNS." +ipns="$($IPFS name publish "${hash}" | cut -d ' ' -f 3 | tr -d ':')" + +# FIXME(sneak) use debmirror to improve this in the future echo "Synchronizing with the main Ubuntu mirror, stage 2." -rsync --recursive --times --links --safe-links --hard-links --stats \ +rsync --recursive --times --links --safe-links --hard-links --stats \ --delete --delete-after -v \ rsync://archive.ubuntu.com/ubuntu \ - "$HOME/mirror" + "$MIRROR_DIR" # Publish the files on IPFS. # This uses the experimental filestore: # https://github.com/ipfs/go-ipfs/issues/3397#issuecomment-284337564 echo "Adding the mirror files to IPFS." -hash="$($IPFS add --progress --local --nocopy --fscache --quieter --recursive "$MIRRORDIR" | tail -n1)" +hash="$($IPFS add --progress --local --nocopy --fscache --quieter +--recursive "$MIRROR_DIR" | tail -n1)" echo "Published IPFS hash ${hash}." echo "Updating IPNS." @@ -61,6 +73,6 @@ ipns="$($IPFS name publish "${hash}" | cut -d ' ' -f 3 | tr -d ':')" echo "IPFS Mirror synchronized." echo "Add the address 'ipfs:/ipns/${ipns}' to your '/etc/apt/sources.list'." echo "For example, add 'deb ipfs:/ipns/${ipns} xenial main' if you are in Ubuntu 16.04, and you want to use IPFS to get updates from the main archive." +__EOF__ sleep 3600 # wait 1h before syncing again -__EOF__