Skip to content

Commit

Permalink
Extend automatic switch at startup to user-install
Browse files Browse the repository at this point in the history
Extended the feature of automatically detecting eGPU and switching at startup using systemd or OpenRC so it works when the script is installed with the user-install command to user's home directory.
  • Loading branch information
ewagner12 authored Feb 18, 2024
1 parent f233c68 commit 72de788
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,24 @@ Download and install the latest release using the following one line command:
cd ~; curl -qLs https://github.com/ewagner12/all-ways-egpu/releases/latest/download/all-ways-egpu.zip -o all-ways-egpu.zip; unzip all-ways-egpu.zip; cd all-ways-egpu-main; chmod +x install.sh; sudo ./install.sh install; cd ../; rm -rf all-ways-egpu.zip all-ways-egpu-main
```

If the above command fails due to a non-writable /usr then go to the next section below.
### Steam Deck/User Installation:
This following installation method is specifically for those using Steam Deck/SteamOS 3.0 or any other distro (such as Fedora Silverblue) where the system files are read-only:

```
cd ~; curl -qLs https://github.com/ewagner12/all-ways-egpu/releases/latest/download/all-ways-egpu.zip -o all-ways-egpu.zip; unzip all-ways-egpu.zip; cd all-ways-egpu-main; chmod +x install.sh; sudo ./install.sh user-install; cd ../; rm -rf all-ways-egpu.zip all-ways-egpu-main
```
Note that running the command above adds ~/bin to your path in Bash. If using a different shell be sure to add ~/bin to your path in your shell. Automatic switching at bootup is not available with this type of installation so the script must be run by the user after login to switch to the eGPU (see Usage section below).
Note that running the command above adds ~/bin to your path in Bash. If using a different shell be sure to add ~/bin to your path in your shell.

### Git
Clone the repo to get the latest from github:
```
git clone https://github.com/ewagner12/all-ways-egpu.git
```

To install/uninstall navigate to the downloaded location:
To install/uninstall navigate to the downloaded location and run the install.sh script:
```
cd all-ways-egpu
```

Install:
```
chmod +x install.sh; sudo ./install.sh install
```

Expand Down
15 changes: 13 additions & 2 deletions all-ways-egpu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

VERSION=0.51.2
VERSION=0.52.0
BINDIR=/usr/bin
USER_IDS_DIR=/usr/share/all-ways-egpu
CONFDIR=/etc/all-ways-egpu
Expand Down Expand Up @@ -90,7 +90,7 @@ setupAutostart() {
fi

if [ "${1}" -eq 1 ]; then
echo "Note startup files will use system configuration, not user configuration"
echo "Note startup files will use first user's configuration"
fi

echo "Recommended if using Method 1: Attempt to re-enable the iGPU/initially disabled devices after login? [y/N]"
Expand Down Expand Up @@ -702,6 +702,17 @@ if [ "$SUDO_USER" != "" ]; then
EGPU_IDS="$USER_IDS_DIR"/egpu-bus-ids
RETRY_FILE="$USER_IDS_DIR"/max-retry
fi
else
# when run as root uses first user config if one is found. To override, specify user instead of * in next line
for HD in /home/*/.config; do
if [ -e "$HD"/all-ways-egpu/egpu-bus-ids ] || [ -e "$HD"/all-ways-egpu/user-bus-ids ]; then
USER_IDS_DIR="$HD"/all-ways-egpu
PCI_DEV="$USER_IDS_DIR"/user-bus-ids
EGPU_IDS="$USER_IDS_DIR"/egpu-bus-ids
RETRY_FILE="$USER_IDS_DIR"/max-retry
break
fi
done
fi

# sanity check Bus IDs format in existing files
Expand Down
2 changes: 1 addition & 1 deletion all-ways-egpu-reenable.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Comment=Re-enables iGPU after setting eGPU as primary for Wayland desktops
Exec=systemctl start all-ways-egpu-user.service
Terminal=false
Type=Application
Version=0.51.2
Version=0.52.0
Categories=System;Settings;Utility;
Keywords=system;hardware;

2 changes: 1 addition & 1 deletion all-ways-egpu.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Comment=Script for setting eGPU as primary for Wayland desktops
Exec=all-ways-egpu
Terminal=true
Type=Application
Version=0.51.2
Version=0.52.0
Categories=System;Settings;Utility;
Keywords=system;hardware;

39 changes: 24 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@ DESTDIR=
BINDIR=/usr/bin
CONFDIR=/etc/all-ways-egpu

initServices() {
# check if using systemd or openrc
if [ -e "$(command -v systemctl)" ]; then
cp systemd/all-ways-egpu.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-user.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-boot-vga.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-shutdown.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-set-compositor.service "${DESTDIR}"${CONFDIR}
cp all-ways-egpu-reenable.desktop "${DESTDIR}"${CONFDIR}
else
if [ -e "$(command -v rc-status)" ]; then
cp OpenRC/all-ways-egpu-openrc "${DESTDIR}"${CONFDIR}
cp OpenRC/all-ways-egpu-boot-vga-openrc "${DESTDIR}"${CONFDIR}
cp OpenRC/all-ways-egpu-set-compositor-openrc "${DESTDIR}"${CONFDIR}
fi
fi
}

case $1 in
install)
mkdir -p "${DESTDIR}"${BINDIR}
cp all-ways-egpu "${DESTDIR}"${BINDIR}
chmod +x "${DESTDIR}"${BINDIR}/all-ways-egpu
mkdir -p "${DESTDIR}"${CONFDIR}
# check if using systemd or openrc
if [ -e "$(command -v systemctl)" ]; then
cp systemd/all-ways-egpu.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-user.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-boot-vga.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-shutdown.service "${DESTDIR}"${CONFDIR}
cp systemd/all-ways-egpu-set-compositor.service "${DESTDIR}"${CONFDIR}
cp all-ways-egpu-reenable.desktop "${DESTDIR}"${CONFDIR}
else
if [ -e "$(command -v rc-status)" ]; then
cp OpenRC/all-ways-egpu-openrc "${DESTDIR}"${CONFDIR}
cp OpenRC/all-ways-egpu-boot-vga-openrc "${DESTDIR}"${CONFDIR}
cp OpenRC/all-ways-egpu-set-compositor-openrc "${DESTDIR}"${CONFDIR}
fi
fi
initServices
cp all-ways-egpu.desktop "${DESTDIR}"/usr/share/applications
;;

user-install)
set -- "${DESTDIR}"/home/*
# Init services hard coded to first user path
sed -i 's,=all-ways-egpu,='"$1"'\/bin\/all-ways-egpu,' systemd/*.service
sed -i 's,="all-ways-egpu",="'"$1"'\/bin\/all-ways-egpu\",' OpenRC/*-openrc
mkdir -p "${DESTDIR}"${CONFDIR}
initServices
for HD in "$@"; do
mkdir -p "$HD"/bin
cp all-ways-egpu "$HD"/bin
Expand Down

0 comments on commit 72de788

Please sign in to comment.