From b4b42c2598c1576665eb1e514dd8e46ebb1a6d42 Mon Sep 17 00:00:00 2001 From: wayne warren Date: Wed, 5 Apr 2023 22:39:05 -0600 Subject: [PATCH] aspects/User: eliminate Builtin User mode in favor of Entrypoint --- app/chrome/src/main.rs | 18 ++++++------------ app/discord/src/main.rs | 20 +++++++++----------- app/drawio/src/main.rs | 2 +- app/firefox/src/main.rs | 7 ++----- app/signal/src/main.rs | 7 ++----- app/skype/src/main.rs | 13 ++++++------- app/steam/src/main.rs | 9 +++------ app/thinkorswim/src/main.rs | 2 +- app/zoom/src/main.rs | 2 +- src/dfiles/aspects.rs | 10 ++-------- 10 files changed, 33 insertions(+), 57 deletions(-) diff --git a/app/chrome/src/main.rs b/app/chrome/src/main.rs index 1fd39d7..5237280 100644 --- a/app/chrome/src/main.rs +++ b/app/chrome/src/main.rs @@ -105,10 +105,7 @@ fn main() -> Result<()> { vec![ Box::new(Chrome {}), Box::new(aspects::Name("chrome".to_string())), - Box::new( - aspects::CurrentUser::detect(aspects::CurrentUserMode::Builtin) - .context("detecting current user")?, - ), + Box::new(aspects::CurrentUser::detect().context("detecting current user")?), Box::new(aspects::PulseAudio {}), Box::new(aspects::X11 {}), Box::new(aspects::Video {}), @@ -116,15 +113,12 @@ fn main() -> Result<()> { Box::new(aspects::SysAdmin {}), Box::new(aspects::Shm {}), ], - vec![ - "google-chrome", - &format!("--user-data-dir={}", data_dir), - ] - .into_iter() - .map(String::from) - .collect(), + vec!["google-chrome", &format!("--user-data-dir={}", data_dir)] + .into_iter() + .map(String::from) + .collect(), Some(String::from("bullseye")), - ); + )?; mgr.execute().context("executing chrome in container") } diff --git a/app/discord/src/main.rs b/app/discord/src/main.rs index f032413..472135c 100644 --- a/app/discord/src/main.rs +++ b/app/discord/src/main.rs @@ -14,18 +14,19 @@ impl aspects::ContainerAspect for Discord { } fn dockerfile_snippets(&self) -> Vec { - vec![aspects::DockerfileSnippet { - order: 91, - content: format!( - r#"WORKDIR /opt/ + vec![ + aspects::DockerfileSnippet { + order: 91, + content: format!( + r#"WORKDIR /opt/ RUN curl https://dl.discordapp.net/apps/linux/0.0.25/discord-0.0.25.deb > /opt/discord.deb && \ dpkg --force-depends -i /opt/discord.deb ; rm /opt/discord.deb RUN apt-get update && apt-get --fix-broken install -y \ && apt-get purge --autoremove \ && rm -rf /var/lib/apt/lists/* \ && rm -rf /src/*.deb "#, - ), - }, + ), + }, aspects::DockerfileSnippet { order: 92, content: String::from( @@ -55,10 +56,7 @@ fn main() -> Result<()> { vec![ Box::new(Discord {}), Box::new(aspects::Name("discord".to_string())), - Box::new( - aspects::CurrentUser::detect(aspects::CurrentUserMode::Builtin) - .context("detecting current user")?, - ), + Box::new(aspects::CurrentUser::detect().context("detecting current user")?), Box::new(aspects::PulseAudio {}), Box::new(aspects::X11 {}), Box::new(aspects::Video {}), @@ -68,7 +66,7 @@ fn main() -> Result<()> { ], vec!["discord"].into_iter().map(String::from).collect(), None, - ); + )?; mgr.execute().context("executing discord in container") } diff --git a/app/drawio/src/main.rs b/app/drawio/src/main.rs index 9f5a579..7db9ca2 100644 --- a/app/drawio/src/main.rs +++ b/app/drawio/src/main.rs @@ -61,7 +61,7 @@ fn main() -> Result<()> { ], vec!["drawio"].into_iter().map(String::from).collect(), None, - ); + )?; mgr.execute().context("executing drawio in container") } diff --git a/app/firefox/src/main.rs b/app/firefox/src/main.rs index 15cb69c..9fc65f9 100644 --- a/app/firefox/src/main.rs +++ b/app/firefox/src/main.rs @@ -55,10 +55,7 @@ fn main() -> Result<()> { vec![ Box::new(Firefox {}), Box::new(aspects::Name("firefox".to_string())), - Box::new( - aspects::CurrentUser::detect(aspects::CurrentUserMode::Entrypoint) - .context("detecting current user")?, - ), + Box::new(aspects::CurrentUser::detect().context("detecting current user")?), Box::new(aspects::PulseAudio {}), Box::new(aspects::X11 {}), Box::new(aspects::Video {}), @@ -75,7 +72,7 @@ fn main() -> Result<()> { .map(String::from) .collect(), Some(String::from("bookworm")), - ); + )?; mgr.execute().context("executing firefox in container") } diff --git a/app/signal/src/main.rs b/app/signal/src/main.rs index ac8e712..265e902 100644 --- a/app/signal/src/main.rs +++ b/app/signal/src/main.rs @@ -56,10 +56,7 @@ fn main() -> Result<()> { Box::new(Signal {}), Box::new(aspects::Name("signal".to_string())), Box::new(aspects::PulseAudio {}), - Box::new( - aspects::CurrentUser::detect(aspects::CurrentUserMode::Builtin) - .context("detecting current user")?, - ), + Box::new(aspects::CurrentUser::detect().context("detecting current user")?), Box::new(aspects::X11 {}), Box::new(aspects::Video {}), Box::new(aspects::DBus {}), @@ -70,7 +67,7 @@ fn main() -> Result<()> { .map(String::from) .collect(), None, - ); + )?; mgr.execute().context("executing signal in container") } diff --git a/app/skype/src/main.rs b/app/skype/src/main.rs index cbaa07c..6ba2147 100644 --- a/app/skype/src/main.rs +++ b/app/skype/src/main.rs @@ -54,7 +54,8 @@ RUN chmod 755 /usr/local/bin/run-skype-and-wait-for-exit"#, contents: r#"#!/bin/bash skypeforlinux sleep 3 -while ps -C skypeforlinux >/dev/null;do sleep 3;done "#.into(), +while ps -C skypeforlinux >/dev/null;do sleep 3;done "# + .into(), }, aspects::ContainerFile { container_path: String::from("./etc/fonts/local.conf"), @@ -91,7 +92,8 @@ while ps -C skypeforlinux >/dev/null;do sleep 3;done "#.into(), false -"#.into(), +"# + .into(), }, ] } @@ -110,10 +112,7 @@ fn main() -> Result<()> { vec![ Box::new(Skype {}), Box::new(aspects::Name("skype".to_string())), - Box::new( - aspects::CurrentUser::detect(aspects::CurrentUserMode::Builtin) - .context("detecting current user")?, - ), + Box::new(aspects::CurrentUser::detect().context("detecting current user")?), Box::new(aspects::PulseAudio {}), Box::new(aspects::X11 {}), Box::new(aspects::Video {}), @@ -126,7 +125,7 @@ fn main() -> Result<()> { .map(String::from) .collect(), None, - ); + )?; mgr.execute().context("executing skype in container") } diff --git a/app/steam/src/main.rs b/app/steam/src/main.rs index d998819..98fa5ce 100644 --- a/app/steam/src/main.rs +++ b/app/steam/src/main.rs @@ -23,7 +23,7 @@ RUN apt-get update && yes 'I AGREE' | apt-get install -y \ steam \ && apt-get purge --autoremove \ && rm -rf /var/lib/apt/lists/* \ - && rm -rf /src/*.deb + && rm -rf /src/*.deb RUN chmod 4755 /opt/Signal/chrome-sandox"#, ), }] @@ -43,10 +43,7 @@ fn main() -> Result<()> { vec![ Box::new(Steam {}), Box::new(aspects::Name("steam".to_string())), - Box::new( - aspects::CurrentUser::detect(aspects::CurrentUserMode::Builtin) - .context("detecting current user")?, - ), + Box::new(aspects::CurrentUser::detect().context("detecting current user")?), Box::new(aspects::PulseAudio {}), Box::new(aspects::Alsa {}), Box::new(aspects::X11 {}), @@ -59,7 +56,7 @@ fn main() -> Result<()> { .map(String::from) .collect(), None, - ); + )?; mgr.execute().context("executing steam in container") } diff --git a/app/thinkorswim/src/main.rs b/app/thinkorswim/src/main.rs index 9cf508a..287b511 100644 --- a/app/thinkorswim/src/main.rs +++ b/app/thinkorswim/src/main.rs @@ -97,7 +97,7 @@ fn main() -> Result<()> { ], vec![format!("{}/thinkorswim", thinkorswim_install_dir)], Some(String::from("bullseye")), - ); + )?; mgr.execute().context("executing thinkorswim in container") } diff --git a/app/zoom/src/main.rs b/app/zoom/src/main.rs index c11a584..e2db2d0 100644 --- a/app/zoom/src/main.rs +++ b/app/zoom/src/main.rs @@ -54,7 +54,7 @@ fn main() -> Result<()> { ], vec!["zoom"].into_iter().map(String::from).collect(), None, - ); + )?; mgr.execute().context("executing zoom in container") } diff --git a/src/dfiles/aspects.rs b/src/dfiles/aspects.rs index 969dadb..2a1d945 100644 --- a/src/dfiles/aspects.rs +++ b/src/dfiles/aspects.rs @@ -496,7 +496,6 @@ impl fmt::Display for CurrentUserMode { #[derive(Clone)] pub struct CurrentUser { - pub mode: CurrentUserMode, name: String, uid: String, group: String, @@ -508,7 +507,7 @@ impl CurrentUser { self.name.clone() } - pub fn detect(mode: CurrentUserMode) -> Result { + pub fn detect() -> Result { let uid = users::get_current_uid(); let gid = users::get_current_gid(); let name = match users::get_user_by_uid(uid) { @@ -520,7 +519,6 @@ impl CurrentUser { None => return Err(Error::MissingGroup(gid.to_string())), }; Ok(CurrentUser { - mode: mode, name: name, uid: uid.to_string(), group: group, @@ -531,14 +529,10 @@ impl CurrentUser { impl ContainerAspect for CurrentUser { fn name(&self) -> String { - format!("User<{}>: {}", &self.mode, &self.name) + format!("User: {}", &self.name) } fn entrypoint_scripts(&self) -> Vec { - match self.mode { - CurrentUserMode::Entrypoint => (), - _ => return Vec::new(), - } vec![entrypoint::Script { description: format!("create a user named {}", self.name), as_user: None,