Last active
September 16, 2019 02:54
-
-
Save vinyanalista/ed031071151d00c5af4d6bdd49374680 to your computer and use it in GitHub Desktop.
Mirroring an Open Build Service repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOCAL_FOLDER='/srv/pub/kamarada/15.1/' | |
DOWNLOADOO_PATH='https://download.opensuse.org/repositories/home:/kamarada:/15.1/' | |
# Only run as root | |
USERNAME=$(whoami) | |
THIS_SCRIPT=$(realpath "$0") | |
if [[ $UID -gt 0 ]] ; then | |
sudo sh $THIS_SCRIPT | |
exit | |
fi | |
# Ensure that paths end in slash | |
[[ $LOCAL_FOLDER != */ ]] && LOCAL_FOLDER="$LOCAL_FOLDER"/ | |
[[ $DOWNLOADOO_PATH != */ ]] && DOWNLOADOO_PATH="$DOWNLOADOO_PATH"/ | |
# Compute skip paths | |
SKIP_PATHS=`echo $DOWNLOADOO_PATH | tr -cd '/' | wc -c` | |
SKIP_PATHS=`expr $SKIP_PATHS - 3` | |
# There are 3 slashes in "https://download.opensuse.org/" | |
# Download everything from OBS | |
cd $LOCAL_FOLDER | |
wget -m -nH --cut-dirs=$SKIP_PATHS -np --reject 'index.*,*.meta4,*.metalink,*.mirrorlist' -e robots=off $DOWNLOADOO_PATH | |
LOCAL_FILES=`find -type f -printf '%P\n'` | |
# For each file stored locally | |
for LOCAL_FILE in $LOCAL_FILES ; do | |
# Check whether the file exists online | |
HTTP_STATUS=`curl -o /dev/null --silent --head --write-out '%{http_code}\n' "$DOWNLOADOO_PATH$LOCAL_FILE"` | |
# If it does not exist online, delete it | |
[[ $HTTP_STATUS == 404 ]] && rm $LOCAL_FILE | |
done | |
# .repo file needs to be deleted, otherwise local mirror redirects to download.opensuse.org | |
find . -name "*.repo" -type f -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment