#!/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} : ${ISO_OUT="/filesrv/web/images/iso"} EXCLUDES=( "*-ppc64*" "*-s390x*" "*-powerpc*" "*-armhf*" "*-azure*" ) 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_REL="rsync://se.releases.ubuntu.com/ubuntu-releases"} : ${SRC_REL="rsync://no.mirrors.blix.com/ubuntu-releases"} : ${SRC_CLOUD="rsync://cloud-images.ubuntu.com/cloud-images"} : ${SRC_CDIMG="rsync://cdimage.ubuntu.com/cdimage"} [[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n---------\n${GREEN}${BOLD}Syncing $SRC_REL into ${ISO_OUT}/ubuntu/ ... ${RESET}\n---------\n" r-norm "${SRC_REL}/" "${ISO_OUT}/ubuntu/" CLOUD_RELS=('xenial' 'bionic' 'focal') [[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n---------\n${GREEN}${BOLD}Syncing Ubuntu cloud images: ${CLOUD_RELS[*]} ... ${RESET}\n---------\n" for clr in "${CLOUD_RELS[@]}"; do [[ "$FSVERBOSE" -eq 1 ]] && echo -e "\n${GREEN}${BOLD} >>> Syncing ${SRC_CLOUD}/${clr}/current into ${ISO_OUT}/ubuntu-cloud/${clr}/ ... ${RESET}\n\n" r-excl -L "${SRC_CLOUD}/${clr}/current" "${ISO_OUT}/ubuntu-cloud/${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" "$ISO_OUT" fi