commit 4b0d8b80afbcbc8ba600373983a587dd8c172fc9 from: gonzalo date: Wed Nov 28 15:08:50 2018 UTC Add options, make it a bit smarter and nice. commit - e3e8e3f92743744c2c48fab355b6a13c73a5c49c commit + 4b0d8b80afbcbc8ba600373983a587dd8c172fc9 blob - 6a5172cb2110b51208cc249a3b1dc6c7dd35dcbb blob + e82d57b9b60f260632b5a15697f8b334f871fedb --- current +++ current @@ -4,9 +4,10 @@ #set -x ## Variables -export RELEASEPATH=/home/gonzalo/rel +export RELEASEPATH=/usr/rel export KERNELSPATH=/kernels export VERSION=64 +export REL=6.4 export MIRROR="http://fastly.cdn.openbsd.org/" ARCH=$(machine -a) @@ -14,23 +15,17 @@ HOST=$(hostname -s) YO=$(hostname) KERNEL=$(sysctl | grep -c kern.osversion=GENERIC.MP) PING=$(ping -c1 -w1 cisco.com | wc -l) -LOCK="/var/empty/current.lock" +LOCK="/tmp/current.lock" -## Check root -if test "$(whoami)" != root; then - doas "$0" "$@" - exit $? -fi - ## Check running if [ -e "${LOCK}" ]; then - printf "Already a current.sh running, look at .lock on /var/empty/\\n" + printf "Already a ${0##*/} running, look at .lock on /tmp\\n" exit 2 fi touch ${LOCK} -printf "[+] Current - OpenBSD\\n" +printf "[+] ${0##*/} - OpenBSD\\n" ## Check internet link if [ ! "${PING}" -lt "1" ]; then @@ -41,6 +36,14 @@ else exit 2 fi +check_root() +{ + if test "$(whoami)" != root; then + doas "$0" "$@" + exit $? + fi +} + ## Checks misc check_path() { @@ -103,6 +106,8 @@ force_new() { cd ${RELEASEPATH} || return + rm -rf "${RELEASEPATH}"/* + while [[ ! -f "${RELEASEPATH}"/SHA256 ]]; do printf "[+] Downloading SHA256 from ${MIRROR}\n\n" ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/SHA256 @@ -136,6 +141,7 @@ check_new() else printf "[+] No updates on mirror ${MIRROR}\\n" rm "${LOCK}" + exit 1 fi } @@ -154,10 +160,10 @@ check_sum() rm ${LOCK} exit 2 else - printf "\\n[+] Files OK, continue...\\n" + printf "\\n[+] Files OK based on SHA256.\\n" fi - rm -rf "${TMPFILE}" + rm "${TMPFILE}" } download_sets() @@ -169,7 +175,7 @@ download_sets() cd ${RELEASEPATH} || return printf "[+] Downloading from ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/\n\n" - + for set in "${kernels[@]}"; do ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/"${set}" done @@ -183,6 +189,38 @@ download_sets() done } +download_rel() +{ + set -A kernels 'bsd' 'bsd.rd' 'bsd.mp' + set -A sets 'comp' 'game' 'man' 'base' + set -A xsets 'xbase' 'xserv' 'xshare' 'xfont' + + cd ${RELEASEPATH} || return + + printf "[+] Downloading Release ${REL} from ${MIRROR}pub/OpenBSD/${REL}/${ARCH}/\n\n" + + cd ${RELEASEPATH} && + ftp -V ${MIRROR}pub/OpenBSD/${REL}/${ARCH}/SHA256 && \ + for set in "${kernels[@]}"; do + ftp -V ${MIRROR}pub/OpenBSD/${REL}/${ARCH}/"${set}" + done + + for set in "${sets[@]}"; do + ftp -V ${MIRROR}pub/OpenBSD/${REL}/${ARCH}/"${set}"${VERSION}.tgz + done + + for set in "${xsets[@]}"; do + ftp -V ${MIRROR}pub/OpenBSD/${REL}/${ARCH}/"${set}"${VERSION}.tgz + done + + check_sum + + rm "${LOCK}" + + exit 1 +} + + cp_files() { cd ${RELEASEPATH} || return @@ -213,25 +251,54 @@ firsttime() recordatorio() { printf "[+] All done!\\n" - rm -rf "${LOCK}" + rm "${LOCK}" exit } +checks() +{ + check_root + check_path + check_kernels_path + check_powerpc + check_rpi3 + check_alix +} + instalation() { download_sets check_sum check_mp check_kernel - cp_files + cp_files firsttime recordatorio } -check_path -check_kernels_path -check_powerpc -check_rpi3 -check_alix -force_new -check_new +usage() +{ + echo + echo "[+] Usage: ${0##*/} [-i][-F][-r][-f]" >&2 + echo + echo "[+] Options:" + echo " -i download and install last snapshot if is new" + echo " -F force download and install last snapshot" + echo " -r download the last release" + echo " -f install first time file (by default on -i and -F)" + echo + rm "${LOCK}" + exit 1 +} + +while getopts 'iFrf' arg; do + case ${arg} in + i) checks ; check_new ;; + F) checks ; force_new ;; + r) checks ; download_rel ;; + f) check_root ; firsttime ;; + *) usage ;; + esac +done + +usage