diff --git a/.goreleaser.yml b/.goreleaser.yml index b3b97f1..cf8a39c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -4,8 +4,11 @@ builds: - id: linux binary: checksec main: ./main.go - flags: -buildmode=pie - ldflags: -s -w + ldflags: + - -s -w + - -X "main.version={{ .Version }}" + - -X "main.commit={{ .Commit }}" + - -X "main.date={{ .Date }}" env: - CGO_ENABLED=0 goos: @@ -17,8 +20,11 @@ builds: - id: darwin binary: checksec main: ./main.go - flags: -buildmode=pie - ldflags: -s -w + ldflags: + - -s -w + - -X "main.version={{ .Version }}" + - -X "main.commit={{ .Commit }}" + - -X "main.date={{ .Date }}" env: - CGO_ENABLED=0 goos: @@ -30,6 +36,13 @@ builds: # - id: windows # binary: checksec # main: ./main.go + # ldflags: + # - -s -w + # - -X "main.version={{ .Version }}" + # - -X "main.commit={{ .Commit }}" + # - -X "main.date={{ .Date }}" + # env: + # - CGO_ENABLED=0 # goos: # - windows # goarch: diff --git a/cmd/root.go b/cmd/root.go index 27b1a7a..89ecde4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "github.com/spf13/cobra" @@ -17,6 +18,10 @@ var rootCmd = &cobra.Command{ Long: `A tool used to quickly survey mitigation technologies in use by processes on a Linux system.`, } +func SetVersionInfo(version, commit, date string) { + rootCmd.Version = fmt.Sprintf("%s (Built on %s from Git SHA %s)", version, date, commit) +} + // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { diff --git a/extras/zsh/README.md b/extras/zsh/README.md deleted file mode 100644 index e752821..0000000 --- a/extras/zsh/README.md +++ /dev/null @@ -1,2 +0,0 @@ -A completion file for zsh was added which can just be put into a directory of zsh's $fpath -(e.g. on gentoo into /usr/share/zsh/site-functions/) diff --git a/extras/zsh/_checksec b/extras/zsh/_checksec deleted file mode 100644 index bd91504..0000000 --- a/extras/zsh/_checksec +++ /dev/null @@ -1,39 +0,0 @@ -#compdef checksec -local curcontext="$curcontext" state state_descr line -typeset -A opt_args -_arguments -C : \ -'--version[print version]' \ -{'--help','--help'}'[print help]' \ -'--debug' \ -'--verbose' \ -{'--update','--upgrade'}'[update program]' \ -{'--format=','--output='}'[use specified output format]:output format:->format' \ -{'--dir=','--dir='}'[check specified DIR]:vdir:->vdir' \ -{'--file=','--file='}'[check specified FILE]:file to check:_files' \ -{'--proc=','--proc='}'[check specified process NAME)]:process name:->procname' \ -{'--proc-all','--proc-all'}'[check all processes]' \ -{'--proc-libs','--proc-libs'}'[check specified ID'\''s process libs)]:process ID to check: _pids' \ -{'--kernel','--kernel'}'[check kernel]' \ -{'--fortify-file=','--fortify-file='}'[check specified FILE for fortify)]:file for fortify:_files' \ -{'--fortify-proc=','--fortify-proc='}'[check specified ID'\''s process for fortify)]:process ID for fortify: _pids' -local ret=$? -case $state in -format) - local formats - formats=( - 'cli:use cli output format' - 'csv:use csv output format' - 'xml:use xml output format' - 'json:use json output format' - ) - _describe -t formats 'output format' formats - ret=$?;; -procname) - compadd "$expl[@]" ${${${${(f)"$(_call_program processes-names ps ${${EUID/(#s)0(#e)/xa}//[0-9]#/}ho command 2> /dev/null)"//[][\(\)]/}:#(ps|COMMAND|-*)}%%\ *}:t} - ret=$?;; -vdir) - compadd "$expl[@]" -v - _files -/ - ret=0;; -esac -return ret diff --git a/main.go b/main.go index b52e15e..abd2d2c 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,13 @@ package main import "github.com/slimm609/checksec/cmd" +var ( + version = "dev" + commit = "none" + date = "unknown" +) + func main() { + cmd.SetVersionInfo(version, commit, date) cmd.Execute() }