feat: 🎸 Add install.sh script

This commit is contained in:
Atsukoro1 2022-12-02 17:01:24 +01:00
parent 8fd7c9b1a2
commit efa52c72d3
7 changed files with 65 additions and 11 deletions

40
install.sh Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
function makeDirectories() {
echo "Creating required directories..."
if [ ! -d "/usr/share/ponyfetch" ]; then
mkdir /usr/share/ponyfetch
mkdir /usr/share/ponyfetch/ponies
fi
}
function compile() {
echo "Compiling ponyfetch..."
if [ ! -f "/usr/bin/ponyfetch" ]; then
cargo build --release
fi
}
function moveFiles() {
echo "Moving files..."
if [ ! -f "/usr/bin/ponyfetch" ]; then
cp target/release/ponyfetch /usr/bin/ponyfetch
fi
toCopyCount=$(ls -1 /usr/share/ponyfetch/ponies/*.txt 2>/dev/null | wc -l)
dirCount=$(ls -1 ponies/*.txt 2>/dev/null | wc -l)
if [ $toCopyCount != $dirCount ]; then
cp -r ponies/* /usr/share/ponyfetch/ponies
fi
}
echo "Thanks for choosing ponyfetch!"
echo "Let's begin installing!"
makeDirectories
compile
moveFiles

View file

@ -12,10 +12,10 @@
/ .'-'''':/ _\.-- \ '.\ )\
( y' -`| /-.-\ \ .'`-. ) \
\( ( (((:.:)) \ '. `-.-' )
'. |\( \\\_// '. '. .-'`|
''.` \``` . '. `-'` /
\ \__. /'. .'
-' / .' ( '-.-'
'. |\( \\\_// '. '. .-'`|
''.` \``` . '. `-'` /
\ \__. /'. .'
-' / .' ( '-.-'
| ,' .| | (
.' / (.' \ \
| ( ( \ \

View file

@ -36,10 +36,7 @@ const COLORS : [(&str, &str); 34] = [
];
pub fn print(text: &str, inline: bool, color: &str) {
let mut color = color;
if color == "rainbowdash" {
color = "bright_magenta";
}
let color = color;
let color = color;
let color = COLORS.iter().find(|(name, _)| name == &color).unwrap().1;

View file

@ -1,3 +1,4 @@
pub mod file;
pub mod colors;
pub mod print;
pub mod print;
pub mod paths;

16
src/helpers/paths.rs Normal file
View file

@ -0,0 +1,16 @@
use std::path::PathBuf;
#[cfg(target_os = "linux")]
pub fn get_pony_path() -> String {
if std::env::current_exe().unwrap().to_str().unwrap().contains("target") {
PathBuf::from("ponies/")
.to_str()
.unwrap()
.to_string()
} else {
PathBuf::from("/usr/share/ponyfetch/ponies/")
.to_str()
.unwrap()
.to_string()
}
}

View file

@ -45,7 +45,7 @@ pub fn print_detail(title: &str, value: String, atype: ActionType, color: &str)
}
pub fn print_ponyline(line: u16, pony: &str, color: &str) {
file_open(&format!("ponies/{}.txt", pony).to_string())
file_open(&format!("{}{}.txt", helpers::paths::get_pony_path(), pony).to_string())
.lines()
.skip(line as usize)
.take(1)

View file

@ -87,7 +87,7 @@ fn main() {
let args: Args = Args::parse();
let line_count = helpers::file::get_file_linecount(
&format!("ponies/{}.txt", &args.pony)
&format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony)
);
let to_skip = ((line_count / 2) as f32).floor() - 6.0;