use std::{fs, env}; use chrono::{Datelike, Timelike, Local}; use rust_utils::utils::run_command; const MONTHS: [&str; 12] = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; const VERSION: &str = env!("CARGO_PKG_VERSION"); fn main() { println!("cargo:rerun-if-changed=build.rs"); let icon_dir = match fs::read_dir("/storage/emulated/0") { Ok(_) => format!("{}/share/the_rock/icon.png", env::var("PREFIX").unwrap()), Err(_) => "/usr/share/the_rock/icon.png".to_string() }; let date = Local::now().date_naive(); let month = MONTHS[date.month() as usize - 1]; let day = date.day(); let year = date.year(); let date_str = format!("{day} {month} {year}"); let time = Local::now().time(); let hour = time.hour(); let minute = time.minute(); let second = time.second(); let time_str = format!("{hour:02}:{minute:02}:{second:02}"); let desktop_file = format!( "[Desktop Entry]\n\ Version={VERSION}\n\ Type=Application\n\ Name=The Rock\n\ Comment=Command line King James bible viewer\n\ Exec=the_rock\n\ Icon={icon_dir}\n\ Terminal=true\n\ StartupNotify=false\n\ Categories=Utility;" ); let the_rock_manpage = format!( ".\\\" Manpage for The Rock.\n\ .\\\" Created on {month} {day}, {year} at {time_str}\n\ .TH the_rock 1 \"{date_str}\" \"{VERSION}\" \"the_rock man page\"\n\ .SH NAME\n\ The Rock \\- Command line King James bible viewer\n\ .SH DESCRIPTION\n\ the_rock [chapter]\n\ .br\n\ The Rock is a command line program to view the King James version of the bible\n\ .SH OPTIONS\n\ If you specify a specific chapter as an argument, or if none are specified, The Rock will open the last chapter it closed on, or it will open Genesis 1\n\ .br\n\ Pass --reset-tabs to close all open chapter tabs\n\ .SH SEE ALSO\n\ bible(1)\n\ .SH AUTHOR\n\ Noah Jelen (noahtjelen@gmail.com)" ); let bible_manpage = format!( ".\\\" Manpage for bible (part of The Rock).\n\ .\\\" Created on {month} {day}, {year} at {time_str}\n\ .TH bible 1 \"{date_str}\" \"{VERSION}\" \"bible man page\"\n\ .SH NAME\n\ bible \\- King James bible verse reference utility\n\ .SH SYNOPSIS\n\ bible \n\ .br\n\ bible -p \n\ .br\n\ bible -c \n\ .br\n\ bible -s \n\ .br\n\ bible \n\ .br\n\ biblr -t \n\ .br\n\ bible [verse or passage][,verse or passage,verse or passage...]\n\ .SH DESCRIPTION\n\ bible is the command line interface of The Rock.\n\ .SH OPTIONS\n\ If no options are specifed, bible will just show Genesis 1:1\n\ Use -v to show current version\n\ .br\n\ Use -h to show the help message\n\ .br\n\ Use -p to show the passage as a paragraph instead of verse list\n\ .br\n\ Use -c to show an entire chapter\n\ .br\n\ Use -s to find all instances of a specific word\n\ .SH EXAMPLES\n\ bible Mark9:23\n\ .br\n\ bible matt24:4-14\n\ .br\n\ bible isa40:31,matt6:9-13,Genesis1\n\ .br\n\ bible -p matt24:4-14\n\ .br\n\ bible -c genesis1\n\ .br\n\ bible -cp exodus20\n\ .SH SEE ALSO\n\ the_rock(1)\n\ .SH AUTHOR\n\ Noah Jelen (noahtjelen@gmail.com)" ); fs::remove_file("man/bible.1").unwrap_or(()); fs::remove_file("man/the_rock.1").unwrap_or(()); fs::remove_file("the_rock.desktop").unwrap_or(()); fs::remove_dir("man/").unwrap_or(()); fs::create_dir("man/").unwrap(); fs::write("man/bible.1", bible_manpage).unwrap(); fs::write("man/the_rock.1", the_rock_manpage).unwrap(); fs::write("the_rock.desktop", desktop_file).unwrap(); if env::set_current_dir("aur/").is_ok() { let aur_pkgbuild = format!( "# Maintainer: Noah Jelen \n\ # Generated by cargo on {month} {day}, {year} at {time_str}\n\ pkgname=the-rock\n\ pkgver={VERSION}\n\ pkgrel=1\n\ pkgdesc=\"A command line King James bible viewer\"\n\ arch=('i686' 'x86_64')\n\ url=\"https://gitlab.com/NoahJelen/the-rock\"\n\ license=('GPL3')\n\ depends=('ncurses' 'gcc-libs' 'glibc')\n\ makedepends=('cargo')\n\ source=(\"https://gitlab.com/NoahJelen/the-rock/-/archive/$pkgver/the-rock-$pkgver.zip\")\n\ conflicts=('the-rock-git' 'bible-kjv')\n\ md5sums=('SKIP')\n\n\ build() {{\n \ cd \"the-rock-$pkgver\"\n \ cargo build --release\n \ cd target/release\n \ ln -sf the_rock bible\n\ }}\n\n\ package() {{\n \ cd \"the-rock-$pkgver\"\n \ mkdir -p \"$pkgdir/usr/share/the_rock\"\n \ mkdir -p \"$pkgdir/usr/share/man/man1/\"\n \ install -Dt \"$pkgdir/usr/bin\" -m755 target/release/the_rock\n \ install -Dt \"$pkgdir/usr/bin\" -m755 target/release/bible\n \ install -Dt \"$pkgdir/usr/share/the_rock/\" bible.rawtext\n \ install -Dt \"$pkgdir/usr/share/applications/\" the_rock.desktop\n \ install -Dt \"$pkgdir/usr/share/the_rock/\" icon.png\n \ install -Dt \"$pkgdir/usr/share/man/man1\" man/the_rock.1\n \ install -Dt \"$pkgdir/usr/share/man/man1\" man/bible.1\n\ }}" ); fs::remove_file("PKGBUILD").unwrap_or(()); fs::write("PKGBUILD", aur_pkgbuild).unwrap_or(()); // use makepkg to generate a .SRCINFO file from the aur pkgbuild let cmd = run_command("makepkg", false, ["--printsrcinfo"]); fs::write(".SRCINFO", cmd.output).unwrap(); } }