Skip to content

Commit

Permalink
aspects/User: eliminate Builtin User mode in favor of Entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
waynr committed Apr 6, 2023
1 parent 0097e99 commit b4b42c2
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 57 deletions.
18 changes: 6 additions & 12 deletions app/chrome/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,20 @@ 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 {}),
Box::new(aspects::DBus {}),
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")
}
20 changes: 9 additions & 11 deletions app/discord/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ impl aspects::ContainerAspect for Discord {
}

fn dockerfile_snippets(&self) -> Vec<aspects::DockerfileSnippet> {
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(
Expand Down Expand Up @@ -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 {}),
Expand All @@ -68,7 +66,7 @@ fn main() -> Result<()> {
],
vec!["discord"].into_iter().map(String::from).collect(),
None,
);
)?;

mgr.execute().context("executing discord in container")
}
2 changes: 1 addition & 1 deletion app/drawio/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() -> Result<()> {
],
vec!["drawio"].into_iter().map(String::from).collect(),
None,
);
)?;

mgr.execute().context("executing drawio in container")
}
7 changes: 2 additions & 5 deletions app/firefox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),
Expand All @@ -75,7 +72,7 @@ fn main() -> Result<()> {
.map(String::from)
.collect(),
Some(String::from("bookworm")),
);
)?;

mgr.execute().context("executing firefox in container")
}
7 changes: 2 additions & 5 deletions app/signal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),
Expand All @@ -70,7 +67,7 @@ fn main() -> Result<()> {
.map(String::from)
.collect(),
None,
);
)?;

mgr.execute().context("executing signal in container")
}
13 changes: 6 additions & 7 deletions app/skype/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -91,7 +92,8 @@ while ps -C skypeforlinux >/dev/null;do sleep 3;done "#.into(),
<bool>false</bool>
</edit>
</match>
</fontconfig>"#.into(),
</fontconfig>"#
.into(),
},
]
}
Expand All @@ -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 {}),
Expand All @@ -126,7 +125,7 @@ fn main() -> Result<()> {
.map(String::from)
.collect(),
None,
);
)?;

mgr.execute().context("executing skype in container")
}
9 changes: 3 additions & 6 deletions app/steam/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"#,
),
}]
Expand All @@ -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 {}),
Expand All @@ -59,7 +56,7 @@ fn main() -> Result<()> {
.map(String::from)
.collect(),
None,
);
)?;

mgr.execute().context("executing steam in container")
}
2 changes: 1 addition & 1 deletion app/thinkorswim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn main() -> Result<()> {
],
vec![format!("{}/thinkorswim", thinkorswim_install_dir)],
Some(String::from("bullseye")),
);
)?;

mgr.execute().context("executing thinkorswim in container")
}
2 changes: 1 addition & 1 deletion app/zoom/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() -> Result<()> {
],
vec!["zoom"].into_iter().map(String::from).collect(),
None,
);
)?;

mgr.execute().context("executing zoom in container")
}
10 changes: 2 additions & 8 deletions src/dfiles/aspects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ impl fmt::Display for CurrentUserMode {

#[derive(Clone)]
pub struct CurrentUser {
pub mode: CurrentUserMode,
name: String,
uid: String,
group: String,
Expand All @@ -508,7 +507,7 @@ impl CurrentUser {
self.name.clone()
}

pub fn detect(mode: CurrentUserMode) -> Result<Self> {
pub fn detect() -> Result<Self> {
let uid = users::get_current_uid();
let gid = users::get_current_gid();
let name = match users::get_user_by_uid(uid) {
Expand All @@ -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,
Expand All @@ -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<entrypoint::Script> {
match self.mode {
CurrentUserMode::Entrypoint => (),
_ => return Vec::new(),
}
vec![entrypoint::Script {
description: format!("create a user named {}", self.name),
as_user: None,
Expand Down

0 comments on commit b4b42c2

Please sign in to comment.