ipfs-ubuntu-mirror/sync.run

82 lines
2.5 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.
2018-10-02 01:34:41 +00:00
sleep 60 # prevent cpu spike on looping
2018-10-01 22:12:11 +00:00
export MIRROR_DIR=/var/lib/ubuntumirror
2018-10-01 22:27:41 +00:00
export IPFS_PATH=/var/lib/ipfs
2018-10-01 22:12:11 +00:00
if [[ ! -d $MIRROR_DIR ]]; then
mkdir -p $MIRROR_DIR
fi
chown ipfs:ipfs $MIRROR_DIR
2018-10-01 21:20:50 +00:00
2018-10-02 01:34:41 +00:00
export GNUPGHOME=/etc/debmirror/gnupg
if [[ ! -d $GNUPGHOME ]]; then
mkdir -p $GNUPGHOME
2018-10-02 01:27:19 +00:00
fi
chown ipfs:ipfs $GNUPGHOME
2018-10-02 01:27:19 +00:00
2018-10-01 21:01:32 +00:00
chpst -u ipfs /bin/bash << '__EOF__'
export IPFS=/usr/local/bin/ipfs
export HOME=/var/lib/ipfs
2018-10-01 21:01:32 +00:00
export IPFS_FD_MAX=4096
2018-10-02 01:34:41 +00:00
gpg --no-default-keyring --keyring $GNUPGHOME/trustedkeys.kbx --import \
/usr/share/keyrings/ubuntu*.gpg
2018-10-02 01:27:19 +00:00
2018-10-01 21:01:32 +00:00
$IPFS config --json Experimental.FilestoreEnabled true
2018-10-01 23:32:00 +00:00
echo "Synchronizing with the main Ubuntu mirror."
2018-10-01 22:12:11 +00:00
set -x # error out if the sync fails
2018-10-01 23:32:00 +00:00
debmirror \
2018-10-02 01:27:19 +00:00
--keyring $GNUPGHOME/trustedkeys.kbx \
2018-10-01 23:32:00 +00:00
-a ${MIRROR_ARCHITECTURES:-amd64} \
--no-source \
-s ${MIRROR_CATEGORIES:-main,universe,multiverse,restricted} \
-h ${UBUNTU_MIRROR_SOURCE:-archive.ubuntu.com} \
-d ${UBUNTU_MIRROR_PROJECTS:-xenial,xenial-updates,xenial-security,xenial-backports,bionic,bionic-updates,bionic-security,bionic-backports} \
--ignore-small-errors \
-r ${UBUNTU_MIRROR_PATH:-/ubuntu} \
--progress \
--method=http \
$MIRROR_DIR
2018-10-01 21:01:32 +00:00
set +x # resume ignoring errors
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
2018-10-01 23:32:00 +00:00
2018-10-01 21:01:32 +00:00
echo "Adding the mirror files to IPFS."
HASH="$($IPFS add --progress --local --nocopy --fscache --quieter --recursive "$MIRROR_DIR" | tail -n1)"
echo "Published (added/pinned) /ipfs/${HASH}."
2018-10-01 21:01:32 +00:00
echo "Updating IPNS."
IPNS="$($IPFS name publish "${HASH}" | cut -d ' ' -f 3 | tr -d ':')"
2018-10-01 21:01:32 +00:00
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'"
2018-10-01 22:12:11 +00:00
__EOF__
sleep 3600 # wait 1h before syncing again