Using bash script to establish local update source for Manjaro

Posted by gclx on Sun, 27 Feb 2022 05:38:21 +0100

As a school with insufficient funds, the infrastructure of our school is relatively backward. There are more than 100 machines in the computer room for students, but the total bandwidth of the Internet is still only 10Mb. Some students saw that I was using Manjaro and were interested in learning Manjaro, but found that the installation of software in the computer room was too slow and wanted to establish a local source with me. Let's do it without saying a word.

At present, China University of science and technology has done a lot in the field of domestic open source server. All major distributions support rsync direct synchronization, and its links refer to

Open source software image of University of science and technology of China

1. Install server
Install a server on the teacher network, or directly install it with raspberry pie + 512GB card.
Note that if the memory card is small, you can buy a mobile hard disk or 512GB card for expansion.

2. Download script
Download the script here https://gitlab.manjaro.org/tools/maintenance-tools/boxit/-/tree/master

3. Modify script
Modify the above script slightly according to your own situation:

#!/bin/bash
HOME="/media/pi/mirror"
TARGET="${HOME}/manjaro"
TMP="${HOME}/.tmp/manjaro"
LOCK="/tmp/rsync-manjaro-stable.lock"

# NOTE: You'll probably want to change this or remove the --bwlimit setting in
# the rsync call below
BWLIMIT=100000

SOURCE="rsync://rsync.mirrors.ustc.edu.cn/repo/manjaro"

[ ! -d "${TARGET}" ] && mkdir -p "${TARGET}"
[ ! -d "${TMP}" ] && mkdir -p "${TMP}"

exec 9>"${LOCK}"
flock -n 9 || exit

## if we are called without a tty (cronjob) only run when there are changes
#if ! tty -s && diff -b <(curl -s "${STATE}") "${TARGET}/state" >/dev/null; then
#	exit 0
#fi

if ! stty &>/dev/null; then
    QUIET="-q"
fi
rsync -rtlvH --safe-links \
    --bwlimit=${BWLIMIT} \
    --delete-after --progress \
    -h ${QUIET} --timeout=600 --contimeout=120 -p \
    --no-motd \
    --temp-dir="${TMP}" \
   ${SOURCE} \
    "${TARGET}"

#ArchlinuxCN---------------------------------------

TARGET="${HOME}/archlinuxcn"
TMP="${HOME}/.tmp/archlinuxcn"
LOCK="/tmp/rsync_archlinuxcn.lock"

SOURCE="rsync://rsync.mirrors.ustc.edu.cn/repo/archlinuxcn"

[ ! -d "${TARGET}" ] && mkdir -p "${TARGET}"
[ ! -d "${TMP}" ] && mkdir -p "${TMP}"

exec 9>"${LOCK}"
flock -n 9 || exit

## if we are called without a tty (cronjob) only run when there are changes
#if ! tty -s && diff -b <(curl -s "${STATE}") "${TARGET}/state" >/dev/null; then
#	exit 0
#fi

if ! stty &>/dev/null; then
    QUIET="-q"
fi

# sleep $((RANDOM%60))

# excluded fh 2019-12-18
rsync -rtlvH --safe-links \
    --bwlimit=${BWLIMIT} \
    --delete-after --progress \
    -h ${QUIET} --timeout=600 --contimeout=120 -p \
    --no-motd \
    --temp-dir="${TMP}" \
   ${SOURCE} \
    "${TARGET}"

Save as / media / pi / mirror / syn sh
Pay attention to the corresponding permissions given to the current user of the mirror folder. The synchronization of Manjaro and ArchlinuxCN requires at least 256GB of space.

4. Configure automatic scripts
Edit crontab

$ crontab -e
#Add 1:20 every day at the bottom to start synchronization
20 01 * * 0,1,2,3,4,5,6 /media/pi/mirror/syn.sh

5. Open cron service

$ /lib/systemd/systemd-sysv-install enable cron

6. Configure computer room Web Service
Install apache2 and set / media/pi/mirror to http://192.168.1.2/mirror

At this point, the source server is installed.

After installing the client in the standby room, you can set the source locally. pacman is so fast! The only regret is that the AUR is too large and there are too many dependencies to move completely. But it's not necessary.

According to similar principles, we can set the local source of debain and Ubuntu. Thanks again to the first-class university USTC for its contribution to open source.

Topics: bash server