From fe52683da7d76320217c2201b5e7d19a65d15ea6 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 28 Aug 2023 09:15:39 -0400 Subject: [PATCH] .. --- Cargo.lock | 11 ++++++ Cargo.toml | 5 ++- build/aarch64-apple-darwin.env | 6 +-- build/aarch64-unknown-linux-gnu.env | 3 ++ build/version.sh | 3 -- build/x86_64-apple-darwin.env | 3 ++ build/x86_64-unknown-linux-gnu.env | 3 ++ justfile | 60 ++++++++++++++++++++++++----- src/main.rs | 18 ++++----- 9 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 build/aarch64-unknown-linux-gnu.env delete mode 100755 build/version.sh create mode 100644 build/x86_64-apple-darwin.env create mode 100644 build/x86_64-unknown-linux-gnu.env diff --git a/Cargo.lock b/Cargo.lock index f06e198..e33fa43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,6 +149,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", + "once_cell", "strsim", ] @@ -574,6 +575,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.27.0+1.1.1v" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e8f197c82d7511c5b014030c9b1efeda40d7d5f99d23b4ceed3524a5e63f02" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.91" @@ -582,6 +592,7 @@ checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index f7d2d89..e6e33bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,14 @@ [package] name = "upnotify" +description = "A tool that prints to stdout when the status of a URL changes." version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -reqwest = { version = "0.11.20", features = ["blocking"] } -clap = "4.4.0" +reqwest = { version = "0.11.20", features = ["blocking", "native-tls-vendored"] } +clap = { version = "4.4.0", features = ["cargo"] } [[bin]] name = "upnotify" \ No newline at end of file diff --git a/build/aarch64-apple-darwin.env b/build/aarch64-apple-darwin.env index 5a8be27..5c831f3 100644 --- a/build/aarch64-apple-darwin.env +++ b/build/aarch64-apple-darwin.env @@ -1,3 +1,3 @@ -ARCH=arm64 -PLATFORM=darwin -UPNOTIFY_BINARY=target/aarch64-apple-darwin/release/upnotify \ No newline at end of file +export ARCH=arm64 +export PLATFORM=darwin +export UPNOTIFY_BINARY=target/aarch64-apple-darwin/release/upnotify \ No newline at end of file diff --git a/build/aarch64-unknown-linux-gnu.env b/build/aarch64-unknown-linux-gnu.env new file mode 100644 index 0000000..69ce72a --- /dev/null +++ b/build/aarch64-unknown-linux-gnu.env @@ -0,0 +1,3 @@ +export ARCH=arm64 +export PLATFORM=linux +export UPNOTIFY_BINARY=target/aarch64-unknown-linux-gnu/release/upnotify \ No newline at end of file diff --git a/build/version.sh b/build/version.sh deleted file mode 100755 index 3ec44f6..0000000 --- a/build/version.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -git tag --list --contains "$(git log -n1 --pretty='%h')" --sort -refname | head -n 1 \ No newline at end of file diff --git a/build/x86_64-apple-darwin.env b/build/x86_64-apple-darwin.env new file mode 100644 index 0000000..f16e361 --- /dev/null +++ b/build/x86_64-apple-darwin.env @@ -0,0 +1,3 @@ +export ARCH=amd64 +export PLATFORM=darwin +export UPNOTIFY_BINARY=target/x86_64-apple-darwin/release/upnotify \ No newline at end of file diff --git a/build/x86_64-unknown-linux-gnu.env b/build/x86_64-unknown-linux-gnu.env new file mode 100644 index 0000000..2eb0797 --- /dev/null +++ b/build/x86_64-unknown-linux-gnu.env @@ -0,0 +1,3 @@ +export ARCH=amd64 +export PLATFORM=linux +export UPNOTIFY_BINARY=target/x86_64-unknown-linux-gnu/release/upnotify \ No newline at end of file diff --git a/justfile b/justfile index b8181de..3d86a3d 100644 --- a/justfile +++ b/justfile @@ -1,31 +1,71 @@ target:=`rustc -vV | sed -n 's|host: ||p'` os_family:=os_family() archive_type:=if os_family == "windows" { "zip" } else { "tarball" } +package_type:="none" os:=os() arch:=arch() -version:=`git tag` +version:=`toml get Cargo.toml package.version --raw` +archive_name:="upnotify-{{version}}-{{target}}" +msg:="Unknown error" default: build -sys-info: - @echo "os_family {{os_family()}}" - @echo "os {{os()}}" - @echo "arch: {{arch()}}" +die: + @echo "Error: {{msg}}" + +assert-darwin-host: + @{{ if os == "macos" { "true" } else { "just msg=\"Not a darwin host\" die" } }} clean: - rm -rf target + rm -rf target dist build: cargo build --release --target {{target}} build-mac-m1: - just target=aarch64-apple-darwin archive + just target=aarch64-apple-darwin assert-darwin-host archive + +build-linux-amd64: + docker run --rm --platform linux/amd64 --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp \ + rust:1.70.0 sh -c "cargo install just toml-cli && just archive" + +build-linux-arm64: + docker run --rm --platform linux/arm64 --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp \ + rust:1.70.0 sh -c "cargo install just toml-cli && just archive" archive-tarball: - tar czf target/{{target}}/release/upnotify-{{version}}-{{target}}.tar.gz target/{{target}}/release/upnotify + tar czf dist/{{target}}/{{archive_name}}.tar.gz target/{{target}}/release/upnotify archive-zip: - zip target/{{target}}/release/upnotify-{{version}}-{{target}}.zip target/{{target}}/release/upnotify + zip dist/{{target}}/{{archive_name}}.zip target/{{target}}/release/upnotify + +archive-all: + just archive-tarball archive-zip archive: build - just archive-{{archive_type}} \ No newline at end of file + just archive-{{archive_type}} + +package-none: + @echo "Nothing to do; specify a package_type" + +package-rpm: + #!/usr/bin/env bash + mkdir -p dist/{{target}} + source build/{{target}}.env + nfpm package -p rpm -f <(VERSION={{version}} envsubst < build/nfpm.yaml.tmpl) --target dist/{{target}}/ + +package-deb: + #!/usr/bin/env bash + mkdir -p dist/{{target}} + source build/{{target}}.env + nfpm package -p deb -f <(VERSION={{version}} envsubst < build/nfpm.yaml.tmpl) --target dist/{{target}}/ + +linux-packages: + just target=x86_64-unknown-linux-gnu package-deb package-rpm + just target=aarch64-unknown-linux-gnu package-deb package-rpm + +package: + just package-{{package_type}} + +homebrew-program: + diff --git a/src/main.rs b/src/main.rs index 7595ca3..bc12197 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::thread::sleep; use std::time::Duration; -use clap::{arg, ArgAction, Command}; + +use clap::{arg, ArgAction, Command, crate_authors, crate_description, crate_name, crate_version}; use reqwest::blocking::Client; use reqwest::StatusCode; @@ -8,14 +9,14 @@ enum Result { StatusCode(StatusCode), ConnectError(reqwest::Error), OtherError(reqwest::Error), - None + None, } fn main() { - let cli = Command::new("Upnotify") - .version("0.1.0") - .author("Scott Jackson") - .about("Monitors HTTP status changes of a URL") + let cli = Command::new(crate_name!()) + .version(crate_version!()) + .author(crate_authors!()) + .about(crate_description!()) .arg( arg!(--url ).required(true).action(ArgAction::Set) ) @@ -24,7 +25,7 @@ fn main() { let url = cli.get_one::("url").expect("required"); let client = Client::builder() .danger_accept_invalid_certs(true) - .build().unwrap_or_else(| _result | panic!("Unable to create client!")); + .build().unwrap_or_else(|_result| panic!("Unable to create client!")); let mut previous_status_option: Result = Result::None; loop { @@ -54,8 +55,7 @@ fn main() { } } } - previous_status_option = if error.is_connect() { Result::ConnectError(error) } - else { Result::OtherError(error) } + previous_status_option = if error.is_connect() { Result::ConnectError(error) } else { Result::OtherError(error) } } } sleep(Duration::from_secs(5));