From 45964da11600f3a284ad8a33235c7dd00116c531 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Wed, 5 Aug 2020 10:06:53 -0400 Subject: [PATCH] tools: add build tools and scripts This commit contains the files and the scripts which are necessary to build, package, and publish the LogDNA Agent for Linux, Win32 and Mac Systems. Some parts have been taken from [Gruntfile](https://github.com/logdna/logdna-agent/blob/master/Gruntfile.js) and some have been taken from the internal instances. Semver: patch Ref: LOG-5336, LOG-5337, LOG-5338, LOG-5339 --- .gitignore | 22 ++-- Dockerfile | 2 +- Gruntfile.js | 72 ------------ LICENSE | 21 ++++ LICENSE.md | 7 -- package.json | 4 - tools/README.md | 92 +++++++++++++++ .../darwin/com.logdna.logdna-agent.plist | 22 ++++ tools/files/darwin/logdna-agent.rb | 23 ++++ tools/files/darwin/mac-after-install | 3 + tools/files/darwin/uninstall-mac-agent | 9 ++ tools/files/linux/after-upgrade | 1 + tools/files/linux/before-remove | 1 + tools/files/linux/init-script | 108 ++++++++++++++++++ tools/files/linux/logrotate | 8 ++ logdna.gpg => tools/files/logdna.gpg | 0 tools/files/win32/VERIFICATION.txt | 17 +++ tools/files/win32/chocolateyBeforeModify.ps1 | 14 +++ tools/files/win32/chocolateyInstall.ps1 | 30 +++++ tools/files/win32/logdna-agent.nuspec | 34 ++++++ tools/files/win32/winTail.ps1 | 21 ++++ tools/scripts/darwin.sh | 71 ++++++++++++ tools/scripts/debian.sh | 71 ++++++++++++ tools/scripts/redhat.sh | 65 +++++++++++ tools/scripts/win32.sh | 47 ++++++++ 25 files changed, 667 insertions(+), 98 deletions(-) delete mode 100644 Gruntfile.js create mode 100644 LICENSE delete mode 100644 LICENSE.md create mode 100644 tools/README.md create mode 100644 tools/files/darwin/com.logdna.logdna-agent.plist create mode 100644 tools/files/darwin/logdna-agent.rb create mode 100644 tools/files/darwin/mac-after-install create mode 100755 tools/files/darwin/uninstall-mac-agent create mode 100644 tools/files/linux/after-upgrade create mode 100644 tools/files/linux/before-remove create mode 100755 tools/files/linux/init-script create mode 100644 tools/files/linux/logrotate rename logdna.gpg => tools/files/logdna.gpg (100%) create mode 100644 tools/files/win32/VERIFICATION.txt create mode 100644 tools/files/win32/chocolateyBeforeModify.ps1 create mode 100644 tools/files/win32/chocolateyInstall.ps1 create mode 100644 tools/files/win32/logdna-agent.nuspec create mode 100644 tools/files/win32/winTail.ps1 create mode 100644 tools/scripts/darwin.sh create mode 100644 tools/scripts/debian.sh create mode 100644 tools/scripts/redhat.sh create mode 100644 tools/scripts/win32.sh diff --git a/.gitignore b/.gitignore index 00ac3f60..a235188e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,20 @@ logs *.log +# dependencies +node_modules + # builds .build .builds -logdna-agent.exe tmp + +# packages **/*.deb **/*.rpm +**/*.exe +**/*.nupkg +**/*.pkg # Test directory .temp @@ -24,22 +31,9 @@ lib-cov # Coverage directory used by tools like istanbul coverage -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - # node-waf configuration .lock-wscript -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git -node_modules -./logdna-agent -*.pkg -*.tgz - # Some extra data package-lock.json *~ diff --git a/Dockerfile b/Dockerfile index f805871e..1fcb8f44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ LABEL org.label-schema.vcs-url="https://github.com/logdna/logdna-agent" LABEL org.label-schema.vendor="LogDNA Inc." LABEL org.label-schema.docker.cmd="docker run logdna/logdna-agent:latest" -COPY logdna.gpg /etc/ +COPY tools/files/logdna.gpg /etc/ RUN echo "deb http://repo.logdna.com stable main" > /etc/apt/sources.list.d/logdna.list && \ apt-key add /etc/logdna.gpg && \ diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index ec5bf257..00000000 --- a/Gruntfile.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict' - -const pkg = require('./package.json') -const grunt = require('grunt') -const os = require('os') - -require('load-grunt-tasks')(grunt) - -module.exports = (grunt) => { - const buildOutputFile = os.platform() !== 'win32' ? 'logdna-agent' : 'logdna-agent.exe' - - grunt.initConfig({ - exec: { - nexe: {cmd: `nexe -i index.js -o ${buildOutputFile} -f -t ~/tmp -r 8.3.0`, maxBuffer: 20000 * 1024} - , fpm_rpm: `fpm -s dir -t rpm -n logdna-agent -v ${pkg.version} --license MIT --vendor 'LogDNA, Inc.' ` - + '--description \'LogDNA Agent for Debian\' --url http://logdna.com/ -m \'\' ' - + '--before-remove ./scripts/linux/files/before-remove --after-upgrade ./scripts/linux/files/after-upgrade -f ' - + './logdna-agent=/usr/bin/logdna-agent ./scripts/linux/files/init-script=/etc/init.d/logdna-agent ' - + './scripts/linux/files/logrotate=/etc/logrotate.d/logdna-agent' - , fpm_deb: `fpm -s dir -t deb -n logdna-agent -v ${pkg.version} --license MIT --vendor 'LogDNA, Inc.' ` - + '--description \'LogDNA Agent for RedHat\' --url http://logdna.com/ -m \'\' ' - + '--before-remove ./scripts/linux/files/before-remove --after-upgrade ./scripts/linux/files/after-upgrade -f ' - + '--deb-no-default-config-files ./logdna-agent=/usr/bin/logdna-agent ./scripts/linux/files/init-script=/etc/init.d/logdna-agent ' - + './scripts/linux/files/logrotate=/etc/logrotate.d/logdna-agent' - , fpm_pkg: `fpm -s dir -t osxpkg -n logdna-agent -v ${pkg.version} --license MIT --vendor 'LogDNA, Inc.' ` - + '--description \'LogDNA Agent for Darwin\' --url http://logdna.com/ -m \'\' ' - + '--after-install ./scripts/macOS/mac-after-install --osxpkg-identifier-prefix com.logdna -f ' - + './logdna-agent=/usr/local/bin/logdna-agent ./scripts/macOS/com.logdna.logdna-agent.plist=' - + '/Library/LaunchDaemons/com.logdna.logdna-agent.plist' - , sign_pkg: `productsign --sign "Developer ID Installer: Answerbook, Inc. (TT7664HMU3)" logdna-agent-${pkg.version}.pkg logdna-agent.pkg` - , choco: 'pushd .\\.builds\\windows & cpack' - - }, copy: { - nuspec: { - files: [{ - src: './logdna-agent.nuspec' - , dest: './.builds/windows/' - }] - }, winexe: { - files: [{ - src: './logdna-agent.exe' - , dest: './.builds/windows/tools/' - }] - }, windowsScripts: { - files: [{ - src: './scripts/windows/chocolateyInstall.ps1' - , dest: './.builds/windows/tools/chocolateyInstall.ps1' - }, { - src: './scripts/windows/winTail.ps1' - , dest: './.builds/windows/tools/winTail.ps1' - }, { - src: './license.txt' - , dest: './.builds/windows/tools/license.txt' - }, { - src: './verification.txt' - , dest: './.builds/windows/tools/verification.txt' - }] - } - - } - }) - - grunt.registerTask('linux', ['exec:nexe', 'exec:fpm_rpm', 'exec:fpm_deb']) - grunt.registerTask('mac', ['exec:nexe', 'exec:fpm_pkg', 'exec:sign_pkg']) - grunt.registerTask('windows', [ - 'exec:nexe' - , 'copy:nuspec' - , 'copy:winexe' - , 'copy:windowsScripts' - , 'exec:choco' - ]) -} diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8267176a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 LogDNA + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 062e2e01..00000000 --- a/LICENSE.md +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2016-2018 LogDNA, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/package.json b/package.json index 57ba190e..58d1a3b6 100644 --- a/package.json +++ b/package.json @@ -47,10 +47,6 @@ "eslint": "^7.6.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-sensible": "^2.2.0", - "grunt": "^1.0.4", - "grunt-contrib-copy": "^1.0.0", - "grunt-exec": "^3.0.0", - "load-grunt-tasks": "^5.1.0", "tap": "^14.10.8" } } diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 00000000..a950d757 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,92 @@ +# How to Build + +## Requirements +- Update the [`CHANGELOG`](../CHANGELOG.md) +- Update the `version` in [`package.json`](../package.json#L3) +- Update the `version` in [`logdna-agent.rb`](./files/darwin/logdna-agent.rb#L2) +- Update the `version` in [`logdna-agent.nuspec`](./files/win32/logdna-agent.nuspec#L7) + +## LogDNA Agent for Debian Systems +LogDNA Agent can be built and released for Debian systems by running the `scripts/debian.sh` script: +`bash tools/scripts/debian.sh` + +### Dependencies +- `Node.js: v8.3.0` and `NPM: v5.3.0` +- `NEXE: v3.3.3` by `npm install -g nexe@3.3.3` +- `fpm` by `sudo gem install --no-document fpm` +- `ghr` by `go get -u github.com/tcnksm/ghr` +- `deb-s3` by `sudo gem install deb-s3` + +### Environment Variables +- `AWS_ACCESS_KEY` +- `AWS_SECRET_KEY` +- `GITHUB_API_TOKEN` + +### Steps +1. Compile the source code into the executable +2. Package the executable into the Debian package +3. Create / Update the GitHub Release for the specified tag by uploading the Debian package +4. Publish the Debian package into the specified S3 bucket + +## LogDNA Agent for RedHat Systems +LogDNA Agent can be built and released for RedHat systems by running the `scripts/redhat.sh` script from the project directory: +`bash tools/scripts/redhat.sh` + +### Dependencies +- `Node.js: v8.3.0` and `NPM: v5.3.0` +- `NEXE: v3.3.3` by `npm install -g nexe@3.3.3` +- `fpm` by `sudo gem install --no-document fpm` +- `ghr` by `go get -u github.com/tcnksm/ghr` +- `rpm-s3` by `git clone https://github.com/crohr/rpm-s3 --recurse-submodules` + +### Environment Variables +- `AWS_ACCESS_KEY` +- `AWS_SECRET_KEY` +- `GITHUB_API_TOKEN` + +### Steps +1. Compile the source code into the executable +2. Package the executable into the RedHat package +3. Create / Update the GitHub Release for the specified tag by uploading the RedHat package +4. Publish the RedHat package into the specified S3 bucket + +## LogDNA Agent for Darwin Systems +LogDNA Agent can be built and released for Darwin systems by running the `scripts/darwin.sh` script from the project directory: +`bash tools/scripts/darwin.sh` + +### Dependencies +- `Node.js: v8.3.0` and `NPM: v5.3.0` +- `NEXE: v3.3.3` by `npm install -g nexe@3.3.3` +- `fpm` by `sudo gem install --no-document fpm` +- `ghr` by `brew install ghr` + +### Environment Variables +- `GITHUB_API_TOKEN` + +### Steps +1. Compile the source code into the executable +2. Package the executable into the MacOSX package +3. Create / Update the GitHub Release for the specified tag by uploading the MacOSX package +4. Sign the MacOSX package using the private keychain +5. Publish the MacOSX package by creating a Pull Request to update [logdna-agent.rb](https://github.com/Homebrew/homebrew-cask/blob/master/Casks/logdna-agent.rb) using [logdna-bot/homebrew-cask](https://github.com/logdnabot/homebrew-cask) + +## LogDNA Agent for Win32 Systems +LogDNA Agent can be built and released for Win32 systems by running the `scripts/win32.sh` script from the project directory: +`./tools/scripts/win32.sh` + +### Dependencies +- `choco` by `iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))` on `PowerShell` +- `nssm` by `choco install -y nssm` +- `Node.js: v8.3.0` and `NPM: v5.3.0` by `choco install nodejs --version=8.3.0` +- `NEXE: v3.3.3` by `npm install -g nexe@3.3.3` +- `ghr` by `go get -u github.com/tcnksm/ghr` + +### Environment Variables +- `GITHUB_API_TOKEN` +- `CHOCO_API_KEY` + +### Steps +1. Compile the source code into the executable +2. Package the executable into the NuPKG package +3. Create / Update the GitHub Release for the specified tag by uploading the NuPKG package +4. Publish the NuPKG package into [Chocolatey](https://chocolatey.org/packages/logdna-agent) diff --git a/tools/files/darwin/com.logdna.logdna-agent.plist b/tools/files/darwin/com.logdna.logdna-agent.plist new file mode 100644 index 00000000..ddf30be4 --- /dev/null +++ b/tools/files/darwin/com.logdna.logdna-agent.plist @@ -0,0 +1,22 @@ + + + + + Disabled + + KeepAlive + + Label + com.logdna.logdna-agentd + ProgramArguments + + /usr/local/bin/logdna-agent + + RunAtLoad + + StandardErrorPath + /Library/Logs/logdna-agent.log + StandardOutPath + /Library/Logs/logdna-agent.log + + diff --git a/tools/files/darwin/logdna-agent.rb b/tools/files/darwin/logdna-agent.rb new file mode 100644 index 00000000..1b4d2877 --- /dev/null +++ b/tools/files/darwin/logdna-agent.rb @@ -0,0 +1,23 @@ +cask 'logdna-agent' do + version '1.6.2' + sha256 '350956cbeddf0f0b1cf991a58d659e2a4c2344b621370e10c8adb950f9c6bc47' + + # github.com/logdna/logdna-agent was verified as official when first introduced to the cask + url "https://github.com/logdna/logdna-agent/releases/download/#{version}/logdna-agent-#{version}.pkg" + appcast 'https://github.com/logdna/logdna-agent/releases.atom' + name 'LogDNA Agent' + homepage 'https://logdna.com/' + + pkg "logdna-agent-#{version}.pkg" + + uninstall pkgutil: 'com.logdna.logdna-agent', + launchctl: 'com.logdna.logdna-agentd' + + caveats <<~EOS + When you first start logdna-agent, you must set your LogDNA API key with the command: + sudo logdna-agent -k + + To always run logdna-agent in the background, use the command: + sudo launchctl load -w /Library/LaunchDaemons/com.logdna.logdna-agent.plist + EOS +end diff --git a/tools/files/darwin/mac-after-install b/tools/files/darwin/mac-after-install new file mode 100644 index 00000000..5390fdbe --- /dev/null +++ b/tools/files/darwin/mac-after-install @@ -0,0 +1,3 @@ +#!/bin/bash +sudo chown root:wheel /Library/LaunchDaemons/com.logdna.logdna-agent.plist +sudo chmod 644 /Library/LaunchDaemons/com.logdna.logdna-agent.plist diff --git a/tools/files/darwin/uninstall-mac-agent b/tools/files/darwin/uninstall-mac-agent new file mode 100755 index 00000000..cc9dcead --- /dev/null +++ b/tools/files/darwin/uninstall-mac-agent @@ -0,0 +1,9 @@ +#!/bin/bash +if sudo /bin/launchctl list com.logdna.logdna-agentd &> /dev/null; then + sudo /bin/launchctl unload "/Library/LaunchDaemons/com.logdna.logdna-agent.plist" +fi + +sudo pkill -f logdna-agent + +( cd / ; sudo pkgutil --only-files --files com.logdna.logdna-agent | tr '\n' '\0' | xargs -n 1 -0 sudo rm -if ) +sudo pkgutil --forget com.logdna.logdna-agent diff --git a/tools/files/linux/after-upgrade b/tools/files/linux/after-upgrade new file mode 100644 index 00000000..ae1d286b --- /dev/null +++ b/tools/files/linux/after-upgrade @@ -0,0 +1 @@ +/etc/init.d/logdna-agent restart diff --git a/tools/files/linux/before-remove b/tools/files/linux/before-remove new file mode 100644 index 00000000..f5034382 --- /dev/null +++ b/tools/files/linux/before-remove @@ -0,0 +1 @@ +/etc/init.d/logdna-agent stop diff --git a/tools/files/linux/init-script b/tools/files/linux/init-script new file mode 100755 index 00000000..812c95f5 --- /dev/null +++ b/tools/files/linux/init-script @@ -0,0 +1,108 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: logdna-agent +# Required-Start: $remote_fs $network $syslog +# Required-Stop: $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts LogDNA Agent at boot +# Description: Enables LogDNA Agent service. +### END INIT INFO + +if [ $(id -u) -ne 0 ]; then + echo "Error: This program can only be used by the root user." + exit 1 +fi + +name="logdna-agent" +cmd="/usr/bin/logdna-agent" +pid_file="/var/run/$name.pid" +stdout_log="/var/log/$name.log" +conf_file="/etc/logdna.conf" + +if [ -f /etc/sysconfig/$name ]; then + . /etc/sysconfig/$name +fi + +get_pid() { + cat "$pid_file" +} + +is_running() { + [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1 +} + +case "$1" in + start) + if is_running; then + echo "Already started" + else + if [ ! -f "$conf_file" ]; then + echo "Error: LogDNA Ingestion Key not set! Use $name -k to set or $name -h for help." + exit 1 + fi + + chmod 0644 /etc/logrotate.d/logdna-agent > /dev/null 2>&1 + + echo "Starting $name..." + $cmd >> "$stdout_log" 2>&1 & + echo $! > "$pid_file" + if ! is_running; then + echo "Unable to start" + echo "Unable to start" >> $stdout_log + exit 1 + fi + fi + ;; + stop) + if is_running; then + echo -n "Stopping $name..." + kill `get_pid` + for i in {1..10} + do + if ! is_running; then + break + fi + + echo -n "." + sleep 1 + done + echo + + if is_running; then + echo "Not stopped; may still be shutting down or shutdown may have failed" + echo "Not stopped; may still be shutting down or shutdown may have failed" >> $stdout_log + exit 1 + else + echo "Stopped" + if [ -f "$pid_file" ]; then + rm "$pid_file" + fi + fi + else + echo "Not running" + fi + ;; + restart) + $0 stop + if is_running; then + echo "Unable to stop, will not attempt to start" + exit 1 + fi + $0 start + ;; + status) + if is_running; then + echo "Running" + else + echo "Stopped" + exit 1 + fi + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/tools/files/linux/logrotate b/tools/files/linux/logrotate new file mode 100644 index 00000000..5c0eadd0 --- /dev/null +++ b/tools/files/linux/logrotate @@ -0,0 +1,8 @@ +/var/log/logdna-agent.log { + rotate 7 + daily + missingok + notifempty + copytruncate + compress +} diff --git a/logdna.gpg b/tools/files/logdna.gpg similarity index 100% rename from logdna.gpg rename to tools/files/logdna.gpg diff --git a/tools/files/win32/VERIFICATION.txt b/tools/files/win32/VERIFICATION.txt new file mode 100644 index 00000000..4a6b77fe --- /dev/null +++ b/tools/files/win32/VERIFICATION.txt @@ -0,0 +1,17 @@ +VERIFICATION + +Verification is intended to assist the Chocolatey moderators and community +in verifying that this package's contents are trustworthy. + +To verify logdna-agent.exe: +1. Download +2. You can use one of the following methods to calculate the checksum + - Use powershell function 'Get-Filehash' + - Use chocolatey utility 'checksum.exe' + + checksum type: sha256 + checksum: 9daf22c15f4f42e8c7ac4cdf73c26f7154d325d0defe14ece18d1203a9c7afd1 + +This package is published by LogDNA. You can build a binary directly +by following the instructions here: +https://github.com/logdna/logdna-agent/blob/master/CONTRIBUTING.md \ No newline at end of file diff --git a/tools/files/win32/chocolateyBeforeModify.ps1 b/tools/files/win32/chocolateyBeforeModify.ps1 new file mode 100644 index 00000000..7b4cc2b7 --- /dev/null +++ b/tools/files/win32/chocolateyBeforeModify.ps1 @@ -0,0 +1,14 @@ +$packageParameters = $env:chocolateyPackageParameters + +IF(!($packageParameters)) +{ + cmd.exe /c "nssm.exe stop logdna-agent & exit /b 0" + cmd.exe /c "nssm.exe remove logdna-agent confirm & exit /b 0" +} + +$registryPath = "HKLM:\SYSTEM\CurrentControlSet\Services\logdna-agent" + +IF(Test-Path $registryPath) +{ + Remove-Item -Path $registryPath -Force -Recurse +} diff --git a/tools/files/win32/chocolateyInstall.ps1 b/tools/files/win32/chocolateyInstall.ps1 new file mode 100644 index 00000000..1d9af7e0 --- /dev/null +++ b/tools/files/win32/chocolateyInstall.ps1 @@ -0,0 +1,30 @@ +$packageParameters = $env:chocolateyPackageParameters + +IF(!($packageParameters)) +{ + if(!(Test-Path -Path $env:ALLUSERSPROFILE\logs)){ + New-Item -ItemType directory -Path $env:ALLUSERSPROFILE\logs -Force + } + if(!(Test-Path -Path $env:ALLUSERSPROFILE\logs\logdna-agent.log)){ + New-Item -ItemType file -Path $env:ALLUSERSPROFILE\logs\logdna-agent.log -Force + } + if(!(Test-Path -Path $env:ALLUSERSPROFILE\logdna)){ + New-Item -ItemType directory -Path $env:ALLUSERSPROFILE\logdna -Force + } + if(Test-Path -Path $env:ALLUSERSPROFILE\logdna\winTail.ps1){ + Remove-Item $env:ALLUSERSPROFILE\logdna\winTail.ps1 -Force + } + Copy-Item $PSScriptRoot\winTail.ps1 -Destination $env:ALLUSERSPROFILE\logdna\winTail.ps1 -Force + cmd.exe /c "nssm.exe install logdna-agent $env:ChocolateyInstall\bin\logdna-agent.exe & exit /b 0" + cmd.exe /c "nssm.exe set logdna-agent AppStdout $env:ALLUSERSPROFILE\logs\logdna-agent.log & exit /b 0" + cmd.exe /c "nssm.exe set logdna-agent AppStderr $env:ALLUSERSPROFILE\logs\logdna-agent.log & exit /b 0" +} + +$registryPath = "HKLM:\SYSTEM\CurrentControlSet\Services\logdna-agent\Parameters" + +IF(!(Test-Path $registryPath)) +{ + New-Item -Path $registryPath -Force +} + +New-ItemProperty -Path $registryPath -Name 'AppStopMethodSkip' -Value 0xe -PropertyType DWORD -Force diff --git a/tools/files/win32/logdna-agent.nuspec b/tools/files/win32/logdna-agent.nuspec new file mode 100644 index 00000000..0f3167b4 --- /dev/null +++ b/tools/files/win32/logdna-agent.nuspec @@ -0,0 +1,34 @@ + + + + + logdna-agent + LogDNA Agent for Windows + 1.6.3 + smusali,leeliu + leeliu + LogDNA Agent for Windows + 1.6.3 + smusali,leeliu + leeliu + LogDNA Agent for Windows + LogDNA Collector Agent Streaming File and Event Logs to LogDNA. + https://logdna.com/ + https://github.com/logdna/logdna-agent + https://github.com/logdna/logdna-agent + https://github.com/logdna/logdna-agent + https://github.com/logdna/logdna-agent/issues + logdna-agent winevent tail logging devops logdna + Copyright 2020 LogDNA, Inc. + https://github.com/logdna/logdna-agent/blob/master/LICENSE.md + false + https://github.com/logdna/artwork/raw/master/ld-logo-square-480.png + LogDNA Agent for Windows + + + + + + + + diff --git a/tools/files/win32/winTail.ps1 b/tools/files/win32/winTail.ps1 new file mode 100644 index 00000000..ee32cd22 --- /dev/null +++ b/tools/files/win32/winTail.ps1 @@ -0,0 +1,21 @@ +Set-PSDebug -Strict +$LogName = $args[0] +$curr = (Get-EventLog -LogName $LogName -Newest 1 2> $null).Index +if ([string]::IsNullOrEmpty($curr)) +{ + $curr = -1 +} +while ($true) +{ + start-sleep -Seconds 1 + $next = (Get-EventLog -LogName $LogName -Newest 1 2> $null).Index + if ([string]::IsNullOrEmpty($next)) + { + $next = -1 + } + if ($next -gt $curr) { + $data = Get-EventLog -LogName $LogName -Newest ($next - $curr + 1000) 2> $null | where {$_.Index -gt $curr} + $curr = $data[-1].Index + $data | ConvertTo-Json + } +} diff --git a/tools/scripts/darwin.sh b/tools/scripts/darwin.sh new file mode 100644 index 00000000..8048e728 --- /dev/null +++ b/tools/scripts/darwin.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# THIS SHOULD RUN ON MACOSX FROM THE PROJECT DIRECTORY + +# VARIABLES +ARCH=x64 +INPUT_TYPE=dir +LICENSE=MIT +NODE_VERSION=8.3.0 # Will upgrade after 1.6.5 +OSXPKG_IDENTIFIER_PREFIX=com.logdna +OUTPUT_TYPE=osxpkg +PACKAGE_NAME=logdna-agent +S3_BUCKET=repo.logdna.com +VERSION=$(cat tools/files/darwin/logdna-agent.rb | grep "version '" | cut -d"'" -f2) + +# PAUSE FUNCTION +function pause(){ + read -s -n 1 -p "Press any key to continue . . ." +} + +# PREPARE FOLDER AND FILES +mkdir -p .build/ .pkg/ +cp \ + tools/files/darwin/com.logdna.logdna-agent.plist \ + tools/files/darwin/mac-after-install \ + tools/files/darwin/uninstall-mac-agent \ + .build/ + +# STEP 1: COMPILE AND BUILD EXECUTABLE +npm install --production +nexe -i index.js -o .build/${PACKAGE_NAME} -t darwin-${ARCH}-${NODE_VERSION} + +# STEP 2: PACKAGE +cd .build/ +fpm \ + --input-type ${INPUT_TYPE} \ + --output-type ${OUTPUT_TYPE} \ + --name ${PACKAGE_NAME} \ + --version ${VERSION} \ + --license ${LICENSE} \ + --vendor "LogDNA, Inc." \ + --description "LogDNA Agent for Darwin" \ + --url "https://logdna.com/" \ + --maintainer "LogDNA " \ + --after-install ./mac-after-install \ + --osxpkg-identifier-prefix ${OSXPKG_IDENTIFIER_PREFIX} \ + --force \ + ./logdna-agent=/usr/local/bin/logdna-agent \ + ./com.logdna.logdna-agent.plist=/Library/LaunchDaemons/com.logdna.logdna-agent.plist + +# STEP 3: SIGN THE PACKAGE +cd ../.pkg +mv ../.build/logdna-agent-${VERSION}.pkg logdna-agent-${VERSION}-unsigned.pkg +productsign --sign "Developer ID Installer: Answerbook, Inc. (TT7664HMU3)" logdna-agent-${VERSION}-unsigned.pkg logdna-agent-${VERSION}.pkg +SHA256CHECKSUM=$(shasum -a 256 logdna-agent-${VERSION}.pkg | cut -d' ' -f1) +sed "s/$(cat ../tools/files/darwin/logdna-agent.rb | grep sha256 | cut -d"'" -f2)/${SHA256CHECKSUM}/" ../tools/files/darwin/logdna-agent.rb > logdna-agent.rb +cd .. + +# STEP 4: RELEASE +ghr -draft \ + -n "LogDNA Agent v${VERSION}" \ + -r ${PACKAGE_NAME} \ + -t ${GITHUB_API_TOKEN} \ + -u logdna \ + ${VERSION} .pkg/ + +# PAUSE TO GET APPROVAL +pause + +# STEP 5: PUBLISH +echo "Update logdna-agent.rb on https://github.com/logdnabot/homebrew-cask/blob/master/Casks/logdna-agent.rb" +echo "Create a Pull Request to update logdna-agent.rb on https://github.com/Homebrew/homebrew-cask/blob/master/Casks/logdna-agent.rb" diff --git a/tools/scripts/debian.sh b/tools/scripts/debian.sh new file mode 100644 index 00000000..87f53b2f --- /dev/null +++ b/tools/scripts/debian.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# THIS SHOULD RUN ON DEBIAN FROM THE PROJECT DIRECTORY + +# VARIABLES +ARCH=x64 +DEB_SIGNATURE_ID=EF506BE8 +INPUT_TYPE=dir +LICENSE=MIT +NODE_VERSION=8.3.0 # Will upgrade after 1.6.5 +OUTPUT_TYPE=deb +PACKAGE_NAME=logdna-agent +S3_BUCKET=repo.logdna.com +VERSION=$(cat ./package.json | grep version | cut -d'"' -f4) + +# PAUSE FUNCTION +function pause(){ + read -s -n 1 -p "Press any key to continue . . ." +} + +# PREPARE FOLDER AND FILES +mkdir -p .build/ .pkg/ +cp \ + tools/files/linux/before-remove \ + tools/files/linux/after-upgrade \ + tools/files/linux/init-script \ + tools/files/linux/logrotate \ + .build/ + +# STEP 1: COMPILE AND BUILD EXECUTABLE +npm install --production +nexe -i index.js -o .build/${PACKAGE_NAME} -t linux-${ARCH}-${NODE_VERSION} + +# STEP 2: PACKAGE +cd .build/ +fpm \ + --input-type ${INPUT_TYPE} \ + --output-type ${OUTPUT_TYPE} \ + --name ${PACKAGE_NAME} \ + --version ${VERSION} \ + --license ${LICENSE} \ + --vendor "LogDNA, Inc." \ + --description "LogDNA Agent for Linux" \ + --url "https://logdna.com/" \ + --maintainer "LogDNA " \ + --before-remove ./before-remove \ + --after-upgrade ./after-upgrade \ + --force --deb-no-default-config-files \ + ./${PACKAGE_NAME}=/usr/bin/${PACKAGE_NAME} \ + ./init-script=/etc/init.d/${PACKAGE_NAME} \ + ./logrotate=/etc/logrotate.d/${PACKAGE_NAME} +mv *.deb ../.pkg/ +cd .. + +# STEP 3: RELEASE +ghr -draft \ + -n "LogDNA Agent v${VERSION}" \ + -r ${PACKAGE_NAME} \ + -t ${GITHUB_API_TOKEN} \ + -u logdna \ + ${VERSION} .pkg/ + +# PAUSE TO GET APPROVAL +pause + +# STEP 4: PUBLISH +deb-s3 upload \ + --access-key-id=${AWS_ACCESS_KEY} \ + --gpg-options="--digest-algo SHA256" \ + --preserve-versions --bucket ${S3_BUCKET} \ + --secret-access-key=${AWS_SECRET_KEY} \ + --sign ${DEB_SIGNATURE_ID} ${PACKAGE_NAME}*${VERSION}*.deb diff --git a/tools/scripts/redhat.sh b/tools/scripts/redhat.sh new file mode 100644 index 00000000..aa56b7d1 --- /dev/null +++ b/tools/scripts/redhat.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# THIS SHOULD RUN ON REDHAT FROM THE PROJECT DIRECTORY + +# VARIABLES +ARCH=x64 +INPUT_TYPE=dir +LICENSE=MIT +NODE_VERSION=8.3.0 # Will upgrade after 1.6.5 +OUTPUT_TYPE=rpm +PACKAGE_NAME=logdna-agent +S3_BUCKET=repo.logdna.com +VERSION=$(cat ./package.json | grep version | cut -d'"' -f4) + +# PAUSE FUNCTION +function pause(){ + read -s -n 1 -p "Press any key to continue . . ." +} + +# PREPARE FOLDER AND FILES +mkdir -p .build/ +cp \ + tools/files/linux/before-remove \ + tools/files/linux/after-upgrade \ + tools/files/linux/init-script \ + tools/files/linux/logrotate \ + .build/ + +# STEP 1: COMPILE AND BUILD EXECUTABLE +npm install --production +nexe -i index.js -o .build/${PACKAGE_NAME} -t linux-${ARCH}-${NODE_VERSION} + +# STEP 2: PACKAGE +cd .build/ +fpm \ + --input-type ${INPUT_TYPE} \ + --output-type ${OUTPUT_TYPE} \ + --name ${PACKAGE_NAME} \ + --version ${VERSION} \ + --license ${LICENSE} \ + --vendor "LogDNA, Inc." \ + --description "LogDNA Agent for Linux" \ + --url "https://logdna.com/" \ + --maintainer "LogDNA " \ + --before-remove ./before-remove \ + --after-upgrade ./after-upgrade \ + --force \ + ./${PACKAGE_NAME}=/usr/bin/${PACKAGE_NAME} \ + ./init-script=/etc/init.d/${PACKAGE_NAME} \ + ./logrotate=/etc/logrotate.d/${PACKAGE_NAME} +mv *.rpm ../.pkg/ +cd .. + +# STEP 3: RELEASE +${HOME}/go/bin/ghr -draft \ + -n "LogDNA Agent v${VERSION}" \ + -r ${PACKAGE_NAME} \ + -t ${GITHUB_API_TOKEN} \ + -u logdna \ + ${VERSION} .pkg/ + +# PAUSE TO GET APPROVAL +pause + +# STEP 4: PUBLISH +AWS_ACCESS_KEY="${AWS_ACCESS_KEY}" AWS_SECRET_KEY="${AWS_SECRET_KEY}" ../rpm-s3/bin/rpm-s3 -v --sign -k 8 -p el6 -b ${S3_BUCKET} ${PACKAGE_NAME}*${VERSION}*.rpm diff --git a/tools/scripts/win32.sh b/tools/scripts/win32.sh new file mode 100644 index 00000000..346c1600 --- /dev/null +++ b/tools/scripts/win32.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# THIS SHOULD RUN ON WIN32 FROM THE PROJECT DIRECTORY + +# VARIABLES +ARCH=x64 +NODE_VERSION=8.3.0 # Will upgrade after 1.6.5 +PACKAGE_NAME=logdna-agent +VERSION=$(cat tools/files/win32/logdna-agent.nuspec | grep "" | cut -d'>' -f2 | cut -d'<' -f1) + +# PAUSE FUNCTION +function pause(){ + read -s -n 1 -p "Press any key to continue . . ." +} + +# PREPARE FOLDER AND FILES +mkdir -p .build/tools/ .pkg/ +cp tools/files/win32/logdna-agent.nuspec .build/ +cp LICENSE .build/tools/license.txt +cp tools/files/win32/*.ps1 tools/files/win32/*.txt .build/tools/ + +# STEP 1: COMPILE AND BUILD EXECUTABLE +npm install --production +nexe -i index.js -o .build/tools/${PACKAGE_NAME}.exe -t win32-${ARCH}-${NODE_VERSION} + +# STEP 2: PACKAGE +cd .build/ +sed -i "s/latest/${VERSION}/" tools/VERIFICATION.txt +SHA256CHECKSUM=$(shasum -a 256 tools/${PACKAGE_NAME}.exe | cut -d' ' -f1) +sed -i "s/$(cat tools/VERIFICATION.txt | grep 'checksum: ' | cut -d' ' -f4)/${SHA256CHECKSUM}/" tools/VERIFICATION.txt +choco pack logdna-agent.nuspec +cd .. +cp .build/*.nupkg .build/tools/*.exe .pkg/ + +# STEP 3: RELEASE +ghr -draft \ + -n "LogDNA Agent v${VERSION}" \ + -r ${PACKAGE_NAME} \ + -t ${GITHUB_API_TOKEN} \ + -u logdna \ + ${VERSION} .pkg/ + +# PAUSE TO GET APPROVAL +pause + +# STEP 4: PUBLISH +choco apikey --key ${CHOCO_API_KEY} --source https://push.chocolatey.org/ +choco push .pkg/*.nupkg --source https://push.chocolatey.org/