Skip to content

Commit

Permalink
Support FreeBSD - Code and documentation changes to support FreeBSD (#…
Browse files Browse the repository at this point in the history
…3048)

* Code and documentation changes to support FreeBSD
  • Loading branch information
abraunegg authored Jan 13, 2025
1 parent c7037f8 commit 260be94
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ AThings
aufxw
aur
autoclean
automake
autoprocess
autoupdate
avmkfdiitirnrenzljwc
Expand Down Expand Up @@ -129,6 +130,7 @@ getenforce
gfortran
GFree
Gibi
gmake
gmodule
GObject
gpg
Expand Down Expand Up @@ -188,6 +190,7 @@ libglib
libgobject
liblphobos
libm
libinotify
libnotify
libsqlite
Lighttpd
Expand All @@ -206,6 +209,7 @@ ltmain
Lyncredible
makepkg
mangleof
maxfiles
mayne
mbr
memtest
Expand Down Expand Up @@ -271,6 +275,7 @@ phlibi
phobos
pidx
pixbuf
pkgconf
pki
pkolmann
podman
Expand Down
32 changes: 21 additions & 11 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ systemdsystemunitdir = @systemdsystemunitdir@
curl_LIBS = @curl_LIBS@
sqlite_LIBS = @sqlite_LIBS@
notify_LIBS = @notify_LIBS@
bsd_inotify_LIBS = @bsd_inotify_LIBS@
COMPLETIONS = @COMPLETIONS@
BASH_COMPLETION_DIR = @BASH_COMPLETION_DIR@
ZSH_COMPLETION_DIR = @ZSH_COMPLETION_DIR@
Expand Down Expand Up @@ -107,16 +108,22 @@ onedrive: $(SOURCES)
else \
echo $(version) > version ; \
fi
$(DC) $(DCFLAGS) $(addprefix -L,$(curl_LIBS)) $(addprefix -L,$(sqlite_LIBS)) $(addprefix -L,$(notify_LIBS)) -L-ldl $(SOURCES) -of$@
$(DC) $(DCFLAGS) $(addprefix -L,$(curl_LIBS)) $(addprefix -L,$(sqlite_LIBS)) $(addprefix -L,$(notify_LIBS)) $(addprefix -L,$(bsd_inotify_LIBS)) -L-ldl $(SOURCES) -of$@

install: all
$(INSTALL) -D onedrive $(DESTDIR)$(bindir)/onedrive
$(INSTALL) -D -m 0644 onedrive.1 $(DESTDIR)$(mandir)/man1/onedrive.1
$(INSTALL) -D -m 0644 contrib/logrotate/onedrive.logrotate $(DESTDIR)$(sysconfdir)/logrotate.d/onedrive
mkdir -p $(DESTDIR)$(bindir)
$(INSTALL) onedrive $(DESTDIR)$(bindir)/onedrive
mkdir -p $(DESTDIR)$(mandir)/man1
$(INSTALL) -m 0644 onedrive.1 $(DESTDIR)$(mandir)/man1/onedrive.1
mkdir -p $(DESTDIR)$(sysconfdir)/logrotate.d
$(INSTALL) -m 0644 contrib/logrotate/onedrive.logrotate $(DESTDIR)$(sysconfdir)/logrotate.d/onedrive
mkdir -p $(DESTDIR)$(docdir)
$(INSTALL) -D -m 0644 $(DOCFILES) $(DESTDIR)$(docdir)
for file in $(DOCFILES); do \
$(INSTALL) -m 0644 $$file $(DESTDIR)$(docdir); \
done
ifeq ($(HAVE_SYSTEMD),yes)
$(INSTALL) -d -m 0755 $(DESTDIR)$(systemduserunitdir) $(DESTDIR)$(systemdsystemunitdir)
mkdir -p $(DESTDIR)$(systemduserunitdir)
mkdir -p $(DESTDIR)$(systemdsystemunitdir)
ifeq ($(RHEL),1)
$(INSTALL) -m 0644 $(system_unit_files) $(DESTDIR)$(systemdsystemunitdir)
$(INSTALL) -m 0644 $(user_unit_files) $(DESTDIR)$(systemdsystemunitdir)
Expand All @@ -126,14 +133,17 @@ else
endif
else
ifeq ($(RHEL_VERSION),6)
install -D contrib/init.d/onedrive.init $(DESTDIR)/etc/init.d/onedrive
install -D contrib/init.d/onedrive_service.sh $(DESTDIR)$(bindir)/onedrive_service.sh
$(INSTALL) contrib/init.d/onedrive.init $(DESTDIR)/etc/init.d/onedrive
$(INSTALL) contrib/init.d/onedrive_service.sh $(DESTDIR)$(bindir)/onedrive_service.sh
endif
endif
ifeq ($(COMPLETIONS),yes)
$(INSTALL) -D -m 0644 contrib/completions/complete.zsh $(DESTDIR)$(ZSH_COMPLETION_DIR)/_onedrive
$(INSTALL) -D -m 0644 contrib/completions/complete.bash $(DESTDIR)$(BASH_COMPLETION_DIR)/onedrive
$(INSTALL) -D -m 0644 contrib/completions/complete.fish $(DESTDIR)$(FISH_COMPLETION_DIR)/onedrive.fish
mkdir -p $(DESTDIR)$(ZSH_COMPLETION_DIR)
$(INSTALL) -m 0644 contrib/completions/complete.zsh $(DESTDIR)$(ZSH_COMPLETION_DIR)/_onedrive
mkdir -p $(DESTDIR)$(BASH_COMPLETION_DIR)
$(INSTALL) -m 0644 contrib/completions/complete.bash $(DESTDIR)$(BASH_COMPLETION_DIR)/onedrive
mkdir -p $(DESTDIR)$(FISH_COMPLETION_DIR)
$(INSTALL) -m 0644 contrib/completions/complete.fish $(DESTDIR)$(FISH_COMPLETION_DIR)/onedrive.fish
endif

uninstall:
Expand Down
50 changes: 34 additions & 16 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ bashcompdir
COMPLETIONS
NOTIFICATIONS
notify_LIBS
bsd_inotify_LIBS
notify_CFLAGS
HAVE_SYSTEMD
systemduserunitdir
Expand Down Expand Up @@ -678,6 +679,7 @@ sqlite_CFLAGS
sqlite_LIBS
notify_CFLAGS
notify_LIBS
bsd_inotify_LIBS
bashcompdir'


Expand Down Expand Up @@ -1309,23 +1311,21 @@ Optional Packages:
Directory for fish completion files
Some influential environment variables:
DC D compiler executable
DCFLAGS flags for D compiler
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
DC D compiler executable
DCFLAGS flags for D compiler
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
curl_CFLAGS C compiler flags for curl, overriding pkg-config
curl_LIBS linker flags for curl, overriding pkg-config
sqlite_CFLAGS
C compiler flags for sqlite, overriding pkg-config
sqlite_LIBS linker flags for sqlite, overriding pkg-config
notify_CFLAGS
C compiler flags for notify, overriding pkg-config
notify_LIBS linker flags for notify, overriding pkg-config
bashcompdir value of completionsdir for bash-completion, overriding
pkg-config
path overriding pkg-config's built-in search path
curl_CFLAGS C compiler flags for curl, overriding pkg-config
curl_LIBS linker flags for curl, overriding pkg-config
sqlite_CFLAGS C compiler flags for sqlite, overriding pkg-config
sqlite_LIBS linker flags for sqlite, overriding pkg-config
notify_CFLAGS C compiler flags for GUI notifications, overriding pkg-config
notify_LIBS linker flags for GUI notifications, overriding pkg-config
bsd_inotify_LIBS linker flags for inotify support on BSD
bashcompdir value of completionsdir for bash-completion, overriding
pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Expand Down Expand Up @@ -2509,6 +2509,24 @@ else
fi
NOTIFICATIONS=$enable_notifications
# Check if Linux or BSD Platform
case "$(uname -s)" in
Linux)
bsd_inotify_LIBS=""
;;
FreeBSD)
bsd_inotify_LIBS="-L/usr/local/lib -linotify"
;;
OpenBSD)
bsd_inotify_LIBS=""
;;
*)
bsd_inotify_LIBS=""
;;
esac
# Export the variable for use in the script
export bsd_inotify_LIBS
# Check whether --enable-completions was given.
if test "${enable_completions+set}" = set; then :
Expand Down
52 changes: 38 additions & 14 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Only the current release version or greater is supported. Earlier versions are n
| Debian 12 | [onedrive](https://packages.debian.org/bookworm/source/onedrive) |<a href="https://packages.debian.org/bookworm/source/onedrive"><img src="https://repology.org/badge/version-for-repo/debian_12/onedrive.svg?header=" alt="Debian 12 package" width="46" height="20"></a>||||| **Note:** Do not install from Debian Package Repositories as the package is obsolete and is not supported<br><br>For a supported application version, it is recommended that for Debian 12 that you install from OpenSuSE Build Service using the Debian Package Install [Instructions](ubuntu-package-install.md) |
| Debian Sid | [onedrive](https://packages.debian.org/sid/onedrive) |<a href="https://packages.debian.org/sid/onedrive"><img src="https://repology.org/badge/version-for-repo/debian_unstable/onedrive.svg?header=" alt="Debian Sid package" width="46" height="20"></a>||||| |
| Fedora | [onedrive](https://koji.fedoraproject.org/koji/packageinfo?packageID=26044) |<a href="https://koji.fedoraproject.org/koji/packageinfo?packageID=26044"><img src="https://repology.org/badge/version-for-repo/fedora_rawhide/onedrive.svg?header=" alt="Fedora Rawhide package" width="46" height="20"></a>||||| |
| FreeBSD | [onedrive](https://www.freshports.org/net/onedrive) |<a href="https://www.freshports.org/net/onedrive"><img src="https://repology.org/badge/version-for-repo/freebsd/onedrive.svg?header=" alt="FreeBSD package" width="46" height="20"></a>||||| |
| Gentoo | [onedrive](https://gpo.zugaina.org/net-misc/onedrive) | No API Available ||||| |
| Homebrew | [onedrive](https://formulae.brew.sh/formula/onedrive) |<a href="https://formulae.brew.sh/formula/onedrive"><img src="https://repology.org/badge/version-for-repo/homebrew/onedrive.svg?header=" alt="Homebrew package" width="46" height="20"></a> ||||| |
| Linux Mint 20.x | [onedrive](https://community.linuxmint.com/software/view/onedrive) |<a href="https://community.linuxmint.com/software/view/onedrive"><img src="https://repology.org/badge/version-for-repo/ubuntu_20_04/onedrive.svg?header=" alt="Ubuntu 20.04 package" width="46" height="20"></a> ||||| **Note:** Do not install from Linux Mint Repositories as the package is obsolete and is not supported<br><br>For a supported application version, it is recommended that for Linux Mint that you install from OpenSuSE Build Service using the Ubuntu Package Install [Instructions](ubuntu-package-install.md) |
Expand Down Expand Up @@ -59,7 +60,7 @@ curl -fsS https://dlang.org/install.sh | bash -s ldc
```text
sudo pacman -S git make pkg-config curl sqlite ldc
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo pacman -S libnotify
```
Expand All @@ -76,19 +77,30 @@ sudo dnf groupinstall 'Development Tools'
sudo dnf install libcurl-devel sqlite-devel
curl -fsS https://dlang.org/install.sh | bash -s dmd
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo dnf install libnotify-devel
```

### Dependencies: FreeBSD
```text
pkg install bash bash-completion gmake pkgconf autoconf automake logrotate libinotify git sqlite3 ldc
```
For GUI notifications the following is also necessary:
```text
pkg install libnotify
```
> [!NOTE]
> Install the required FreeBSD packages as 'root' unless you have installed 'sudo'
### Dependencies: Gentoo
```text
sudo emerge app-portage/layman
sudo layman -a dlang
```
Add ebuild from contrib/gentoo to a local overlay to use.

For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo emerge x11-libs/libnotify
```
Expand All @@ -113,7 +125,7 @@ sudo apt install build-essential
sudo apt install libcurl4-openssl-dev libsqlite3-dev pkg-config git curl
curl -fsS https://dlang.org/install.sh | bash -s dmd
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo apt install libnotify-dev
```
Expand All @@ -134,7 +146,7 @@ These instructions were validated using:
sudo apt install build-essential
sudo apt install libcurl4-openssl-dev libsqlite3-dev pkg-config git curl ldc
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo apt install libnotify-dev
```
Expand All @@ -145,7 +157,7 @@ sudo zypper addrepo https://download.opensuse.org/repositories/devel:languages:D
sudo zypper refresh
sudo zypper install gcc git libcurl-devel sqlite3-devel dmd phobos-devel phobos-devel-static
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo zypper install libnotify-devel
```
Expand All @@ -156,7 +168,7 @@ sudo zypper addrepo https://download.opensuse.org/repositories/devel:languages:D
sudo zypper refresh
sudo zypper install gcc git libcurl-devel sqlite3-devel dmd phobos-devel phobos-devel-static
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo zypper install libnotify-devel
```
Expand All @@ -166,19 +178,20 @@ sudo zypper install libnotify-devel
sudo zypper refresh
sudo zypper install gcc git libcurl-devel sqlite3-devel dmd phobos-devel phobos-devel-static
```
For notifications the following is also necessary:
For GUI notifications the following is also necessary:
```text
sudo zypper install libnotify-devel
```

## Compilation & Installation
### High Level Steps
1. Install the platform dependencies for your Linux OS
2. Activate your DMD or LDC compiler
3. Clone the GitHub repository, run configure and make, then install
4. Deactivate your DMD or LDC compiler
1. Install the platform dependencies for your platform
2. Activate your DMD or LDC compiler if required
3. Clone the GitHub repository,
4. Run the 'configure' command then build the application and install it
5. Deactivate your DMD or LDC compiler if required

### Building using DMD Reference Compiler
### Linux: Building the application using the DMD Reference Compiler
Before cloning and compiling, if you have installed DMD via curl for your OS, you will need to activate DMD as per example below:
```text
Run `source ~/dlang/dmd-2.088.0/activate` in your shell to use dmd-2.088.0.
Expand All @@ -198,6 +211,17 @@ make clean; make;
sudo make install
```

### FreeBSD: Building the application using FreeBSD version of LDC
```text
git clone https://github.com/abraunegg/onedrive.git
cd onedrive
./configure
gmake clean; gmake;
gmake install
```
> [!NOTE]
> Install the application as 'root' unless you have installed 'sudo'
### Build options
#### GUI Notification Support
GUI notification support can be enabled using the `configure` switch `--enable-notifications`.
Expand Down Expand Up @@ -230,7 +254,7 @@ as far as possible automatically, but can be overridden by passing
> For successful compilation of this application, it's crucial that the build environment is equipped with a minimum of 1GB of memory and an additional 1GB of swap space. To verify your system's swap space availability, you can use the `swapon` command. Ensuring these requirements are met is vital for the application's compilation process.
> [!NOTE]
> The 'configure' step will detect the correct version of LDC to be used when compiling the client under ARMHF and ARM64 cpu architectures.
> The 'configure' step will detect the correct version of LDC to be used when compiling the client under ARMHF and ARM64 CPU architectures.
```text
git clone https://github.com/abraunegg/onedrive.git
Expand Down
54 changes: 50 additions & 4 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -867,11 +867,9 @@ int main(string[] cliArgs) {
performFileSystemMonitoring = true;

// What are the current values for the platform we are running on
// Max number of open files /proc/sys/fs/file-max
string maxOpenFiles = strip(readText("/proc/sys/fs/file-max"));
string maxOpenFiles = strip(getMaxOpenFiles());
// What is the currently configured maximum inotify watches that can be used
// /proc/sys/fs/inotify/max_user_watches
string maxInotifyWatches = strip(readText("/proc/sys/fs/inotify/max_user_watches"));
string maxInotifyWatches = strip(getMaxInotifyWatches());

// Start the monitor process
addLogEntry("OneDrive synchronisation interval (seconds): " ~ to!string(appConfig.getValueLong("monitor_interval")));
Expand Down Expand Up @@ -1238,6 +1236,54 @@ int main(string[] cliArgs) {
}
}

// Retrieves the maximum number of open files allowed by the system
string getMaxOpenFiles() {
version (Linux) {
try {
// Read max open files from procfs on Linux
return strip(readText("/proc/sys/fs/file-max"));
} catch (Exception e) {
return "Unknown (Error reading /proc/sys/fs/file-max)";
}
} else version (FreeBSD) {
try {
// Read max open files using sysctl on FreeBSD
return strip(executeShell("sysctl -n kern.maxfiles").output);
} catch (Exception e) {
return "Unknown (sysctl error)";
}
} else version (OpenBSD) {
try {
// Read max open files using sysctl on OpenBSD
return strip(executeShell("sysctl -n kern.maxfiles").output);
} catch (Exception e) {
return "Unknown (sysctl error)";
}
} else {
return "Unsupported platform";
}
}

// Retrieves the maximum inotify watches allowed (Linux) or a placeholder for other platforms
string getMaxInotifyWatches() {
version (Linux) {
try {
// Read max inotify watches from procfs on Linux
return strip(readText("/proc/sys/fs/inotify/max_user_watches"));
} catch (Exception e) {
return "Unknown (Error reading /proc/sys/fs/inotify/max_user_watches)";
}
} else version (FreeBSD) {
// FreeBSD uses kqueue instead of inotify, no direct equivalent
return "N/A (uses kqueue)";
} else version (OpenBSD) {
// OpenBSD uses kqueue instead of inotify, no direct equivalent
return "N/A (uses kqueue)";
} else {
return "Unsupported platform";
}
}

// Print error message when --sync or --monitor has not been used and no valid 'no-sync' operation was requested
void printMissingOperationalSwitchesError() {
// notify the user that --sync or --monitor were missing
Expand Down
Loading

0 comments on commit 260be94

Please sign in to comment.