Skip to content

Commit

Permalink
Merge pull request #12 from Achiefs/11-add-packages
Browse files Browse the repository at this point in the history
Add package generation, package build tests, config improvements and more
  • Loading branch information
okynos authored Nov 19, 2021
2 parents 5060c92 + ed9c193 commit 3f4a832
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.rpm filter=lfs diff=lfs merge=lfs -text
*.deb filter=lfs diff=lfs merge=lfs -text
13 changes: 13 additions & 0 deletions .github/workflows/pkg-build-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Pkg build
on: [push]
jobs:
Pkg-build-ubuntu:
runs-on: ubuntu-20.04
steps:
- name: Check out repository code, branch='${{ github.ref }}'
uses: actions/checkout@v2
- name: Install required dependencies
run: sudo apt install -y curl devscripts equivs tar gcc
- name: Building package
run: cd pkg/deb && sudo ./builder.sh
- run: echo "Job's status is ${{ job.status }}."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# These are backup files generated by rustfmt
**/*.rs.bk
Cargo.lock

# Files generated by the software execution
fim.log
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ This software aims to improve the File integrity monitoring that we perform nowa
File integrity monitoring is a common task in a security environment that all world is demanding.
For that reason, we want to produce faster and easy to use open-source FIM tool improving similar functionality from Ossec.

## How to compile
## First steps: Package installation (RPM and DEB only)
To install FIM packages you only need to perform a few steps:
1. Download our last package from the packages repository, located at Github `fim/pkg/{rpm,deb}/repository/release`

2. Install with
RPM: `yum install fim-*.rpm`
DEB: `apt install $(pwd)/PACKAGE_NAME.deb`

3. You can start to work typing `sudo nohup fim` in your terminal
4. FIM software will start monitoring any activity on the default folders configured in `/etc/fim/config.yml` file.

5. If you want to test it you could launch `touch /tmp/file.txt` in your terminal then, take a look at `/usr/share/fim/events.json` file. It will store each produced event in JSON format.


## Contributing: How to compile
We suggest using the `Cargo` tool to get dependencies automatically downloaded
Steps:
```
cargo build --release
```

## Set up environment
### Set up environment
Linux
- Install git
- Install gcc
Expand Down
28 changes: 0 additions & 28 deletions config.yml

This file was deleted.

21 changes: 21 additions & 0 deletions config/linux/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.2.0

# Monitor folder or files in unix.
monitor:
- path: /tmp/
- path: /bin/
- path: /usr/bin/
- path: /etc

# Path to output and events files:
# output to write app log.
# events to write monitorized folder/files events.
log:
output:
file: /var/log/fim/fim.log
# Possible levels debug, info, error, warning
level: debug
events:
file: /usr/share/fim/events.json
# Format of output events options json/syslog
format: json
21 changes: 21 additions & 0 deletions config/windows/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.2.0

# Monitor folder or files in windows.
monitor:
- path: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
- path: C:\Program Files\
- path: C:\Users\
- path: C:\Windows\Temp\

# Path to output and events files:
# output to write app log.
# events to write monitorized folder/files events.
log:
output:
file: C:\ProgramData\fim\fim.log
# Possible levels debug, info, error, warning
level: debug
events:
file: C:\ProgramData\fim\events.json
# Format of output events options json/syslog
format: json
33 changes: 33 additions & 0 deletions pkg/deb/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# Dependencies: curl, devscripts, equivs, tar, gcc
set -ex

brand="fim"
target_dir=$(pwd)
architecture="amd64"
base_dir="${target_dir}/../../"
version="$(head -n1 ${base_dir}/config/linux/config.yml | cut -d' ' -f2)"
release="1"

# Build directories
build_dir="/tmp/${brand}"
pkg_name="${brand}_${version}-${release}"
sources_dir="${build_dir}/${pkg_name}"
pkg_dir="${sources_dir}/pkg/deb"

mkdir -p ${sources_dir}
cp -R ${base_dir}/* ${sources_dir}/

# Generating directory structure to build the .deb package
cd ${build_dir} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}"

# Installing build dependencies
cd ${pkg_dir}
mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y"

# Build package
debuild -b -uc -us

full_pkg_name="${pkg_name}_${architecture}.deb"
mv "${pkg_dir}/../${full_pkg_name}" ${target_dir}/
rm -rf ${build_dir}
13 changes: 13 additions & 0 deletions pkg/deb/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fim (0.2.0-1) devel; urgency=medium

* Initial release
* More info: https://github.com/Achiefs/fim/releases/tag/v0.2.0

-- Jose Fernandez <[email protected]> Sat, 09 Oct 2021 14:00:00 +0000

fim (0.1.0-1) UNRELEASED; urgency=medium

* Closes itp bug
* More info: https://github.com/Achiefs/fim/releases/tag/v0.1.0

-- Jose Fernandez <[email protected]> Thu, 07 Oct 2021 22:45:00 +0000
1 change: 1 addition & 0 deletions pkg/deb/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
14 changes: 14 additions & 0 deletions pkg/deb/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source: fim
Section: admin
Priority: optional
Maintainer: Jose Fernandez <[email protected]>
Build-Depends: debhelper (>=10)
Standards-Version: 4.0.0
Homepage: https://github.com/Achiefs/fim

Package: fim
Architecture: any
Depends: ${shlibs:Depends}
Description: This software helps you to monitor your files of any unwanted action.
With FIM you could take a deep eye into your files
and know when they are exactly changed.
27 changes: 27 additions & 0 deletions pkg/deb/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This work was packaged for Debian by:

Jose Fernandez <[email protected]> on Thu, 07 Oct 2021 22:45:00 +0000

It was downloaded from:

https://github.com/Achiefs/fim/releases

Upstream Authors:

[email protected]
[email protected]

Copyright:

GNU General Public License version 3.

License:

GNU General Public License version 3.

The Debian packaging is:

Copyright (C) 2021 Achiefs <[email protected]>

and is licensed under the GPL version 3,
see "/usr/share/common-licenses/GPL-3".
21 changes: 21 additions & 0 deletions pkg/deb/debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e

INSTALL_DIR="/usr/local"

case "$1" in
remove|failed-upgrade|abort-install|abort-upgrade|disappear)
rm -rf ${INSTALL_DIR}/bin/fim
rm -rf ${INSTALL_DIR}/etc/fim/config.yml
;;

upgrade)
;;

*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac

exit 0
44 changes: 44 additions & 0 deletions pkg/deb/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

# Package build options
export BUILD_DIR="../.."
export TARGET_DIR="${CURDIR}/debian/fim"
export PKG_DIR="${TARGET_DIR}/usr"
export CONFIG_DIR="${TARGET_DIR}/etc/fim"
export BIN_DIR="${PKG_DIR}/bin"
export DOC_DIR="${PKG_DIR}/share/doc/fim"

%:
dh $@

override_dh_clean:

override_dh_install:
curl https://sh.rustup.rs -sSf | sh -s -- -y

echo ${CURDIR}
${HOME}/.cargo/bin/cargo build --release

mkdir -p ${CONFIG_DIR}
mkdir -p ${BIN_DIR}
mkdir -p ${DOC_DIR}
install -m 0750 ${BUILD_DIR}/target/release/fim ${BIN_DIR}/
install -m 0640 ${BUILD_DIR}/config/linux/config.yml ${CONFIG_DIR}/
install -m 0640 ${BUILD_DIR}/pkg/deb/debian/copyright ${DOC_DIR}/
install -m 0640 ${BUILD_DIR}/pkg/deb/debian/changelog ${DOC_DIR}/

override_dh_installdocs:

override_dh_installchangelogs:

override_dh_perl:

override_dh_link:

.PHONY: override_dh_clean override_dh_install override_dh_installdocs override_dh_installchangelogs override_dh_perl override_dh_link
3 changes: 3 additions & 0 deletions pkg/deb/repository/release/fim_0.2.0-1_amd64.deb
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/deb/repository/test/fim_0.2.0-1_amd64.deb
Git LFS file not shown
36 changes: 36 additions & 0 deletions pkg/rpm/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# Dependencies: rpm-build, tar, gcc
set -ex

brand="fim"
current_dir=$(pwd)
architecture="x86_64"
rpmbuild="/usr/bin/rpmbuild"
version="$(head -n1 ../../config/linux/config.yml | cut -d' ' -f2)"
bin_path="/usr/bin"
config_path="/etc/${brand}"

# Build directories
build_dir="/tmp/fim"
pkg_name="${brand}-${version}"
sources_dir="${build_dir}/${pkg_name}"
rpm_build_dir="${build_dir}/rpmbuild"
mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

# Prepare the sources directory to build the source tar.gz
mkdir -p ${sources_dir}
cp -R ../../* ${sources_dir}

cp ${brand}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec

# Generating source tar.gz
cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}"
echo "%debug_package %{nil}" >> /root/.rpmmacros

# Building RPM
$rpmbuild --define "_topdir ${rpm_build_dir}" --define "_version ${version}" \
--define "_bindir ${bin_path}" --define "_configdir ${config_path}" \
--target ${architecture} -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec

cp ${rpm_build_dir}/RPMS/${architecture}/${brand}*.rpm ${current_dir}/
rm -rf ${build_dir}
57 changes: 57 additions & 0 deletions pkg/rpm/fim.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Summary: FIM software provides a easy way to watch your files.
Name: fim
Version: %{_version}
Release: 1
License: GPL
Group: System Environment/Daemons
Source0: %{name}-%{version}.tar.gz
URL: https://github.com/Achiefs/fim
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Vendor: Achiefs <[email protected]>
Packager: Jose Fernandez <[email protected]>
AutoReqProv: no
ExclusiveOS: linux

%description
FIM helps you to monitor your files of any unwanted action.

%prep
%setup -q
curl https://sh.rustup.rs -sSf | sh -s -- -y

%build
source $HOME/.cargo/env
cargo build --release

%install
mkdir -p -m 640 ${RPM_BUILD_ROOT}%{_configdir}
mkdir -p -m 640 ${RPM_BUILD_ROOT}%{_bindir}

install -m 0750 target/release/fim ${RPM_BUILD_ROOT}%{_bindir}/
install -m 0640 config/linux/config.yml ${RPM_BUILD_ROOT}%{_configdir}/

%pre
%post
%preun

%postun
# If the package is been uninstalled
if [ $1 = 0 ];then
# Remove lingering folders and files
rm -f %{_bindir}/%{name}
rm -rf %{_configdir}
fi

%clean
rm -fr %{buildroot}

%files
%defattr(-,root,root)
%attr(750, root, root) %{_bindir}/fim
%dir %attr(750, root, root) %{_configdir}
%attr(640, root, root) %{_configdir}/config.yml


%changelog
* Tue Oct 05 2021 support <[email protected]> - 0.2.0
- More info: https://github.com/Achiefs/fim/releases/tag/v0.2.0
3 changes: 3 additions & 0 deletions pkg/rpm/repository/release/fim-0.2.0-1.x86_64.rpm
Git LFS file not shown
Loading

0 comments on commit 3f4a832

Please sign in to comment.