Commit Diff


commit - 781e7f5c98145efa9c4a76d36872db02b5bfca42
commit + 8754f60320a41bbc2dd90c3eda3c1b36899bdf7e
blob - /dev/null
blob + 6a5172cb2110b51208cc249a3b1dc6c7dd35dcbb (mode 755)
--- /dev/null
+++ current
@@ -0,0 +1,237 @@
+#!/bin/ksh
+
+## DEBUG
+#set -x
+
+## Variables
+export	RELEASEPATH=/home/gonzalo/rel
+export	KERNELSPATH=/kernels
+export	VERSION=64
+export	MIRROR="http://fastly.cdn.openbsd.org/"
+
+ARCH=$(machine -a)
+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"
+
+## 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"
+	exit 2
+fi
+
+touch ${LOCK}
+
+printf "[+] Current - OpenBSD\\n"
+
+## Check internet link
+if [ ! "${PING}" -lt "1" ]; then
+	printf "[+] Conexion OK.\\n"
+else
+	printf "[+] Verifica la conexion a internet.\\n"
+	rm "${LOCK}"
+	exit 2
+fi
+
+## Checks misc
+check_path()
+{
+	if [ ! -d "${RELEASEPATH}" ]; then
+		mkdir ${RELEASEPATH}
+	fi
+}
+
+check_kernels_path()
+{
+	if [ ! -d "${KERNELSPATH}" ]; then
+		mkdir ${KERNELSPATH}
+	fi
+}
+
+check_powerpc()
+{
+	if [ "${ARCH}" == "powerpc" ]; then
+		export ARCH=macppc
+	fi
+}
+
+check_rpi3()
+{
+	if [ "${ARCH}" == "aarch64" ]; then
+		export ARCH=arm64
+	fi
+}
+
+check_alix()
+{
+	if [ "${HOST}" == "alix" ]; then
+		export RELEASEPATH=/home/gonzalo/datos/rel
+	fi
+}
+
+check_mp()
+{
+	if [ "${KERNEL}" -eq 1 ]; then
+		cp bsd.mp bsd
+	fi
+}
+
+check_kernel()
+{
+	if [ ! -f /bsd ]; then
+		printf "*** WARNING no kernel on /bsd, rolling back ***\\n"
+
+		cp ${KERNELSPATH}/bsd /
+
+	elif [ ! -f /bsd ]; then
+		printf "[+] Last kernel was reinstalled\\n"
+		ls ${KERNELSPATH}/bsd
+	else
+		printf "[+] Kernel is OK...\\n"
+	fi
+}
+
+force_new()
+{
+	cd ${RELEASEPATH} || return
+
+	while [[ ! -f "${RELEASEPATH}"/SHA256 ]]; do
+		printf "[+] Downloading SHA256 from ${MIRROR}\n\n"
+		ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/SHA256
+		cp ${RELEASEPATH}/SHA256 ${RELEASEPATH}/SHA256.ultimo
+		printf "\\n[+] ${YO} is a new setup or ${RELEASEPATH} was wiped.\\n"
+		instalation
+	done
+}
+
+check_new()
+{
+	cd ${RELEASEPATH} || return
+
+	if [ -f "${RELEASEPATH}"/SHA256.ultimo ]; then
+		printf "[+] Downloading SHA256 from ${MIRROR}\n\n"
+		ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/SHA256
+		ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/SHA256.sig
+	fi
+
+	printf "\\n[+] Comparing SHA256 looking for updates..."
+
+	DIFF=$(diff -Nup ${RELEASEPATH}/SHA256 ${RELEASEPATH}/SHA256.ultimo | wc -l) || return
+
+	printf "\\n[+] Rename SHA256 to .ultimo for nexts updates..\\n"
+
+	cp ${RELEASEPATH}/SHA256 ${RELEASEPATH}/SHA256.ultimo
+
+	if [ "${DIFF}" -gt 1 ]; then
+		printf "[+] Starting upgrade...\\n"
+		instalation
+	else
+		printf "[+] No updates on mirror ${MIRROR}\\n"
+		rm "${LOCK}"
+	fi
+}
+
+check_sum()
+{
+	TMPFILE=`mktemp /tmp/SHA256.XXXXXXXXXX`
+
+	cd ${RELEASEPATH} || return
+
+	for i in *; do grep -e "($i)" ${RELEASEPATH}/SHA256 >> "${TMPFILE}" ; done;
+
+	CHECK=$(cksum -c -q "${TMPFILE}" | wc -l)
+
+	if [ "${CHECK}" -gt 0 ]; then
+		printf "\\n[+] Files are corrupted, please check.\\n"
+		rm ${LOCK}
+		exit 2
+	else
+		printf "\\n[+] Files OK, continue...\\n"
+	fi
+
+	rm -rf "${TMPFILE}"
+}
+
+download_sets()
+{
+	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 from ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/\n\n"
+	
+	for set in "${kernels[@]}"; do
+	ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/"${set}"
+	done
+
+	for set in "${sets[@]}"; do
+	ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/"${set}"${VERSION}.tgz
+	done
+
+	for set in "${xsets[@]}"; do
+	ftp -V ${MIRROR}pub/OpenBSD/snapshots/${ARCH}/"${set}"${VERSION}.tgz
+	done
+}
+
+cp_files()
+{
+	cd ${RELEASEPATH} || return
+	## maybe you have an old etcXX.tgz in there
+	rm -rf ./*etc*
+	##
+	mv /bsd ${KERNELSPATH}
+	cp bsd bsd.rd /
+	cp /sbin/reboot /sbin/oreboot
+
+	printf "[+] Installing files from sets...\\n"
+
+	for _f in [!b]*${VERSION}.tgz base${VERSION}.tgz; do tar -C / -xzphf "$_f" || break; done
+
+	printf "[+] Relinking kernel...\\n"
+
+	sha256 -h /var/db/kernel.SHA256 /bsd
+}
+
+firsttime()
+{
+	printf "[+] Setting up rc.firsttime...\\n"
+	echo 'cd /dev && sh MAKEDEV all' >>/etc/rc.firsttime
+	echo "/usr/sbin/fw_update -v" >>/etc/rc.firsttime
+	chmod +x /etc/rc.firsttime
+}
+
+recordatorio()
+{
+	printf "[+] All done!\\n"
+	rm -rf "${LOCK}"
+	exit
+}
+
+instalation()
+{
+	download_sets
+	check_sum
+	check_mp
+	check_kernel
+	cp_files  
+	firsttime
+	recordatorio
+}
+
+check_path
+check_kernels_path
+check_powerpc
+check_rpi3
+check_alix
+force_new
+check_new