Skip to content

Commit

Permalink
Merge branch 'main' into alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 committed Nov 7, 2024
2 parents 9ed6fd5 + 8ea3da9 commit 29d8958
Show file tree
Hide file tree
Showing 30 changed files with 810 additions and 260 deletions.
9 changes: 1 addition & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: "actions/stale"
versions: '>= 9'
- dependency-name: "actions/setup-python"
versions: '> 4'
- dependency-name: "crossterm"
versions: '> 0.27.0'
interval: "weekly"
25 changes: 24 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 58 additions & 37 deletions core/src/inner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
fs::File,
io::{BufRead, BufReader, Read},
ops::{Deref, DerefMut},
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
rc::Rc,
Expand All @@ -14,8 +15,34 @@ use temp_dir::TempDir;

const TAB_DATA: Dir = include_dir!("$CARGO_MANIFEST_DIR/tabs");

pub fn get_tabs(validate: bool) -> (TempDir, Vec<Tab>) {
let (temp_dir, tab_files) = TabList::get_tabs();
// Allow the unused TempDir to be stored for later destructor call
#[allow(dead_code)]
pub struct TabList(pub Vec<Tab>, TempDir);

// Implement deref to allow Vec<Tab> methods to be called on TabList
impl Deref for TabList {
type Target = Vec<Tab>;

fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for TabList {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl IntoIterator for TabList {
type Item = Tab;
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

pub fn get_tabs(validate: bool) -> TabList {
let (temp_dir, tab_files) = TabDirectories::get_tabs();

let tabs: Vec<_> = tab_files
.into_iter()
Expand All @@ -33,53 +60,35 @@ pub fn get_tabs(validate: bool) -> (TempDir, Vec<Tab>) {

let tabs: Vec<Tab> = tabs
.into_iter()
.map(
|(
TabEntry {
name,
data,
multi_selectable,
},
directory,
)| {
let mut tree = Tree::new(Rc::new(ListNode {
name: "root".to_string(),
description: String::new(),
command: Command::None,
task_list: String::new(),
}));
let mut root = tree.root_mut();
create_directory(data, &mut root, &directory, validate);
Tab {
name,
tree,
multi_selectable,
}
},
)
.map(|(TabEntry { name, data }, directory)| {
let mut tree = Tree::new(Rc::new(ListNode {
name: "root".to_string(),
description: String::new(),
command: Command::None,
task_list: String::new(),
multi_select: false,
}));
let mut root = tree.root_mut();
create_directory(data, &mut root, &directory, validate, true);
Tab { name, tree }
})
.collect();

if tabs.is_empty() {
panic!("No tabs found");
}
(temp_dir, tabs)
TabList(tabs, temp_dir)
}

#[derive(Deserialize)]
struct TabList {
struct TabDirectories {
directories: Vec<PathBuf>,
}

#[derive(Deserialize)]
struct TabEntry {
name: String,
data: Vec<Entry>,
#[serde(default = "default_multi_selectable")]
multi_selectable: bool,
}

fn default_multi_selectable() -> bool {
true
}

#[derive(Deserialize)]
Expand All @@ -94,6 +103,12 @@ struct Entry {
entry_type: EntryType,
#[serde(default)]
task_list: String,
#[serde(default = "default_true")]
multi_select: bool,
}

fn default_true() -> bool {
true
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -174,24 +189,29 @@ fn create_directory(
node: &mut NodeMut<Rc<ListNode>>,
command_dir: &Path,
validate: bool,
parent_multi_select: bool,
) {
for entry in data {
let multi_select = parent_multi_select && entry.multi_select;

match entry.entry_type {
EntryType::Entries(entries) => {
let mut node = node.append(Rc::new(ListNode {
name: entry.name,
description: entry.description,
command: Command::None,
task_list: String::new(),
multi_select,
}));
create_directory(entries, &mut node, command_dir, validate);
create_directory(entries, &mut node, command_dir, validate, multi_select);
}
EntryType::Command(command) => {
node.append(Rc::new(ListNode {
name: entry.name,
description: entry.description,
command: Command::Raw(command),
task_list: String::new(),
multi_select,
}));
}
EntryType::Script(script) => {
Expand All @@ -210,6 +230,7 @@ fn create_directory(
file: script,
},
task_list: entry.task_list,
multi_select,
}));
}
}
Expand Down Expand Up @@ -252,9 +273,9 @@ fn is_executable(path: &Path) -> bool {
.unwrap_or(false)
}

impl TabList {
impl TabDirectories {
fn get_tabs() -> (TempDir, Vec<PathBuf>) {
let temp_dir = TempDir::new().unwrap();
let temp_dir = TempDir::with_prefix("linutil_scripts").unwrap();
TAB_DATA
.extract(&temp_dir)
.expect("Failed to extract the saved directory");
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::rc::Rc;
use ego_tree::Tree;
use std::path::PathBuf;

pub use inner::get_tabs;
pub use inner::{get_tabs, TabList};

#[derive(Clone, Hash, Eq, PartialEq)]
pub enum Command {
Expand All @@ -23,7 +23,6 @@ pub enum Command {
pub struct Tab {
pub name: String,
pub tree: Tree<Rc<ListNode>>,
pub multi_selectable: bool,
}

#[derive(Clone, Hash, Eq, PartialEq)]
Expand All @@ -32,4 +31,5 @@ pub struct ListNode {
pub description: String,
pub command: Command,
pub task_list: String,
pub multi_select: bool,
}
20 changes: 19 additions & 1 deletion core/tabs/applications-setup/dwmtitus-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,28 @@ setupDisplayManager() {
printf "%b\n" "${YELLOW}3. GDM ${RC}"
printf "%b\n" "${YELLOW} ${RC}"
printf "%b" "${YELLOW}Please select one: ${RC}"
read -r DM
read -r choice
case "$choice" in
1)
DM="sddm"
;;
2)
DM="lightdm"
;;
3)
DM="gdm"
;;
*)
printf "%b\n" "${RED}Invalid selection! Please choose 1, 2, or 3.${RC}"
exit 1
;;
esac
case "$PACKAGER" in
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm "$DM"
if [ "$DM" = "lightdm" ]; then
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm lightdm-gtk-greeter
fi
;;
apt-get|nala)
"$ESCALATION_TOOL" "$PACKAGER" install -y "$DM"
Expand Down
33 changes: 33 additions & 0 deletions core/tabs/applications-setup/podman-compose-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh -e

. ../common-script.sh

installPodmanCompose() {
if ! command_exists podman-compose; then
printf "%b\n" "${YELLOW}Installing Podman Compose...${RC}"
case "$PACKAGER" in
apt-get|nala)
"$ESCALATION_TOOL" "$PACKAGER" install -y podman-compose
;;
zypper)
"$ESCALATION_TOOL" "$PACKAGER" --non-interactive install podman-compose
;;
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --noconfirm --needed podman-compose
;;
dnf)
"$ESCALATION_TOOL" "$PACKAGER" install -y podman-compose
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
exit 1
;;
esac
else
printf "%b\n" "${GREEN}Podman Compose is already installed.${RC}"
fi
}

checkEnv
checkEscalationTool
installPodmanCompose
33 changes: 33 additions & 0 deletions core/tabs/applications-setup/podman-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh -e

. ../common-script.sh

installPodman() {
if ! command_exists podman; then
printf "%b\n" "${YELLOW}Installing Podman...${RC}"
case "$PACKAGER" in
apt-get|nala)
"$ESCALATION_TOOL" "$PACKAGER" install -y podman
;;
zypper)
"$ESCALATION_TOOL" "$PACKAGER" --non-interactive install podman
;;
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --noconfirm --needed podman
;;
dnf)
"$ESCALATION_TOOL" "$PACKAGER" install -y podman
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
exit 1
;;
esac
else
printf "%b\n" "${GREEN}Podman is already installed.${RC}"
fi
}

checkEnv
checkEscalationTool
installPodman
Loading

0 comments on commit 29d8958

Please sign in to comment.