diff --git a/src/recipe.rs b/src/recipe.rs index 567ca70..5d0588d 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -10,47 +10,53 @@ pub struct Recipe { #[serde(alias = "fedora-version")] pub fedora_version: u16, - pub scripts: Scripts, + pub scripts: Option, - pub rpm: Rpm, + pub rpm: Option, #[serde(alias = "usr-dir-overlays")] pub usr_dir_overlays: Option>, pub containerfiles: Option, - pub firstboot: FirstBoot, + pub firstboot: Option, } impl Recipe { pub fn process_repos(mut self) -> Self { - self.rpm.repos = self - .rpm - .repos - .iter() - .map(|s| s.replace("%FEDORA_VERSION%", self.fedora_version.to_string().as_str())) - .collect(); + if let Some(rpm) = &mut self.rpm { + if let Some(repos) = &rpm.repos { + rpm.repos = Some( + repos + .iter() + .map(|s| { + s.replace("%FEDORA_VERSION%", self.fedora_version.to_string().as_str()) + }) + .collect(), + ); + } + } self } } #[derive(Debug, Serialize, Deserialize)] pub struct Scripts { - pub pre: Vec, - pub post: Vec, + pub pre: Option>, + pub post: Option>, } #[derive(Debug, Serialize, Deserialize)] pub struct Rpm { - pub repos: Vec, - pub install: Vec, - pub remove: Vec, + pub repos: Option>, + pub install: Option>, + pub remove: Option>, } #[derive(Debug, Serialize, Deserialize)] pub struct FirstBoot { pub yafti: bool, - pub flatpaks: Vec, + pub flatpaks: Option>, } #[derive(Debug, Serialize, Deserialize)] diff --git a/templates/starting_point.template b/templates/starting_point.template index b98093b..0706640 100644 --- a/templates/starting_point.template +++ b/templates/starting_point.template @@ -34,15 +34,19 @@ RUN find /tmp/scripts -type f -exec chmod +x {} \; {{ print_autorun_scripts(mode = "pre") }} +{% if scripts and scripts.pre %} {% for script in scripts.pre %} RUN /bin/bash -c '/tmp/scripts/{{ script }} pre' {% endfor %} +{% endif %} +{% if rpm and rpm.repos %} {% for repo in rpm.repos %} RUN wget "{{ repo }}" -P "/etc/yum.repos.d/" {% endfor %} +{% endif %} -{% if rpm.remove %} +{% if rpm and rpm.remove %} RUN rpm-ostree override remove {% for app in rpm.remove %}{{ app }} {% endfor %} {% endif %} @@ -68,15 +72,17 @@ RUN echo "-- firstboot: Removing all \"firstboot\" components --"; \ rm -rf "${FIRSTBOOT_DATA}" {% endif %} -{% if rpm.install %} +{% if rpm and rpm.install %} RUN rpm-ostree install {% for app in rpm.install %}{{ app }} {% endfor %} {% endif %} {{ print_autorun_scripts(mode = "post") }} +{% if scripts and scripts.pre %} {% for script in scripts.post -%} RUN /bin/bash -c '/tmp/scripts/{{ script }} post' {% endfor -%} +{% endif %} {% if containerfiles and containerfiles.post %} {% for containerfile in containerfiles.post %}