diff --git a/.gitignore b/.gitignore index 73815bd..4c4313f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# sorry but I don't need my network config public +setup/network.toml +# also other config contains like access tokens so just hide everything +setup/ + # rust/cargo /target/ diff --git a/setup/autostart.toml b/setup/autostart.toml deleted file mode 100644 index d7eb4c1..0000000 --- a/setup/autostart.toml +++ /dev/null @@ -1,4 +0,0 @@ -# setup an autostarting kiosk that runs a webpage in a browser -[kiosk] -page = "https://time.is" -user = "kiosk" diff --git a/setup/network.toml b/setup/network.toml deleted file mode 100644 index 64c4d14..0000000 --- a/setup/network.toml +++ /dev/null @@ -1,8 +0,0 @@ -# enable connecting the raspberry pi into your tailscale network -tailscale = true - -# add a wifi network -[[wifi]] -ssid = "eduroam" -security = "WPA-PSK" -password = "yoursupersecretpassword" diff --git a/setup/os.toml b/setup/os.toml deleted file mode 100644 index 4394c7c..0000000 --- a/setup/os.toml +++ /dev/null @@ -1,33 +0,0 @@ -[alpine] -# the alpine version. I recommend always using the latest available -branch = "v3.17" - -# aarch64 is required if you want to run some software like a browser -arch = "aarch64" - -# unless you have a local mirror that you know will be fast, just leave this empty -mirror = "https://ftp.halifax.rwth-aachen.de/alpine" - -# here you can add some extra repositories and their signing keys -extra_repos = [] -extra_keys = [] - -[host] -# set your local keyboard layout -keymap = "de" -keymap_variant = "de-dvorak" - -# create a user for you to log in -[[user]] -name = "msrd0" -password = "changeme" -sudo = true -authorized_keys = [ - # add your ssh key(s) here -] - -# create a user for the autostarting kiosk -[[user]] -name = "kiosk" -password = "changeme" -groups = ["audio", "cdrom", "dialout", "floppy", "input", "uucp", "video"] diff --git a/setup/packages.toml b/setup/packages.toml deleted file mode 100644 index 80f27a2..0000000 --- a/setup/packages.toml +++ /dev/null @@ -1,7 +0,0 @@ -# install some extra alpine packages -install = [ - "emacs-nox", "tmux", -] - -# add openrc units to autostart -autostart = [] diff --git a/src/setup/autostart.rs b/src/setup/autostart.rs deleted file mode 100644 index af1f77a..0000000 --- a/src/setup/autostart.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Autostart { - pub kiosk: Kiosk -} - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Kiosk { - pub page: String, - pub user: String -} diff --git a/src/setup/mod.rs b/src/setup/mod.rs deleted file mode 100644 index 0d3bb45..0000000 --- a/src/setup/mod.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! This module contains definitions to read the setup files. -use anyhow::Context as _; -use serde::de::DeserializeOwned; -use std::{ - fs, - path::{Path, PathBuf} -}; - -pub mod autostart; -pub mod network; -pub mod os; -pub mod packages; - -use autostart::Autostart; -use network::Network; -use os::Os; -use packages::Packages; - -pub struct Setup { - pub os: Os, - pub network: Network, - pub packages: Packages, - pub autostart: Autostart -} - -impl Setup { - fn read(path: &Path, file: &str) -> anyhow::Result { - toml::from_slice(&fs::read(path.join(file)).with_context(|| format!("Failed to read {file}"))?) - .with_context(|| format!("Failed to deserialize {file}")) - } - - pub fn load() -> anyhow::Result { - let path = PathBuf::from("setup"); - let os = Self::read(&path, "os.toml")?; - let network = Self::read(&path, "network.toml")?; - let packages = Self::read(&path, "packages.toml")?; - let autostart = Self::read(&path, "autostart.toml")?; - Ok(Self { - os, - network, - packages, - autostart - }) - } -} diff --git a/src/setup/network.rs b/src/setup/network.rs deleted file mode 100644 index 605027c..0000000 --- a/src/setup/network.rs +++ /dev/null @@ -1,33 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Network { - #[serde(default)] - pub tailscale: bool, - - #[serde(default)] - pub wifi: Vec -} - -#[derive(Deserialize)] -//#[serde(deny_unknown_fields)] -pub struct Wifi { - pub ssid: String, - - #[serde(flatten)] - pub security: WifiSecurity -} - -#[derive(Deserialize)] -#[serde(tag = "security")] -pub enum WifiSecurity { - #[serde(rename = "none")] - None, - - #[serde(rename = "WPA-PSK")] - WpaPsk { password: String }, - - #[serde(rename = "WPA-EAP")] - WpaEap { identity: String, password: String } -} diff --git a/src/setup/os.rs b/src/setup/os.rs deleted file mode 100644 index 6ada02b..0000000 --- a/src/setup/os.rs +++ /dev/null @@ -1,216 +0,0 @@ -use serde::{ - de::{self, Deserializer, Visitor}, - Deserialize -}; -use std::{ - borrow::Cow, - fmt::{self, Display, Formatter} -}; - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Os { - pub alpine: Alpine, - pub rpi: Rpi, - pub host: Host, - pub user: Vec -} - -pub enum Branch { - Edge, - Version(String) -} - -impl Branch { - pub fn git_branch(&self) -> Cow<'static, str> { - match self { - Self::Edge => "master".into(), - Self::Version(v) => format!("{v}-stable").into() - } - } -} - -impl Default for Branch { - fn default() -> Self { - Self::Version("3.17".into()) - } -} - -impl<'de> Deserialize<'de> for Branch { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de> - { - struct BranchVisitor; - - impl<'de> Visitor<'de> for BranchVisitor { - type Value = Branch; - - fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "the alpine branch, either edge or a version like v3.17") - } - - fn visit_str(self, v: &str) -> Result - where - E: de::Error - { - if let Some(version) = v.strip_prefix('v') { - Ok(Branch::Version(version.to_owned())) - } else if v == "edge" { - Ok(Branch::Edge) - } else { - Err(E::custom("Invalid branch, expected either edge or a version like v3.17")) - } - } - } - - deserializer.deserialize_str(BranchVisitor) - } -} - -impl Display for Branch { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - Self::Version(v) => write!(f, "v{v}"), - Self::Edge => write!(f, "edge") - } - } -} - -#[derive(Default, Deserialize)] -#[serde(rename_all = "lowercase")] -pub enum Arch { - ArmHf, - #[default] - ArmV7, - Aarch64 -} - -impl Arch { - pub fn cbuild(&self) -> &'static str { - match self { - Self::ArmHf => "armv6-alpine-linux-musleabihf", - Self::ArmV7 => "armv7-alpine-linux-musleabihf", - Self::Aarch64 => "aarch64-alpine-linux-musl" - } - } - - pub fn to_str(&self) -> &'static str { - match self { - Self::ArmHf => "armhf", - Self::ArmV7 => "armv7", - Self::Aarch64 => "aarch64" - } - } - - pub fn is64bit(&self) -> bool { - matches!(self, Self::Aarch64) - } -} - -impl Display for Arch { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.write_str(self.to_str()) - } -} - -fn default_mirror() -> String { - "https://dl-cdn.alpinelinux.org/alpine".into() -} - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Alpine { - #[serde(default)] - pub branch: Branch, - - #[serde(default)] - pub arch: Arch, - - #[serde(default = "default_mirror")] - pub mirror: String, - - #[serde(default)] - pub extra_repos: Vec, - - #[serde(default)] - pub extra_keys: Vec -} - -fn default_cmdline() -> String { - "dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait"; - "modules=loop,squashfs,sd-mod,usb-storage root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes console=tty1 rootwait" - .into() -} - -fn default_usercfg() -> String { - r#"# modify this file instead of config.txt - -# hide raspberry pi logo on startup -disable_splash=1 -boot_delay=0 - -# enable uart / disable bluetooth -enable_uart=1 -dtoverlay=disable-bt - -# enable HDMI output -dtoverlay=vc4-kms-v3d -display_auto_detect=1 -disable_overscan=1 -"# - .into() -} - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Rpi { - #[serde(default = "default_cmdline")] - pub cmdline: String, - - #[serde(default = "default_usercfg")] - pub usercfg: String -} - -fn default_hostname() -> String { - "alpi".into() -} - -fn default_keymap() -> String { - "de".into() -} - -fn default_timezone() -> String { - "Europe/Amsterdam".into() -} - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Host { - #[serde(default = "default_hostname")] - pub hostname: String, - - #[serde(default = "default_keymap")] - pub keymap: String, - pub keymap_variant: Option, - - #[serde(default = "default_timezone")] - pub timezone: String -} - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct User { - pub name: String, - - pub password: Option, - - #[serde(default)] - pub sudo: bool, - - #[serde(default)] - pub groups: Vec, - - #[serde(default)] - pub authorized_keys: Vec -} diff --git a/src/setup/packages.rs b/src/setup/packages.rs deleted file mode 100644 index ba1a65f..0000000 --- a/src/setup/packages.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Packages { - pub install: Vec, - pub autostart: Vec -}