Skip to content

Commit

Permalink
feat(daemon): add service with ClamAV sidecars [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Nov 23, 2023
1 parent c2e7e12 commit 980353b
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ dist
!.yarn/sdks
!.yarn/versions

########################################
# Visual Studio Code

.vscode/*
!.vscode/extensions.json

########################################
# Custom

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "clamav"]
path = clamav
url = https://github.com/Cisco-Talos/clamav.git
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"recommendations": [
"coolbear.systemd-unit-file",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"idleberg.nsis",
"panicbit.cargo",
"tamasfe.even-better-toml",
"tauri-apps.tauri-vscode"
]
}
3 changes: 0 additions & 3 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
12 changes: 10 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [3. Webview with Yarn v3](#3-webview-with-yarn-v3)
- [4. Final Check](#4-final-check)
- [5. Optional requirements](#5-optional-requirements)
- [Debian-based OS](#debian-based-os)
- [Local development](#local-development)
- [Build a release](#build-a-release)
- [Binary (standalone)](#binary-standalone)
Expand Down Expand Up @@ -67,8 +68,7 @@ Then run:
```sh
git clone https://github.com/ivangabriele/clamav-desktop.git # or your fork
cd ./clamav-desktop
git submodule init
git submodule update
yarn setup # to init, install and update Husky hooks / Git submodules
```

#### 2. Core with Tauri & tauri-driver
Expand Down Expand Up @@ -113,6 +113,13 @@ You should now be able to run `yarn dev` which will launch the application
- [ggshield](https://github.com/GitGuardian/ggshield#installation)
for `yarn test:sec` command.

##### Debian-based OS

- [nsis](https://nsis.sourceforge.io/Main_Page):
```sh
sudo apt-get install nsis
```

### Local development

This will watch for file changes and automatically re-hydrate the webapp on the go:
Expand Down Expand Up @@ -213,5 +220,6 @@ Our official `feat`, `fix`, `perf`, `refactor`, `style` & `test` scopes are:

- `cloud`: Any change impacting the Cloud screen.
- `dashboard`: Any change impacting the Dashboard screen.
- `daemon`: Any change impacting the Dashboard screen.
- `scanner`: Any change impacting the Scanner screen.
- `settings`: Any change impacting the Settings screen.
9 changes: 9 additions & 0 deletions assets/deb/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

cp clamav-desktop-daemon /usr/local/bin/
chmod +x /usr/local/bin/clamav-desktop-daemon

systemctl enable clamav-desktop-daemon
systemctl start clamav-desktop-daemon

exit 0
38 changes: 38 additions & 0 deletions assets/msi/postinstall.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Outfile "InstallService.exe"
RequestExecutionLevel admin

Section
SetOutPath $INSTDIR

; Copy the binary to the installation directory
File "clamav-desktop-daemon.exe"

; Create the service
nsExec::ExecToLog 'sc create clamav-desktop-daemon binPath= "$INSTDIR\clamav-desktop-daemon.exe" start= auto'
Pop $0 ; Get the exit code
StrCmp $0 0 +3
MessageBox MB_ICONEXCLAMATION|MB_OK "Failed to create the service. Error code $0."
Quit

; Start the service
nsExec::ExecToLog 'sc start clamav-desktop-daemon'
Pop $0
StrCmp $0 0 +3
MessageBox MB_ICONEXCLAMATION|MB_OK "Failed to start the service. Error code $0."
Quit

MessageBox MB_ICONINFORMATION|MB_OK "Service installed and started successfully."
SectionEnd

Section "Uninstall"
; Stop the service before uninstalling
nsExec::ExecToLog 'sc stop clamav-desktop-daemon'
; TODO Find a solid way to wait for the service to stop.
Sleep 3000 ; Wait for the service to stop

; Delete the service
nsExec::ExecToLog 'sc delete clamav-desktop-daemon'

; Delete the binary
Delete "$INSTDIR\clamav-desktop-daemon.exe"
SectionEnd
8 changes: 8 additions & 0 deletions assets/pkg/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cp clamav-desktop-daemon /usr/local/bin/
chmod +x /usr/local/bin/clamav-desktop-daemon

launchctl load /Library/LaunchDaemons/com.clamav-desktop.service.plist

exit 0
1 change: 1 addition & 0 deletions clamav
Submodule clamav added at 29ed81
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"release:deb:install": "yarn release:deb && sudo dpkg -i ./src-tauri/target/release/bundle/deb/clamav-desktop_0.3.24_amd64.deb",
"release:dmg": "tauri build -b dmg",
"release:msi": "tauri build -b msi",
"setup": "git fetch -p && git submodule update --init",
"start": "./src-tauri/target/release/clamav-desktop",
"test": "yarn test:lint && yarn test:type && yarn test:unit:core && test:unit:webview",
"test:e2e": "xvfb-run wdio run ./configs/wdio.config.ts",
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/clamav-desktop-daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "clamav-desktop-daemon"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions src-tauri/clamav-desktop-daemon/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit 980353b

Please sign in to comment.