Skip to content

Commit

Permalink
add ubuntu install script
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-pro committed Jan 15, 2024
1 parent 06d57b9 commit f71b89e
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This changes the screen brightness via monitor control APIs, whereas those utili
For Windows, you can download pre-compiled binaries from
[Releases](https://github.com/jacob-pro/solar-screen-brightness/releases).

If you are using Linux, please read the [Linux Guide](docs/LINUX_GUIDE.md)
If you are using Linux, please read the [Linux Guide](linux/README.md)

There is also a CLI only version of the application available.

Expand Down
16 changes: 13 additions & 3 deletions docs/LINUX_GUIDE.md → linux/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Linux Guide

## Installation

For Ubuntu you can use the [installation script](./ubuntu_install.sh):

```bash
curl -sSf https://github.com/jacob-pro/solar-screen-brightness/raw/master/linux/ubuntu_install.sh?raw=true | bash -s install
```

## External Monitor Support

Internally `solar-screen-brightness` uses the [`brightness` crate](https://github.com/stephaneyfx/brightness).

On Linux, the `brightness` crate interacts with devices found at `/sys/class/backlight`.

The [ddcci-backlight](https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux)
kernel driver is required to expose external monitors as backlight devices (via DDC/CI).

## Installing the Driver
### Installing the Driver

On Ubuntu-like distributions you should be able to use APT to install:

Expand Down Expand Up @@ -39,7 +49,7 @@ sudo make unload
modprobe ddcci-backlight dyndbg
```

## Backlight Permissions
### Backlight Permissions

If you have `systemd`
[version 243 or later](https://github.com/systemd/systemd/blob/877aa0bdcc2900712b02dac90856f181b93c4e40/NEWS#L262),
Expand All @@ -57,7 +67,7 @@ RUN+="/bin/bash -c '/bin/chmod g+w /sys/class/backlight/*/brightness'"

`usermod -a -G video $USER` (requires logging out to take effect)

## Known Issues
### Known Issues

- [Monitors connected via a USB-C dock, on Intel devices, require updating to the Linux Kernel 5.10 for DDC/CI to work](https://gitlab.freedesktop.org/drm/intel/-/issues/37).
- [Hot swapping monitors is not yet supported, you need to reload the kernel module](https://gitlab.com/ddcci-driver-linux/ddcci-driver-linux/-/issues/5)
106 changes: 106 additions & 0 deletions linux/ubuntu_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash

# Install Script for Solar Screen Brightness on Ubuntu
# 1. Installs Rust Cargo (via Rustup) if necessary
# 2. Installs any required packages if necessary
# 3. Compiles and installs the latest applications (ssb and ssb-cli) from GitHub
# 4. Creates desktop and autostart entries

set -e

DESKTOP_ENTRY="${HOME}/.local/share/applications/solar-screen-brightness.desktop"
AUTOSTART_DIR="${HOME}/.config/autostart"
AUTOSTART_ENTRY="${AUTOSTART_DIR}/solar-screen-brightness.desktop"
SSB_BINARY="${HOME}/.cargo/bin/ssb"
SSB_DATA_DIR="${HOME}/.local/share/solar-screen-brightness"
ICON_PATH="${SSB_DATA_DIR}/icon.png"
SSB_CONFIG_DIR="${HOME}/.config/solar-screen-brightness"

function install_package_if_not_exists () {
if [ $(dpkg-query -W -f='${Status}' ${1} 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
echo "Attempting to install ${1}"
sudo apt install -y ${1};
else
echo "Package ${1} is already installed"
fi
}

function refresh_desktop() {
echo "Updating Desktop"
xdg-desktop-menu forceupdate
}

function install() {
if ! command -v cargo &> /dev/null; then
echo "Rust Cargo could not be found. Attempting to install Rust..."
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
else
echo "Cargo found: $(cargo --version)"
fi

install_package_if_not_exists "libssl-dev"
install_package_if_not_exists "libudev-dev"
install_package_if_not_exists "libgtk-3-dev"
install_package_if_not_exists "libxdo-dev"

echo "Installing latest Solar Screen Brightness..."
cargo install --git https://github.com/jacob-pro/solar-screen-brightness

ICON_URL="https://github.com/jacob-pro/solar-screen-brightness/blob/06d57b9054ae29c5e73e491f5d073a4986f2224a/assets/icon-256.png?raw=true"

echo "Downloading icon to ${ICON_PATH}"
curl -sS -L --create-dirs --output "${ICON_PATH}" "${ICON_URL}"

# Quotes https://askubuntu.com/a/1023258
echo "Creating desktop entry ${DESKTOP_ENTRY}"
cat <<EOT >> ${DESKTOP_ENTRY}
[Desktop Entry]
Type=Application
Name=Solar Screen Brightness
Exec="${SSB_BINARY}"
Icon=${ICON_PATH}
Terminal=false
EOT

echo "Creating autostart entry ${AUTOSTART_ENTRY}"
mkdir -p ${AUTOSTART_DIR}
cat <<EOT >> ${AUTOSTART_ENTRY}
[Desktop Entry]
Type=Application
Name=Solar Screen Brightness
Exec="${SSB_BINARY} --minimised"
Icon=${ICON_PATH}
Terminal=false
EOT

refresh_desktop

echo "Successfully installed $(ssb-cli --version)"
}

function uninstall() {
echo "Removing desktop entry"
rm -f ${DESKTOP_ENTRY}
echo "Removing startup entry"
rm -f ${AUTOSTART_ENTRY}
refresh_desktop

if command -v ssb &> /dev/null; then
echo "Uninstalling solar-screen-brightness"
cargo uninstall solar-screen-brightness
fi

echo "Deleting config"
rm -rf ${SSB_CONFIG_DIR}
echo "Deleting data"
rm -rf ${SSB_DATA_DIR}
}

if [ "$1" = "install" ]; then
install
elif [ "$1" = "uninstall" ]; then
uninstall
else
echo "Usage: ./ubuntu-install.sh [install or uninstall]"
fi

0 comments on commit f71b89e

Please sign in to comment.