Browse Source

Installation script, new and usable flags, improved README

main
Unbewohnte 3 years ago
parent
commit
0ee2bb77df
  1. 36
      README.md
  2. 4
      fumofiles/mini.fumo
  3. 34
      install.sh
  4. 38
      src/main.rs

36
README.md

@ -16,7 +16,7 @@
# Installation # Installation
## Compile it yourself ## "Compile it yourself" way
install Rust install Rust
- [installation instructions](https://www.rust-lang.org/tools/install) - [installation instructions](https://www.rust-lang.org/tools/install)
@ -29,32 +29,46 @@ cd into cloned repo
compile for your OS && Architecture compile for your OS && Architecture
- `cargo build --release` - `cargo build --release`
move compiled executable to the current directory
- `mv target/release/fumosay .` or `mv target/[target_name]/release/fumosay .`
**or** **or**
## Download a pre-compiled version (only amd64 Linux and Windows) ## "Download a pre-compiled version (Linux amd64 only)" way
- [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases) - [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases)
## After compilation|downloading unzip
- `unzip [zip_archive_name]` or `7z x [7z_archive_name]`
create a directory where the program will 'sit' cd into unzipped directory
- `mkdir $HOME/fumosay` - `cd fumosay/`
retrieve the executable and fumofiles and move them there ## After compilation|downloading
- `mv fumosay/target/release/fumo $HOME/fumosay/ && mv fumofiles $HOME/fumosay`
run installation script
- `chmod +x install.sh && sudo ./install.sh`
**binary file and fumofiles must be in the same directory as install.sh !**
**Now you have fumosay installed !** **Now you have fumosay installed !**
The next possible step would probably be to add this directory to the $PATH environment variable.
--- ---
## Use ## Use
``` ```
./fumosay [message] fumosay message_here
```
prints a message with a default fumo.fumo template
```
fumosay -f mini.fumo message_here
```
prints a message with a mini.fumo template. You can add your own fumofiles
in /usr/share/fumosay/fumofiles/ and use them with -f flag
```
fumosay -d path/to/your/fumofiles/ -f your_fumo.fumo fumofumo
``` ```
uses a non-default path to fumofiles and a custom fumofile
--- ---

4
fumofiles/mini.fumo

@ -0,0 +1,4 @@
<!message>
\
\
(ᗜˬᗜ)

34
install.sh

@ -0,0 +1,34 @@
#!/bin/bash
# fumosay installation script
FUMOSAY_BIN_DIR_PATH=/usr/bin/
FUMOFILES_DIR_PATH=/usr/share/fumosay/fumofiles/
# create directories
mkdir -p $FUMOSAY_BIN_DIR_PATH && mkdir -p $FUMOFILES_DIR_PATH
# copy fumosay binary
if [ -e fumosay ]
then
cp fumosay $FUMOSAY_BIN_DIR_PATH && echo "Copied binary file"
elif [ -e target/x86_64-unknown-linux-musl/release/fumosay ] # For debug purposes. The binary file should be in the same directory as the script !!!
then
cp target/x86_64-unknown-linux-musl/release/fumosay $FUMOSAY_BIN_DIR_PATH && echo "Copied binary from linux-musl directory"
else
echo "Could not find a fumosay binary file"
exit 1
fi
# copy fumofiles
if [ -d fumofiles ]
then
cp -r fumofiles/* $FUMOFILES_DIR_PATH && echo "Copied fumofiles"
else
echo "Could not find fumofiles directory"
exit 1
fi
echo "Installation completed"

38
src/main.rs

@ -1,11 +1,13 @@
use std::fs; use std::fs;
use std::env; use std::path::Path;
use clap::{Arg, App}; use clap::{Arg, App};
/// Indicator of where the message should be in fumofile /// Indicator of where the message should be in fumofile
pub const MESSAGE_INDICATOR: &str = "!message"; const MESSAGE_INDICATOR: &str = "!message";
/// Fumofile name of the default fumo /// Fumofile name of the default fumo
pub const FUMO_DEFAULT: &str = "fumo.fumo"; const FUMO_DEFAULT: &str = "fumo.fumo";
/// Default directory where fumofiles are placed
const FUMOFILES_DIR: &str = "/usr/share/fumosay/fumofiles/";
/// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given /// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given
/// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the /// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the
@ -30,7 +32,19 @@ fn main() {
.value_name("fumofile") .value_name("fumofile")
.help("choose another fumofumo to print") .help("choose another fumofumo to print")
.takes_value(true) .takes_value(true)
.required(false)) .required(false)
.default_value(FUMO_DEFAULT)
)
.arg(
Arg::with_name("fumofiles_directory")
.short("d")
.long("fumofiles_directory")
.value_name("fumofiles_directory_path")
.help("look for fumofiles in given directory instead")
.takes_value(true)
.required(false)
.default_value(FUMOFILES_DIR)
)
.arg( .arg(
Arg::with_name("message") Arg::with_name("message")
.short("m") .short("m")
@ -42,16 +56,14 @@ fn main() {
.multiple(true) .multiple(true)
).get_matches(); ).get_matches();
// default path to the fumofile // process fumofiles directory
// grab path to exe // directory with all fumofiles
let executable_path = env::current_exe().expect("Could not get current exe`s path!"); let new_fumofiles_dir = matches.value_of("fumofiles_directory").unwrap();
// remove the last bit (exe filename) // name of the fumofile to work with
let executable_dir = executable_path.parent().expect("Could not get exe`s parent directory !"); let fumofile_name = matches.value_of("fumo").unwrap();
// local path to the default fumofile // the whole path to the selected fumo
let fumofile_default_path = std::path::Path::new("fumofiles").join(FUMO_DEFAULT); let fumofile_path = Path::new(&new_fumofiles_dir).join(fumofile_name);
// add them together
let fumofile_path = executable_dir.join(fumofile_default_path);
// read fumofile // read fumofile
let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!"); let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!");

Loading…
Cancel
Save