Compare commits
2 Commits
6c017b3262
...
cec35fc16b
| Author | SHA1 | Date | |
|---|---|---|---|
| cec35fc16b | |||
| e5fb6e7231 |
11
native.sh
11
native.sh
@@ -4,11 +4,18 @@ NATIVE=~/.sdkman/candidates/java/21.0.2-graalce/bin/native-image
|
|||||||
BIN_FILE=totp
|
BIN_FILE=totp
|
||||||
|
|
||||||
echo "Creating uberjar"
|
echo "Creating uberjar"
|
||||||
clojure -T:build uber
|
#clojure -T:build uber
|
||||||
UBERJAR=$(realpath --relative-to=target target/clj-totp-*-standalone.jar)
|
UBERJAR=$(realpath --relative-to=target target/clj-totp-*-standalone.jar)
|
||||||
|
|
||||||
echo "Creating native image"
|
echo "Creating native image"
|
||||||
$NATIVE -jar target/$UBERJAR -o target/$BIN_FILE -H:+ReportExceptionStackTraces --features=clj_easy.graal_build_time.InitClojureClasses --report-unsupported-elements-at-runtime --verbose --no-fallback -H:ReflectionConfigurationFiles=./reflect_config.json
|
$NATIVE -jar target/$UBERJAR -o target/$BIN_FILE\
|
||||||
|
-H:+ReportExceptionStackTraces\
|
||||||
|
-H:ReflectionConfigurationFiles=./reflect_config.json\
|
||||||
|
--verbose --no-fallback\
|
||||||
|
--features=clj_easy.graal_build_time.InitClojureClasses\
|
||||||
|
--report-unsupported-elements-at-runtime\
|
||||||
|
--initialize-at-build-time=org.fusesource.jansi.Ansi\
|
||||||
|
--trace-class-initialization=org.fusesource.jansi.Ansi
|
||||||
|
|
||||||
echo "Executable created on target/$BIN_FILE"
|
echo "Executable created on target/$BIN_FILE"
|
||||||
cp target/$BIN_FILE ~/bin
|
cp target/$BIN_FILE ~/bin
|
||||||
|
|||||||
@@ -9,17 +9,18 @@
|
|||||||
(:import [java.util TimerTask Timer])
|
(:import [java.util TimerTask Timer])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
|
(def DEFAULT_BAR_STYLE :coloured-ascii-boxes)
|
||||||
|
|
||||||
(defn print-timer
|
(defn print-timer
|
||||||
([] (print-timer 1 30))
|
([] (print-timer 1 30 DEFAULT_BAR_STYLE))
|
||||||
([start] (print-timer start 30))
|
([bar-style] (print-timer 1 30 bar-style))
|
||||||
([start period]
|
([start period bar-style]
|
||||||
(let [a (atom start)]
|
(let [a (atom start)]
|
||||||
(pd/animate! a :opts {:total period
|
(pd/animate! a :opts {:total period
|
||||||
;:line 1
|
;:line 1
|
||||||
:label "Next TOTP: "
|
:label "Next TOTP: "
|
||||||
;:redraw-rate 60 ;; updates per second
|
;:redraw-rate 60 ;; updates per second
|
||||||
:style (:coloured-ascii-boxes pd/styles)}
|
:style (get pd/styles bar-style)}
|
||||||
;(println)
|
;(println)
|
||||||
(run! (fn [_] (Thread/sleep 1000) (swap! a inc)) (range start (inc period)))
|
(run! (fn [_] (Thread/sleep 1000) (swap! a inc)) (range start (inc period)))
|
||||||
;(println)
|
;(println)
|
||||||
@@ -27,8 +28,8 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn- print-confinuous
|
(defn- print-confinuous
|
||||||
([secret] (print-confinuous secret "sha1" 6 30 true))
|
([secret] (print-confinuous secret "sha1" 6 30 true DEFAULT_BAR_STYLE))
|
||||||
([secret algorithm digits period bar]
|
([secret algorithm digits period bar bar-style]
|
||||||
(let [step-millis (* 1000 period)
|
(let [step-millis (* 1000 period)
|
||||||
now (System/currentTimeMillis)
|
now (System/currentTimeMillis)
|
||||||
delay (int (- step-millis (rem now step-millis)))
|
delay (int (- step-millis (rem now step-millis)))
|
||||||
@@ -39,9 +40,9 @@
|
|||||||
task (proxy [TimerTask] []
|
task (proxy [TimerTask] []
|
||||||
(run [] (println) (fn-show secret)))
|
(run [] (println) (fn-show secret)))
|
||||||
task-bar (proxy [TimerTask] []
|
task-bar (proxy [TimerTask] []
|
||||||
(run [] (print-timer)))
|
(run [] (print-timer bar-style)))
|
||||||
task-init (proxy [TimerTask] []
|
task-init (proxy [TimerTask] []
|
||||||
(run [] (print-timer (- period delay-sec) period)))]
|
(run [] (print-timer (- period delay-sec) period bar-style)))]
|
||||||
(println "\n <Generating continuosly, press enter to stop>\n")
|
(println "\n <Generating continuosly, press enter to stop>\n")
|
||||||
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
|
;; (println "Now:" now ", Delay:" delay ", Next execution: " (+ now delay))
|
||||||
(println "Refresing in" delay-sec "seconds")
|
(println "Refresing in" delay-sec "seconds")
|
||||||
@@ -56,10 +57,10 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn cmd-generate
|
(defn cmd-generate
|
||||||
[& {:keys [secret continuous algorithm digits period bar]}]
|
[& {:keys [secret continuous algorithm digits period bar bar-style]}]
|
||||||
;;(pp/pprint opts)
|
;;(pp/pprint opts)
|
||||||
(if continuous
|
(if continuous
|
||||||
(print-confinuous secret algorithm digits period bar)
|
(print-confinuous secret algorithm digits period bar bar-style)
|
||||||
(println (get-otp secret algorithm digits period))))
|
(println (get-otp secret algorithm digits period))))
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn cmd-get-multi
|
(defn cmd-get-multi
|
||||||
[& {:keys [continuous bar _arguments]}]
|
[& {:keys [continuous bar bar-style _arguments]}]
|
||||||
;(pp/pprint opts)
|
;(pp/pprint opts)
|
||||||
(with-config
|
(with-config
|
||||||
(let [apps (filter some? #_{:clj-kondo/ignore [:unresolved-symbol]}
|
(let [apps (filter some? #_{:clj-kondo/ignore [:unresolved-symbol]}
|
||||||
@@ -109,9 +110,9 @@
|
|||||||
delay (int (- step-millis (rem now step-millis)))
|
delay (int (- step-millis (rem now step-millis)))
|
||||||
delay-sec (int (/ delay 1000))
|
delay-sec (int (/ delay 1000))
|
||||||
task-bar (proxy [TimerTask] []
|
task-bar (proxy [TimerTask] []
|
||||||
(run [] (print-timer)))
|
(run [] (print-timer bar-style)))
|
||||||
task-init (proxy [TimerTask] []
|
task-init (proxy [TimerTask] []
|
||||||
(run [] (print-timer (- period delay-sec) period)))]
|
(run [] (print-timer (- period delay-sec) period bar-style)))]
|
||||||
(print-app-continuous period apps)
|
(print-app-continuous period apps)
|
||||||
(when bar
|
(when bar
|
||||||
(. (new Timer) (schedule task-init 0))
|
(. (new Timer) (schedule task-init 0))
|
||||||
@@ -232,7 +233,11 @@
|
|||||||
{:option "bar" :short "b"
|
{:option "bar" :short "b"
|
||||||
:as "Show progress bar"
|
:as "Show progress bar"
|
||||||
:type :with-flag
|
:type :with-flag
|
||||||
:default true}]
|
:default true}
|
||||||
|
{:option "bar-style" :short "s"
|
||||||
|
:as "Progress bar style"
|
||||||
|
:type #{:ascii-basic :ascii-boxes :coloured-ascii-boxes :emoji-circles :emoji-boxes}
|
||||||
|
:default :coloured-ascii-boxes}]
|
||||||
:runs cmd-generate}
|
:runs cmd-generate}
|
||||||
;; Generate a TOTP for a configured app
|
;; Generate a TOTP for a configured app
|
||||||
{:command "get" :short "g"
|
{:command "get" :short "g"
|
||||||
@@ -252,7 +257,11 @@
|
|||||||
{:option "bar" :short "b"
|
{:option "bar" :short "b"
|
||||||
:as "Show progress bar"
|
:as "Show progress bar"
|
||||||
:type :with-flag
|
:type :with-flag
|
||||||
:default true}]
|
:default true}
|
||||||
|
{:option "bar-style" :short "s"
|
||||||
|
:as "Progress bar style"
|
||||||
|
:type #{:ascii-basic :ascii-boxes :coloured-ascii-boxes :emoji-circles :emoji-boxes}
|
||||||
|
:default :coloured-ascii-boxes}]
|
||||||
:runs cmd-get-multi}
|
:runs cmd-get-multi}
|
||||||
;; Check and init your config file
|
;; Check and init your config file
|
||||||
{:command "config" :short "c"
|
{:command "config" :short "c"
|
||||||
|
|||||||
Reference in New Issue
Block a user