#!/usr/bin/env bash ##### # # +===================================================+ # | © 2020 Privex Inc. | # | https://www.privex.io | # +===================================================+ # | | # | Ubuntu Light Mirror Script | # | | # | Core Developer(s): | # | | # | (+) Chris (@someguy123) [Privex] | # | | # +===================================================+ # ##### #### # Use colors, but only if connected to a terminal, and that terminal # supports them. #### if which tput >/dev/null 2>&1; then ncolors=$(tput colors); fi RED="" GREEN="" YELLOW="" BLUE="" BOLD="" NORMAL="" RESET="" if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then RED="$(tput setaf 1)" GREEN="$(tput setaf 2)" YELLOW="$(tput setaf 3)" BLUE="$(tput setaf 4)" BOLD="$(tput bold)" NORMAL="$(tput sgr0)" RESET="$(tput sgr0)" fi # If RESET_OWNER is 1, will run `chmod -R "$NEW_OWNER" folder` after each sync : ${RESET_OWNER=1} : ${NEW_OWNER="www-data:www-data"} : ${FSVERBOSE=0} : ${REPO_OUT="/filesrv/web/mirrors/alpine"} EXCLUDES=( "*/aarch64/*" "*/armhf/*" "*/armv7/*" "*/ppc64le/*" "*/s390x/*" ) RS_ARGS=("--delete") RS_EXCL=() for x in "${EXCLUDES[@]}"; do RS_EXCL+=("--exclude" "$x") done #### # If you specify the parameter `-v` then that will enable verbose mode # and change rsync to display full details during the sync #### if [[ "$#" -gt 0 && "$1" == "-v" ]]; then RS_ARGS+=('-avh' '--progress') FSVERBOSE=1 else RS_ARGS+=('-aq') fi r-excl() { rsync "${RS_EXCL[@]}" "${RS_ARGS[@]}" "$@" } r-norm() { rsync "${RS_ARGS[@]}" "$@" } : ${SRC_REPO="rsync://uk.alpinelinux.org/alpine"} #[[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n---------\n${GREEN}${BOLD}Syncing ${SRC_REPO}/v3.10 into ${REPO_OUT}/v3.10 ... ${RESET}\n---------\n" #r-excl "${SRC_REPO}/v3.10/" "${REP_OUT}/v3.10/" ALP_VERS=('v3.10') [[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n---------\n${GREEN}${BOLD}Syncing alpine versions: ${ALP_VERS[*]} ... ${RESET}\n---------\n" for clr in "${ALP_VERS[@]}"; do [[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n${GREEN}${BOLD} >>> Syncing ${SRC_REPO}/${clr}/ into ${REPO_OUT}/${clr}/ ... ${RESET}\n\n" r-excl -L "${SRC_REPO}/${clr}/" "${REPO_OUT}/${clr}/" done #[[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n---------\n${GREEN}${BOLD}Syncing Ubuntu daily desktop + server releases ... ${RESET}\n---------\n" #r-excl "${SRC_CDIMG}/ubuntu-server/daily/" "${ISO_OUT}/ubuntu-daily/server/" #r-excl "${SRC_CDIMG}/ubuntu/daily-live/" "${ISO_OUT}/ubuntu-daily/desktop/" if [[ "$RESET_OWNER" -eq 1 && "$EUID" -eq 0 ]]; then [[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n${GREEN}${BOLD} >>> Resetting owner to '$NEW_OWNER' for all files in $ISO_OUT ... ${RESET}\n\n" chown -R "$NEW_OWNER" "$REPO_OUT" fi