#!/usr/bin/env bash

# https://liquorix.net
# apt install -y apt-transport-https

#codename="$(find /etc/apt -type f -name '*.list' | xargs grep -E '^deb' | awk '{print $3}' | grep -Eo '^[a-z]+' | sort | uniq -c | sort -n | tail -n1 | grep -Eo '[a-z]+$')"

# codename:
# https://liquorix.net/debian/dists/
#[DIR]	bullseye/	2020-02-15 14:04 	- 	 
#[DIR]	buster/		2020-02-15 14:04 	- 	 
#[DIR]	oldstable/	2020-02-15 14:04 	- 	 
#[DIR]	sid/		2020-02-15 14:04 	- 	 
#[DIR]	stable/		2020-02-15 14:04 	- 	 
#[DIR]	stretch/	2020-02-15 14:04 	- 	 
#[DIR]	testing/	2020-02-15 14:04 	- 	 
#[DIR]	unstable/	2020-02-15 14:04 	- 	 

# stable   == buster
# testing  == bullseye
# unstable == sid
codename=testing

ln -sf /etc/apt/sources.list-available/liquorix.list /etc/apt/sources.list.d/liquorix.list


apt-get update && apt-get install -y --no-install-recommends \
	curl gpg ca-certificates


KEY_DIR=/etc/apt/keyrings
mkdir -p ${KEY_DIR}

keyring_url='https://liquorix.net/liquorix-keyring.gpg'
keyring_path="${KEY_DIR}/liquorix-keyring.gpg"

curl "$keyring_url" | gpg --batch --yes --output "$keyring_path" --dearmor

apt-get install apt-transport-https lsb-release -y

cat > /etc/apt/sources.list-available/liquorix.list <<EOF
# curl "$keyring_url" | gpg --batch --yes --output "$keyring_path" --dearmor


deb [arch=$ARCH signed-by=${keyring_path}] https://liquorix.net/debian $codename main
deb-src [arch=$ARCH signed-by=${keyring_path}] http://liquorix.net/debian $codename main

# deb [arch=$ARCH signed-by=${keyring_path}] http://mirror.unit193.net/liquorix $codename main
# deb-src [arch=$ARCH signed-by=${keyring_path}] http://mirror.unit193.net/liquorix $codename main"
EOF

apt-get update -y

apt-get install -y linux-image-liquorix-amd64 linux-headers-liquorix-amd64
