#!/bin/bash

function execute_download() {
  declare file_url="$1" file_sha256sum="$2" file_path="$3"

  echo "[installer] download ${file_url}"
  wget "${file_url}" -O "${file_path}" || exit 255
  chmod +x "${file_path}" || exit 255

  echo "${file_sha256sum} ${file_path}" | sha256sum -c - >/dev/null 2>&1
  if [[ $? -ne 0 ]]; then
    echo >&2 "Checksum verification failed for ${file_path}."
    exit 255
  fi

}

execute_download \
  'https://raw.githubusercontent.com/novln/Kiss-my-Arch/master/bootstrap/vbox-install/bootstrap' \
  '2416a9a78838db68e2b5914ca9ae1c086ef56eab8b868cd513f8af88d20afe25' \
  '/usr/local/sbin/arch-bootstrap'

execute_download \
  'https://raw.githubusercontent.com/novln/Kiss-my-Arch/master/bootstrap/vbox-install/configure' \
  'f55f69e3cfb4fafd64f54e45a371eba9d9ba7bca1051305638e22f721f1276b9' \
  '/usr/local/sbin/arch-configure'

timedatectl set-ntp true || exit 253
/usr/local/sbin/arch-bootstrap || exit 254

exit 0