#!/usr/bin/env sh

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[39m' # No Color

die() {
    echo -e '[ '"${RED}$1${NC}"' ]'
    exit 1
}

warning() {
    echo -e '[ '"${YELLOW}$1${NC}"' ]'
}

notify() {
    echo -e '[ '"${BLUE}$1${NC}"' ]'
}

success() {
    echo -e '[ '"${GREEN}$1${NC}"' ]'
}

warning "Starting at $(date -u)"

find overlay/ -type f -name .gitkeep -delete

LC_ALL=C.UTF-8 rsync -acxv --no-times --delete-after --exclude '*-opkg' -e "ssh -p ${OPENWRT_SSH_PORT:-22}" overlay/ "${OPENWRT_SSH_HOST:-root@192.168.0.1}:/overlay/upper/" || die "Couldn't rsync config"

success "Done at $(date -u)"
