ipfs-ubuntu-mirror/sync.run

79 lines
2.7 KiB
Plaintext
Raw Normal View History

2018-10-01 21:01:32 +00:00
#!/bin/bash
#
# Copyright (C) 2018 JaquerEspeis
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Make a full sync of an Ubuntu mirror.
# This currently requires more than 1TB of storage space and takes a long time.
sleep 1 # prevent cpu spike on looping
2018-10-01 22:12:11 +00:00
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
2018-10-01 21:20:50 +00:00
2018-10-01 21:01:32 +00:00
chpst -u ipfs /bin/bash << '__EOF__'
export IPFS=/usr/local/bin/ipfs
export HOME=/home/ipfs
export IPFS_FD_MAX=4096
$IPFS config --json Experimental.FilestoreEnabled true
# Two stage sync of the main Ubuntu mirror.
# More info and options in https://wiki.ubuntu.com/Mirrors/Scripts.
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 \
2018-10-01 22:12:11 +00:00
rsync://archive.ubuntu.com/ubuntu "$MIRROR_DIR"
2018-10-01 21:01:32 +00:00
echo "Adding the mirror files to IPFS."
2018-10-01 22:12:11 +00:00
hash="$(
$IPFS add --progress --local --nocopy --fscache --quieter
--recursive "$MIRROR_DIR" | tail -n1)"
2018-10-01 21:01:32 +00:00
echo "Published IPFS hash ${hash}."
2018-10-01 22:12:11 +00:00
echo "Updating IPNS."
ipns="$($IPFS name publish "${hash}" | cut -d ' ' -f 3 | tr -d ':')"
# FIXME(sneak) use debmirror to improve this in the future
2018-10-01 21:01:32 +00:00
echo "Synchronizing with the main Ubuntu mirror, stage 2."
2018-10-01 22:12:11 +00:00
rsync --recursive --times --links --safe-links --hard-links --stats \
--delete --delete-after -v \
2018-10-01 21:01:32 +00:00
rsync://archive.ubuntu.com/ubuntu \
2018-10-01 22:12:11 +00:00
"$MIRROR_DIR"
2018-10-01 21:01:32 +00:00
# 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."
2018-10-01 22:12:11 +00:00
hash="$($IPFS add --progress --local --nocopy --fscache --quieter
--recursive "$MIRROR_DIR" | tail -n1)"
2018-10-01 21:01:32 +00:00
echo "Published IPFS hash ${hash}."
echo "Updating IPNS."
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."
2018-10-01 22:12:11 +00:00
__EOF__
sleep 3600 # wait 1h before syncing again