forked from gitbackup/Steam-Deck.Mount-External-Drive
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a32922d702 | ||
|
|
d27b178dba | ||
|
|
c6179033b2 | ||
|
|
f674ad76dc | ||
|
|
abd7b301ac | ||
|
|
de97181d48 | ||
|
|
40d9dc1460 | ||
|
|
c085619ef8 | ||
|
|
acc2e5d94a | ||
|
|
ae033667f9 | ||
|
|
12af3862eb | ||
|
|
caa5e85aa7 | ||
|
|
2ce8a29318 | ||
|
|
c4f617ca79 | ||
|
|
6bfc08fac9 | ||
|
|
57381447c8 | ||
|
|
7b107b5233 | ||
|
|
e0be5491ad | ||
|
|
2e4f81e785 | ||
|
|
1068b31d2b | ||
|
|
5cb035c9d8 | ||
|
|
c3f735e660 | ||
|
|
ce806669b0 | ||
|
|
aa8bab290a | ||
|
|
81a4f6794d | ||
|
|
fee7e90ef2 | ||
|
|
726aa18d80 | ||
|
|
e9db8ee745 | ||
|
|
88ad8caa7c | ||
|
|
ed934766ec | ||
|
|
836fae8530 | ||
|
|
718524076d | ||
|
|
aa200d97f8 | ||
|
|
5492959915 | ||
|
|
fc4dd2b2b3 | ||
|
|
83036b014c | ||
|
|
af34293d97 | ||
|
|
ee6033b32a | ||
|
|
348dc32486 | ||
|
|
5b2f51faf2 | ||
|
|
39398d549f | ||
|
|
4af9f2a912 | ||
|
|
8724f1e13f | ||
|
|
10c9143cb8 | ||
|
|
4d047775ee | ||
|
|
360e6f7afb | ||
|
|
907350251d | ||
|
|
fa0f775e4a | ||
|
|
7d11b79842 | ||
|
|
9d996f5a5b | ||
|
|
c119967788 | ||
|
|
b162f43ccb | ||
|
|
f9dc99b486 | ||
|
|
7edacd0e25 | ||
|
|
15f7258234 | ||
|
|
be88485649 | ||
|
|
b6ebec9018 | ||
|
|
8b353435d0 | ||
|
|
c50dbeaacf | ||
|
|
d652b94db5 | ||
|
|
d901cd08e3 | ||
|
|
0662441295 | ||
|
|
d2ce0ca697 | ||
|
|
1b9aacdac2 | ||
|
|
3b0349fe4c | ||
|
|
a7f6dcd13a | ||
|
|
695c1a01d5 | ||
|
|
617a7b7480 | ||
|
|
cbbc8f7488 | ||
|
|
b6478440fb | ||
|
|
596a47fdac | ||
|
|
dc71750b19 | ||
|
|
5435d0e15f | ||
|
|
f309ad2627 | ||
|
|
97f831bb61 | ||
|
|
f50f608d07 | ||
|
|
da83261382 | ||
|
|
031f826afc | ||
|
|
f95306a3b9 |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
config/
|
||||
temp/
|
||||
logs/
|
||||
@@ -1,5 +1,60 @@
|
||||
# Steam-Deck.Mount-External-Drive
|
||||
A Script to (Un)Mount and Setup Auto-Mount for an External USB SSD on the Steam Deck
|
||||
# Steam-Deck.Mount-External-Drive 3.5
|
||||
Script to Auto-Mount NTFS, BTRFS & exFat SDCards, External USB Drives (or SSD Docks) & Internal Partitions (If you Dual-Boot) on the Steam Deck
|
||||
|
||||
NTFS & BTRFS Partitions containing a SteamLibrary at root level or in a folder named `SteamLibrary` will automatically be added to Steam, exFAT isn't supported as a SteamLibrary but will be Mounted for use with other Launchers or for Media/ROMs etc.
|
||||
|
||||
# "This is cool! How can I thank you?"
|
||||
### Why not drop me a sub over on my youtube channel ;) [Chinballs Gaming](https://www.youtube.com/chinballsTV?sub_confirmation=1)
|
||||
|
||||
### Also [Check out all these other things I'm making](https://github.com/scawp/Steam-Deck.Tools-List)
|
||||
|
||||
|
||||
# Steam OS 3.5 Now supports Ext4 external Drives out the box so see **Uninstall** if thats all you need!
|
||||
|
||||
# How does this work?
|
||||
|
||||
This script is basically a mirror of Valves own Auto-Mount script (which lives on SteamOS at `/usr/lib/hwsupport/steamos-automount.sh` ) adding in support for `ntfs`, `btrfs` & `exFAT` and adding rules for Internal Partitions.
|
||||
|
||||
Additional RegEx has been added to the rules to allow he mounting of "Full Disk" Formatted drives (eg ones that don't have a partitions table) so even drives that are eg `sda` or `mmcblk0` as well as `sda1` or `mmcblk0p1` can be mounted.
|
||||
|
||||
SteamOS's rule for this lives at `/usr/lib/udev/rules.d/99-steamos-automount.rules` and because SteamOS has a Read-Only File System, files in `/usr/` cannot be changed without removing the Read-Onlyness, however systemd rules can be overwritten due to how systemd prioritieses directories, so by adding a rule with the same name in `/etc/udev/rules.d/` we can override the rule without making changes to SteamOS.
|
||||
|
||||
Looking for the old code? see https://github.com/scawp/Steam-Deck.Mount-External-Drive/tree/pre-3.5
|
||||
|
||||
a `udev` rule is added to `/etc/udev/rules.d/99-steamos-automount.rules` which takes priority over `/usr/lib/udev/rules.d/99-steamos-automount.rules`
|
||||
this then calls systemd `/etc/systemd/system/external-drive-mount@[sda|sda1|sda2|sdd1|etc].service`
|
||||
that then runs `/home/deck/.local/share/scawp/SDMED/automount.sh` to Auto Mount any supported SD/External USB/Internal Partitions.
|
||||
|
||||
`/etc/fstab` is not required for mounting in this way, (however if a Device has an `fstab` entry these scripts will still work)
|
||||
|
||||
# Video Guide
|
||||
https://youtu.be/q9tiNzVWjVo
|
||||
|
||||
https://www.youtube.com/watch?v=Yglf1EKBv2A
|
||||
|
||||
# Operation
|
||||
|
||||
The Drive(s) will be Auto-Mounted to `/run/media/deck/[LABEL]` eg `/run/media/deck/External-ssd/` if the Device has no `label` then the Devices `UUID` will be used eg `/run/media/deck/a12332-12bf-a33ab-eef/`
|
||||
|
||||
# Installation
|
||||
|
||||
## Via Curl (One Line Install)
|
||||
|
||||
In Konsole type `curl -sSL https://raw.githubusercontent.com/scawp/Steam-Deck.Mount-External-Drive/main/curl_install.sh | bash`
|
||||
|
||||
a `sudo` password is required (run `passwd` if required first)
|
||||
|
||||
# Uninstall
|
||||
|
||||
`sudo rm /etc/udev/rules.d/99-steamos-automount.rules`
|
||||
|
||||
`sudo rm /etc/systemd/system/external-drive-mount@.service`
|
||||
|
||||
`sudo rm -r /home/deck/.local/share/scawp/SDMED`
|
||||
|
||||
`sudo udevadm control --reload`
|
||||
|
||||
`sudo systemctl daemon-reload`
|
||||
|
||||
# WORK IN PROGRESS!
|
||||
|
||||
This will probably have bugs, so beware! log bugs under [issues](https://github.com/scawp/Steam-Deck.Mount-External-Drive/issues)!
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Comment=https://github.com/scawp/Steam-Deck.Mount-External-Drive
|
||||
Exec=
|
||||
GenericName=
|
||||
Icon=dialog-scripts
|
||||
MimeType=
|
||||
Name=Scawps Mount on Start Up Script
|
||||
StartupNotify=true
|
||||
Terminal=false
|
||||
Type=Application
|
||||
X-KDE-AutostartScript=true
|
||||
X-KDE-SubstituteUID=false
|
||||
Executable → Regular
+208
-18
@@ -1,28 +1,218 @@
|
||||
#!/bin/bash
|
||||
#Steam Deck Mount External Drive by scawp
|
||||
#License: DBAD: https://github.com/scawp/Steam-Deck.Mount-External-Drive/blob/main/LICENSE.md
|
||||
#Source: https://github.com/scawp/Steam-Deck.Mount-External-Drive
|
||||
# Use at own Risk!
|
||||
|
||||
script_dir="$(dirname $(realpath "$0"))"
|
||||
config_dir="$script_dir/config"
|
||||
set -euo pipefail
|
||||
|
||||
mkdir -p "$config_dir"
|
||||
# Originally from https://serverfault.com/a/767079
|
||||
|
||||
function mount_drive () {
|
||||
mkdir "/run/media/deck/$(lsblk -noLABEL $1)"
|
||||
chown deck:deck "/run/media/deck/$(lsblk -noLABEL $1)"
|
||||
mount "$1" "/run/media/deck/$(lsblk -noLABEL $1)" -ouid=1000,gid=1000
|
||||
# This script is called from our systemd unit file to mount or unmount
|
||||
# a USB drive.
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "Usage: $0 {add|remove} device_name (e.g. sdb1)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ "$1" = "remove" ]; then
|
||||
exit 0;
|
||||
if [[ $# -ne 2 ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ -f "$config_dir/drive_list.conf" ]; then
|
||||
if [ ! -z "$(grep "^$(lsblk -noUUID /dev/$2)$" "$config_dir/drive_list.conf")" ] || [ ! -z "$(grep "^ALWAYS$" "$config_dir/drive_list.conf")" ]; then
|
||||
mount_drive "/dev/$2"
|
||||
ACTION=$1
|
||||
DEVBASE=$2
|
||||
DEVICE="/dev/${DEVBASE}"
|
||||
|
||||
# Shared between this and the auto-mount script to ensure we're not double-triggering nor automounting while formatting
|
||||
# or vice-versa.
|
||||
MOUNT_LOCK="/var/run/jupiter-automount-${DEVBASE//\/_}.lock"
|
||||
|
||||
# Obtain lock
|
||||
exec 9<>"$MOUNT_LOCK"
|
||||
if ! flock -n 9; then
|
||||
echo "$MOUNT_LOCK is active: ignoring action $ACTION"
|
||||
# Do not return a success exit code: it could end up putting the service in 'started' state without doing the mount
|
||||
# work (further start commands will be ignored after that)
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Wait N seconds for steam
|
||||
wait_steam()
|
||||
{
|
||||
local i=0
|
||||
local wait=$1
|
||||
echo "Waiting up to $wait seconds for steam to load"
|
||||
while ! pgrep -x steamwebhelper &>/dev/null && (( i++ < wait )); do
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
send_steam_url()
|
||||
{
|
||||
local command="$1"
|
||||
local arg="$2"
|
||||
local encoded=$(urlencode "$arg")
|
||||
if pgrep -x "steam" > /dev/null; then
|
||||
# TODO use -ifrunning and check return value - if there was a steam process and it returns -1, the message wasn't sent
|
||||
# need to retry until either steam process is gone or -ifrunning returns 0, or timeout i guess
|
||||
systemd-run -M 1000@ --user --collect --wait sh -c "./.steam/root/ubuntu12_32/steam steam://${command}/${encoded@Q}"
|
||||
echo "Sent URL to steam: steam://${command}/${arg} (steam://${command}/${encoded})"
|
||||
else
|
||||
echo "Could not send steam URL steam://${command}/${arg} (steam://${command}/${encoded}) -- steam not running"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
exit 0;
|
||||
# From https://gist.github.com/HazCod/da9ec610c3d50ebff7dd5e7cac76de05
|
||||
urlencode()
|
||||
{
|
||||
[ -z "$1" ] || echo -n "$@" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g'
|
||||
}
|
||||
|
||||
do_mount()
|
||||
{
|
||||
declare -i ret
|
||||
# NOTE: these values are ABI, since they are sent to the Steam client
|
||||
readonly FSCK_ERROR=1
|
||||
readonly MOUNT_ERROR=2
|
||||
|
||||
# Get info for this drive: $ID_FS_LABEL, and $ID_FS_TYPE
|
||||
dev_json=$(lsblk -o PATH,LABEL,FSTYPE --json -- "$DEVICE" | jq '.blockdevices[0]')
|
||||
ID_FS_LABEL=$(jq -r '.label | select(type == "string")' <<< "$dev_json")
|
||||
ID_FS_TYPE=$(jq -r '.fstype | select(type == "string")' <<< "$dev_json")
|
||||
|
||||
# Global mount options
|
||||
OPTS="rw,noatime"
|
||||
|
||||
# File system type specific mount options
|
||||
#if [[ ${ID_FS_TYPE} == "vfat" ]]; then
|
||||
# OPTS+=",users,gid=100,umask=000,shortname=mixed,utf8=1,flush"
|
||||
#fi
|
||||
|
||||
case "${ID_FS_TYPE}" in
|
||||
"ntfs")
|
||||
echo "FSType is NTFS"
|
||||
#Extra Opts don't seem necessary anymore? add if required
|
||||
#OPTS+=""
|
||||
;;
|
||||
"exfat")
|
||||
echo "FSType is exFat"
|
||||
#OPTS+=",users,gid=100,umask=000,shortname=mixed,utf8=1,flush"
|
||||
;;
|
||||
"btrfs")
|
||||
echo "FSType is btrfs"
|
||||
;;
|
||||
"ext4")
|
||||
echo "FSType is ext4"
|
||||
#exit 2
|
||||
;;
|
||||
*)
|
||||
echo "Error mounting ${DEVICE}: unsupported fstype: ${ID_FS_TYPE} - ${dev_json}"
|
||||
rm "${MOUNT_LOCK}"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
# Prior to talking to udisks, we need all udev hooks (we were started by one) to finish, so we know it has knowledge
|
||||
# of the drive. Our own rule starts us as a service with --no-block, so we can wait for rules to settle here
|
||||
# safely.
|
||||
#if ! udevadm settle; then
|
||||
# echo "Failed to wait for \`udevadm settle\`"
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
# Ask udisks to auto-mount. This needs a version of udisks that supports the 'as-user' option.
|
||||
ret=0
|
||||
reply=$(busctl call --allow-interactive-authorization=false --expect-reply=true --json=short \
|
||||
org.freedesktop.UDisks2 \
|
||||
/org/freedesktop/UDisks2/block_devices/"${DEVBASE}" \
|
||||
org.freedesktop.UDisks2.Filesystem \
|
||||
Mount 'a{sv}' 3 \
|
||||
as-user s deck \
|
||||
auth.no_user_interaction b true \
|
||||
options s "$OPTS") || ret=$?
|
||||
|
||||
if (( ret != 0 )); then
|
||||
send_steam_url "system/devicemountresult" "${DEVBASE}/${MOUNT_ERROR}"
|
||||
echo "Error mounting ${DEVICE} (status = $ret)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Expected reply is of the format
|
||||
# {"type":"s","data":["/run/media/deck/home"]}
|
||||
mount_point=$(jq -r '.data[0] | select(type == "string")' <<< "$reply" || true)
|
||||
if [[ -z $mount_point ]]; then
|
||||
echo "Error when mounting ${DEVICE}: udisks returned success but could not parse reply:"
|
||||
echo "---"$'\n'"$reply"$'\n'"---"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${ID_FS_TYPE} == "exfat" ]]; then
|
||||
echo "exFat does not support symlinks, do not add library to Steam"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Create a symlink from /run/media to keep compatibility with apps
|
||||
# that use the older mount point (for SD cards only).
|
||||
case "${DEVBASE}" in
|
||||
mmcblk0p*)
|
||||
if [[ -z "${ID_FS_LABEL}" ]]; then
|
||||
old_mount_point="/run/media/${DEVBASE}"
|
||||
else
|
||||
old_mount_point="/run/media/${mount_point##*/}"
|
||||
fi
|
||||
if [[ ! -d "${old_mount_point}" ]]; then
|
||||
rm -f -- "${old_mount_point}"
|
||||
ln -s -- "${mount_point}" "${old_mount_point}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "**** Mounted ${DEVICE} at ${mount_point} ****"
|
||||
|
||||
if [ -f "${mount_point}/libraryfolder.vdf" ]; then
|
||||
send_steam_url "addlibraryfolder" "${mount_point}"
|
||||
else
|
||||
#TODO check permissions are 1000 when creating new SteamLibrary
|
||||
mkdir -p "${mount_point}/SteamLibrary"
|
||||
chown deck:deck "${mount_point}/SteamLibrary"
|
||||
send_steam_url "addlibraryfolder" "${mount_point}/SteamLibrary"
|
||||
fi
|
||||
}
|
||||
|
||||
do_unmount()
|
||||
{
|
||||
local mount_point=$(findmnt -fno TARGET "${DEVICE}" || true)
|
||||
if [[ -n $mount_point ]]; then
|
||||
# Remove symlink to the mount point that we're unmounting
|
||||
find /run/media -maxdepth 1 -xdev -type l -lname "${mount_point}" -exec rm -- {} \;
|
||||
else
|
||||
# If we don't know the mount point then remove all broken symlinks
|
||||
find /run/media -maxdepth 1 -xdev -xtype l -exec rm -- {} \;
|
||||
fi
|
||||
}
|
||||
|
||||
do_retrigger()
|
||||
{
|
||||
local mount_point=$(findmnt -fno TARGET "${DEVICE}" || true)
|
||||
[[ -n $mount_point ]] || return 0
|
||||
|
||||
# In retrigger mode, we want to wait a bit for steam as the common pattern is starting in parallel with a retrigger
|
||||
wait_steam 10
|
||||
# This is a truly gnarly way to ensure steam is ready for commands.
|
||||
# TODO literally anything else
|
||||
sleep 6
|
||||
send_steam_url "addlibraryfolder" "${mount_point}"
|
||||
}
|
||||
|
||||
case "${ACTION}" in
|
||||
add)
|
||||
do_mount
|
||||
;;
|
||||
remove)
|
||||
do_unmount
|
||||
;;
|
||||
retrigger)
|
||||
do_retrigger
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
#Steam Deck Mount External Drive by scawp
|
||||
#License: DBAD: https://github.com/scawp/Steam-Deck.Mount-External-Drive/blob/main/LICENSE.md
|
||||
#Source: https://github.com/scawp/Steam-Deck.Mount-External-Drive
|
||||
# Use at own Risk!
|
||||
|
||||
#curl -sSL https://raw.githubusercontent.com/scawp/Steam-Deck.Mount-External-Drive/main/curl_install.sh | bash
|
||||
|
||||
#stop running script if anything returns an error (non-zero exit )
|
||||
set -e
|
||||
|
||||
repo_url="https://raw.githubusercontent.com/scawp/Steam-Deck.Mount-External-Drive/main"
|
||||
repo_lib_dir="$repo_url/lib"
|
||||
|
||||
tmp_dir="/tmp/scawp.SDMED.install"
|
||||
|
||||
rules_install_dir="/etc/udev/rules.d"
|
||||
service_install_dir="/etc/systemd/system"
|
||||
script_install_dir="/home/deck/.local/share/scawp/SDMED"
|
||||
|
||||
device_name="$(uname --nodename)"
|
||||
user="$(id -u deck)"
|
||||
|
||||
if [ "$device_name" != "steamdeck" ] || [ "$user" != "1000" ]; then
|
||||
zenity --question --width=400 \
|
||||
--text="This code has been written specifically for the Steam Deck with user Deck \
|
||||
\nIt appears you are running on a different system/non-standard configuration. \
|
||||
\nAre you sure you want to continue?"
|
||||
if [ "$?" != 0 ]; then
|
||||
#NOTE: This code will never be reached due to "set -e", the system will already exit for us but just incase keep this
|
||||
echo "bye then! xxx"
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
function install_automount () {
|
||||
zenity --question --width=400 \
|
||||
--text="Read $repo_url/README.md before proceeding. \
|
||||
\nDo you want to install the Auto-Mount Service?"
|
||||
if [ "$?" != 0 ]; then
|
||||
#NOTE: This code will never be reached due to "set -e", the system will already exit for us but just incase keep this
|
||||
echo "bye then! xxx"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo "Making tmp folder $tmp_dir"
|
||||
mkdir -p "$tmp_dir"
|
||||
|
||||
echo "Downloading Required Files"
|
||||
curl -o "$tmp_dir/automount.sh" "$repo_url/automount.sh"
|
||||
curl -o "$tmp_dir/external-drive-mount@.service" "$repo_lib_dir/external-drive-mount@.service"
|
||||
curl -o "$tmp_dir/99-steamos-automount.rules" "$repo_lib_dir/99-steamos-automount.rules"
|
||||
|
||||
echo "Making script folder $script_install_dir"
|
||||
mkdir -p "$script_install_dir"
|
||||
|
||||
echo "Copying $tmp_dir/automount.sh to $script_install_dir/automount.sh"
|
||||
sudo cp "$tmp_dir/automount.sh" "$script_install_dir/automount.sh"
|
||||
|
||||
echo "Adding Execute and Removing Write Permissions"
|
||||
sudo chmod 555 $script_install_dir/automount.sh
|
||||
|
||||
echo "Copying $tmp_dir/99-steamos-automount.rules to $rules_install_dir/99-steamos-automount.rules"
|
||||
sudo cp "$tmp_dir/99-steamos-automount.rules" "$rules_install_dir/99-steamos-automount.rules"
|
||||
|
||||
#remove old rules if installed
|
||||
if [ -f "$rules_install_dir/99-external-drive-mount.rules" ]; then
|
||||
sudo rm "$rules_install_dir/99-external-drive-mount.rules"
|
||||
fi
|
||||
|
||||
if [ -f "$rules_install_dir/98-external-drive-mount.rules" ]; then
|
||||
sudo rm "$rules_install_dir/98-external-drive-mount.rules"
|
||||
fi
|
||||
|
||||
echo "Copying $tmp_dir/external-drive-mount@.service to $service_install_dir/external-drive-mount@.service"
|
||||
sudo cp "$tmp_dir/external-drive-mount@.service" "$service_install_dir/external-drive-mount@.service"
|
||||
|
||||
echo "Reloading Services"
|
||||
sudo udevadm control --reload
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
install_automount
|
||||
|
||||
zenity --question --width=400 \
|
||||
--text="Restart Required to take effect, \
|
||||
\nDo you want to Restart Now?"
|
||||
if [ "$?" != 0 ]; then
|
||||
#NOTE: This code will never be reached due to "set -e", the system will already exit for us but just incase keep this
|
||||
echo "bye then! xxx"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
reboot
|
||||
|
||||
echo "Done."
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
#Steam Deck Mount External Drive by scawp
|
||||
#License: DBAD: https://github.com/scawp/Steam-Deck.Mount-External-Drive/blob/main/LICENSE.md
|
||||
#Source: https://github.com/scawp/Steam-Deck.Mount-External-Drive
|
||||
# Use at own Risk!
|
||||
|
||||
script_dir="$(dirname $(realpath "$0"))"
|
||||
lib_dir="$script_dir/lib"
|
||||
conf_dir="$script_dir/conf"
|
||||
rules_install_dir="/etc/udev/rules.d"
|
||||
service_install_dir="/etc/systemd/system"
|
||||
|
||||
echo -en "Read https://github.com/scawp/Steam-Deck.Mount-External-Drive before proceeding. \
|
||||
\nDo you want to install the Auto-Mount Service? (y/n) :"
|
||||
read confirm
|
||||
if [ "$confirm" != "y" ]; then
|
||||
echo "bye then! xxx"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo -en "Would you like to Auto-Mount Any and All External Drives? \
|
||||
\n\"y\": Any Drive will be Auto-Mounted on insert. \
|
||||
\n\"n\": Drives that are Whitelisted using \"zMount.sh\" will be Auto-Mounted on insert. \
|
||||
\n(y/n) :"
|
||||
read confirm
|
||||
if [ "$confirm" != "y" ]; then
|
||||
echo "ALWAYS" > $conf_dir/drive_list.conf
|
||||
fi
|
||||
|
||||
echo "Copying $lib_dir/99-external-drive-mount.rules to $rules_install_dir/99-external-drive-mount.rules"
|
||||
sudo cp "$lib_dir/99-external-drive-mount.rules" "$rules_install_dir/99-external-drive-mount.rules"
|
||||
|
||||
sed -e "s&\[AUTOMOUNTSCRIPT\]&$script_dir&g" "$lib_dir/template.service" > "$lib_dir/external-drive-mount@.service"
|
||||
|
||||
echo "Copying $lib_dir/external-drive-mount@.service to $service_install_dir/external-drive-mount@.service"
|
||||
sudo cp "$lib_dir/external-drive-mount@.service" "$service_install_dir/external-drive-mount@.service"
|
||||
|
||||
echo "Adding Execute permissions"
|
||||
chmod +x $script_dir/zMount.sh
|
||||
chmod +x $script_dir/automount.sh
|
||||
|
||||
echo "Reloading Services"
|
||||
sudo udevadm control --reload
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
echo "Done."
|
||||
@@ -1,4 +0,0 @@
|
||||
# /etc/udev/rules.d/
|
||||
# sudo udevadm control --reload
|
||||
KERNEL=="sd[a-z][0-9]", ACTION=="add", RUN+="/bin/systemctl start external-drive-mount@%k.service"
|
||||
KERNEL=="sd[a-z][0-9]", ACTION=="remove", RUN+="/bin/systemctl stop external-drive-mount@%k.service"
|
||||
@@ -0,0 +1,8 @@
|
||||
# /etc/udev/rules.d/
|
||||
# sudo udevadm control --reload
|
||||
KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="add", RUN+="/bin/systemctl start --no-block external-drive-mount@%k.service"
|
||||
KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="remove", RUN+="/bin/systemctl stop --no-block external-drive-mount@%k.service"
|
||||
KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="add", RUN+="/bin/systemctl start --no-block external-drive-mount@%k.service"
|
||||
KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="remove", RUN+="/bin/systemctl stop --no-block external-drive-mount@%k.service"
|
||||
KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="add", RUN+="/bin/systemctl start --no-block external-drive-mount@%k.service"
|
||||
KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="remove", RUN+="/bin/systemctl stop --no-block external-drive-mount@%k.service"
|
||||
@@ -8,5 +8,5 @@ Description=Mount External Drive on %i
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=true
|
||||
ExecStart=[AUTOMOUNTSCRIPT]/automount.sh add %i
|
||||
ExecStop=[AUTOMOUNTSCRIPT]/automount.sh remove %i
|
||||
ExecStart=/home/deck/.local/share/scawp/SDMED/automount.sh add %i
|
||||
ExecStop=/home/deck/.local/share/scawp/SDMED/automount.sh remove %i
|
||||
@@ -1,12 +0,0 @@
|
||||
# /etc/systemd/system
|
||||
# maybe move to user? ~/.local/share/systemd/user
|
||||
# sudo systemctl daemon-reload
|
||||
|
||||
[Unit]
|
||||
Description=Mount External Drive on %i
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=true
|
||||
ExecStart=[AUTOMOUNTSCRIPT]/automount.sh add %i
|
||||
ExecStop=[AUTOMOUNTSCRIPT]/automount.sh remove %i
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/bin/bash
|
||||
#Steam Deck Mount External Drive by scawp
|
||||
#License: DBAD: https://github.com/scawp/Steam-Deck.Mount-External-Drive/blob/main/LICENSE.md
|
||||
#Source: https://github.com/scawp/Steam-Deck.Mount-External-Drive
|
||||
# Use at own Risk!
|
||||
|
||||
script_dir="$(dirname $(realpath "$0"))"
|
||||
tmp_dir="$script_dir/temp"
|
||||
log_dir="$script_dir/logs"
|
||||
config_dir="$script_dir/config"
|
||||
|
||||
mkdir -p "$tmp_dir"
|
||||
mkdir -p "$log_dir"
|
||||
mkdir -p "$config_dir"
|
||||
|
||||
function log_error () {
|
||||
echo "$1" | sed "s&^&[$(date "+%F %T")] ("$0") &" | tee -a "$log_dir/error.log"
|
||||
}
|
||||
|
||||
function log_msg () {
|
||||
echo "$1" | sed "s&^&[$(date "+%F %T")] ("$0") &" | tee -a "$log_dir/info.log"
|
||||
}
|
||||
|
||||
function mount_drive () {
|
||||
udisksctl mount --no-user-interaction -b "$1" 2> $tmp_dir/last_error.log 1> $tmp_dir/last_msg.log
|
||||
if [ "$?" != 0 ]; then
|
||||
log_error "$(sed -n '1p' $tmp_dir/last_error.log)"
|
||||
else
|
||||
log_msg "$(sed -n '1p' $tmp_dir/last_msg.log)"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -f "$config_dir/drive_list.conf" ]; then
|
||||
while read -r drive_uuid; do
|
||||
mount_drive "/dev/disk/by-uuid/$drive_uuid"
|
||||
done < "$config_dir/drive_list.conf"
|
||||
else
|
||||
log_error "No Config file, Run \"./zMount.sh\" and add a drive to \"Boot on Start up\"!"
|
||||
fi
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 142 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 59 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.9 KiB |
@@ -1,152 +0,0 @@
|
||||
#!/bin/bash
|
||||
#Steam Deck Mount External Drive by scawp
|
||||
#License: DBAD: https://github.com/scawp/Steam-Deck.Mount-External-Drive/blob/main/LICENSE.md
|
||||
#Source: https://github.com/scawp/Steam-Deck.Mount-External-Drive
|
||||
# Use at own Risk!
|
||||
|
||||
script_dir="$(dirname $(realpath "$0"))"
|
||||
tmp_dir="$script_dir/temp"
|
||||
log_dir="$script_dir/logs"
|
||||
config_dir="$script_dir/config"
|
||||
|
||||
mkdir -p "$tmp_dir"
|
||||
mkdir -p "$log_dir"
|
||||
mkdir -p "$config_dir"
|
||||
|
||||
external_drive_list="$tmp_dir/external_drive_list.txt"
|
||||
|
||||
#TODO this is to fore kdesu dialog to use sudo, maybe theres a better way?
|
||||
if [ ! -f ~/.config/kdesurc ];then
|
||||
touch ~/.config/kdesurc
|
||||
echo "[super-user-command]" > ~/.config/kdesurc
|
||||
echo "super-user-command=sudo" >> ~/.config/kdesurc
|
||||
fi
|
||||
|
||||
function log_error () {
|
||||
echo "$1" | sed "s&^&[$(date "+%F %T")] ("$0") &" | tee -a "$log_dir/error.log"
|
||||
}
|
||||
|
||||
function log_msg () {
|
||||
echo "$1" | sed "s&^&[$(date "+%F %T")] ("$0") &" | tee -a "$log_dir/info.log"
|
||||
}
|
||||
|
||||
function list_gui () {
|
||||
#IFS=$';';
|
||||
# --extra-button "Auto Mount"
|
||||
selected_device=$(zenity --list --title="Select Drive to (un)Mount" \
|
||||
--width=1000 --height=360 --print-column=ALL --separator="\t" \
|
||||
--ok-label "(Un)Mount" --extra-button "Refresh" \
|
||||
--column="Path" --column="Size" --column="UUID" \
|
||||
--column="Mount Point" \
|
||||
$(cat "$external_drive_list" | sed -e 's/$/\t/'))
|
||||
ret_value="$?"
|
||||
#unset IFS;
|
||||
}
|
||||
|
||||
function confirm_gui () {
|
||||
zenity --question --width=400 \
|
||||
--text="Do you want to $1 device $2 with uuid of $3?"
|
||||
|
||||
if [ "$?" = 1 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
function get_drive_list () {
|
||||
lsblk -nlo HOTPLUG,PATH,SIZE,UUID,MOUNTPOINT | grep -i '^\s*1' | awk '$4!=""' | awk '{ if ( $5!="") print $2"\t"$3"\t"$4"\t"$5;else print $2"\t"$3"\t"$4"\tUnmounted"}' > "$external_drive_list"
|
||||
}
|
||||
|
||||
function sudo_mount_drive () {
|
||||
if [ "$1" = "mount" ]; then
|
||||
kdesu -c "udisksctl mount -b \"/dev/disk/by-uuid/$2\" 2> $tmp_dir/last_error.log 1> $tmp_dir/last_msg.log"
|
||||
else
|
||||
kdesu -c "udisksctl unmount -b \"/dev/disk/by-uuid/$2\" 2> $tmp_dir/last_error.log 1> $tmp_dir/last_msg.log"
|
||||
fi
|
||||
|
||||
if [ "$?" != 0 ]; then
|
||||
log_error "$(sed -n '1p' $tmp_dir/last_error.log)"
|
||||
ret_value="$(sed -n '1p' $tmp_dir/last_error.log)"
|
||||
ret_success=0
|
||||
else
|
||||
log_msg "$(sed -n '1p' $tmp_dir/last_msg.log)"
|
||||
ret_value="$(sed -n '1p' $tmp_dir/last_msg.log)"
|
||||
ret_success=1
|
||||
fi
|
||||
}
|
||||
|
||||
function mount_drive () {
|
||||
if [ "$1" = "mount" ]; then
|
||||
udisksctl mount --no-user-interaction -b "/dev/disk/by-uuid/$2" 2> $tmp_dir/last_error.log 1> $tmp_dir/last_msg.log
|
||||
else
|
||||
udisksctl unmount --no-user-interaction -b "/dev/disk/by-uuid/$2" 2> $tmp_dir/last_error.log 1> $tmp_dir/last_msg.log
|
||||
fi
|
||||
|
||||
if [ "$?" != 0 ]; then
|
||||
log_error "$(sed -n '1p' $tmp_dir/last_error.log)"
|
||||
ret_value="$(sed -n '1p' $tmp_dir/last_error.log)"
|
||||
sudo_mount_drive $1 $2
|
||||
else
|
||||
log_msg "$(sed -n '1p' $tmp_dir/last_msg.log)"
|
||||
ret_value="$(sed -n '1p' $tmp_dir/last_msg.log)"
|
||||
ret_success=1
|
||||
fi
|
||||
}
|
||||
|
||||
function main () {
|
||||
get_drive_list
|
||||
list_gui
|
||||
echo "$ret_value"
|
||||
mount_point="$(echo "$selected_device" | awk '{ print $4 }')"
|
||||
path="$(echo "$selected_device" | awk '{ print $1 }')"
|
||||
uuid="$(echo "$selected_device" | awk '{ print $3 }')"
|
||||
|
||||
echo "the path: $path"
|
||||
if [ "$ret_value" = 1 ]; then
|
||||
if [ "$selected_device" = "Refresh" ]; then
|
||||
main
|
||||
else
|
||||
if [ "$selected_device" = "Auto Mount" ]; then
|
||||
continue
|
||||
else
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$selected_device" = "" ]; then
|
||||
zenity --error --width=400 \
|
||||
--text="No Device Selected, Quitting!"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "$mount_point" = "Unmounted" ]; then
|
||||
confirm_gui "mount" "$path" "$uuid"
|
||||
mount_drive "mount" "$uuid"
|
||||
if [ "$ret_success" = "1" ]; then
|
||||
if [ -f "$config_dir/drive_list.conf" ]; then
|
||||
if [ ! "$(grep ^"$uuid"$ "$config_dir/drive_list.conf")" ]; then
|
||||
#TODO: Function
|
||||
zenity --question --width=400 \
|
||||
--text="Do you want to mount "$(lsblk -noMOUNTPOINT $path)" on Boot?"
|
||||
if [ "$?" = 0 ]; then
|
||||
echo "$uuid" >> "$config_dir/drive_list.conf"
|
||||
zenity --info --width=400 \
|
||||
--text="$path will be mounted on Boot"
|
||||
|
||||
exit 0;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
confirm_gui "unmount" "$path" "$uuid"
|
||||
mount_drive "unmount" "$uuid"
|
||||
fi
|
||||
|
||||
zenity --info --width=400 \
|
||||
--text="$ret_value"
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
main
|
||||
Reference in new issue
Block a user