Skip to content

Commit

Permalink
Merge pull request #1 from kpcyrd/format
Browse files Browse the repository at this point in the history
Pass a custom format to arch-audit
  • Loading branch information
kpcyrd authored Mar 13, 2021
2 parents ab68c75 + 00ab4b0 commit d81bdae
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rust

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt-get install libpango1.0-dev libatk1.0-dev libgtk-3-dev libappindicator3-dev
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: Install dependencies
run: sudo apt-get install libpango1.0-dev libatk1.0-dev libgtk-3-dev libappindicator3-dev
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace --tests -- --deny warnings
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ system.

## Install

git clone https://aur.archlinux.org/arch-audit-gtk.git
cd arch-audit-gtk
makepkg -si
pacman -S arch-audit-gtk

## Gnome3

Expand Down
28 changes: 14 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{anyhow, bail, Result, Context};
use inotify::{Inotify, WatchMask};
use std::borrow::Cow;
use log::{warn, info, debug};
use std::env;
use std::fs::File;
use std::path::Path;
use std::sync::mpsc;
Expand Down Expand Up @@ -63,15 +64,23 @@ impl Status {
}
}

fn update() -> Result<Vec<Update>> {
let output = Command::new("arch-audit")
.args(&["-u"])
fn check_updates() -> Result<Vec<Update>> {
// Select the arch-audit binary
let bin = env::var("ARCH_AUDIT_BIN");
let bin = bin.as_ref()
.map(|x| x.as_str())
.unwrap_or("arch-audit");

// Run the arch-audit binary
let output = Command::new(bin)
.args(&["-u", "--format", "%s: %n (%t)"])
.output()
.context("Failed to run arch-audit")?;

info!("arch-audit exited: {}", output.status);

if output.status.success() {
// if arch-audit didn't indicate an error, read the update list into lines
let output = String::from_utf8_lossy(&output.stdout);
let updates = output.trim()
.split('\n')
Expand All @@ -96,7 +105,7 @@ fn update() -> Result<Vec<Update>> {
fn background(update_rx: mpsc::Receiver<()>, result_tx: glib::Sender<Status>) {
loop {
info!("Checking for security updates...");
let msg = update()
let msg = check_updates()
.map(Status::MissingUpdates)
.unwrap_or_else(|e| Status::Error(format!("{:#}", e)));
result_tx.send(msg).ok();
Expand Down Expand Up @@ -141,7 +150,7 @@ fn gtk_main() -> Result<()> {
update_tx.send(()).unwrap();
});

let status_mi = gtk::MenuItem::with_label(&format!("Starting..."));
let status_mi = gtk::MenuItem::with_label("Starting...");
m.append(&status_mi);

let mi = gtk::MenuItem::with_label(QUIT);
Expand Down Expand Up @@ -252,12 +261,3 @@ fn main() -> Result<()> {
gtk_main()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test() {
}
}

0 comments on commit d81bdae

Please sign in to comment.