2024-07-17 12:18:27 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
begin
|
|
|
|
set -l dir (status dirname)
|
|
|
|
source "$dir/../../Scripts/software.fish"
|
|
|
|
|
|
|
|
function configureSW -V dir
|
|
|
|
sudo cp "$dir/rclone.service" "$dir/rclone.target" "$dir/rclone@.service" /etc/systemd/user
|
|
|
|
end
|
|
|
|
|
2024-07-20 03:08:23 +00:00
|
|
|
function userConfig -V dir -a name
|
|
|
|
source "$dir/../../Scripts/config.fish"
|
2024-10-13 17:52:28 +00:00
|
|
|
set -l key "programs.rclone.configurations"
|
2024-09-22 15:50:05 +00:00
|
|
|
set -l configs (getUserConfig "$name" "$key" --apply "builtins.attrNames" --json)
|
2024-07-20 03:08:23 +00:00
|
|
|
|
|
|
|
if [ (echo "$configs" | jq "length") -gt 0 ]
|
2024-10-06 19:25:34 +00:00
|
|
|
if [ "$XDG_SESSION_TYPE" = tty ]
|
2024-09-19 20:23:45 +00:00
|
|
|
set -l sessionPid
|
|
|
|
set -l freeTty
|
|
|
|
set -l service
|
|
|
|
set -l sessionConfig
|
|
|
|
set -l welcomeConfig ~"$name"/.config/plasma-welcomerc
|
2024-07-20 03:08:23 +00:00
|
|
|
set -l entryPoint ~"$name"/.config/autostart/PortValhallaProfile.desktop
|
2024-07-20 03:09:42 +00:00
|
|
|
sudo -u "$name" mkdir -p "$(dirname "$entryPoint")"
|
2024-07-20 03:08:23 +00:00
|
|
|
|
2024-09-19 20:23:45 +00:00
|
|
|
begin
|
|
|
|
set -l file (sudo mktemp)
|
|
|
|
sudo openvt -sw -- bash -c "tty > $(string escape $file)"
|
|
|
|
set freeTty (basename (sudo cat $file))
|
|
|
|
sudo rm $file
|
|
|
|
end
|
|
|
|
|
|
|
|
set service "getty@$freeTty"
|
|
|
|
set sessionConfig "/etc/systemd/system/$service.service.d/autologin.conf"
|
|
|
|
sudo mkdir -p (dirname $sessionConfig)
|
|
|
|
|
|
|
|
begin
|
|
|
|
printf %s\n \
|
|
|
|
"[General]" \
|
|
|
|
"LastSeenVersion=1.0.0" \
|
|
|
|
"ShowUpdatePage=false"
|
2024-10-06 19:25:34 +00:00
|
|
|
end | sudo -u "$name" tee "$welcomeConfig" >/dev/null
|
2024-09-19 20:23:45 +00:00
|
|
|
|
2024-07-20 03:08:23 +00:00
|
|
|
begin
|
|
|
|
printf %s\n \
|
|
|
|
"#!/user/bin/env xdg-open" \
|
|
|
|
"[Desktop Entry]" \
|
|
|
|
"Name=PortValhalla Profile" \
|
|
|
|
"Type=Application" \
|
|
|
|
"Terminal=false" (
|
|
|
|
printf "%s " \
|
|
|
|
"Exec=env" \
|
2024-09-19 21:48:29 +00:00
|
|
|
"VALHALLA_REQUEST_LOGOUT=1" \
|
2024-09-08 15:09:01 +00:00
|
|
|
"CONFIG_NAME=$(echo "$CONFIG_NAME" | string escape)" \
|
2024-07-20 03:08:23 +00:00
|
|
|
"konsole -e fish $(realpath (status filename) | string escape) userConfig"
|
|
|
|
)
|
2024-10-06 19:25:34 +00:00
|
|
|
end | sudo -u "$name" tee "$entryPoint" >/dev/null
|
2024-07-20 03:08:23 +00:00
|
|
|
|
|
|
|
sudo chmod +x "$entryPoint"
|
2024-09-19 20:23:45 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
printf %s\n \
|
|
|
|
"[Service]" \
|
|
|
|
"ExecStart=" \
|
|
|
|
"ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin $name %I \$TERM"
|
2024-10-06 19:25:34 +00:00
|
|
|
end | sudo tee "$sessionConfig" >/dev/null
|
2024-09-19 20:23:45 +00:00
|
|
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl restart $service
|
|
|
|
|
|
|
|
while [ -z "$sessionPid" ]
|
|
|
|
set sessionPid (sudo pgrep -t $freeTty -u "$name")
|
|
|
|
end
|
|
|
|
|
|
|
|
sudo openvt -sw -- sudo -u "$name" env (sudo cat /proc/$sessionPid/environ | string split0) /usr/lib/plasma-dbus-run-session-if-needed startplasma-wayland
|
|
|
|
sudo rm "$entryPoint"
|
|
|
|
sudo rm "$welcomeConfig"
|
|
|
|
sudo rm "$sessionConfig"
|
|
|
|
sudo rmdir (dirname "$sessionConfig")
|
|
|
|
sudo systemctl daemon-reload
|
2024-07-30 15:42:29 +00:00
|
|
|
else if [ -n "$name" ] && [ "$name" != "$USER" ]
|
2024-09-08 15:09:01 +00:00
|
|
|
sudo -Eu "$name" CONFIG_NAME="$CONFIG_NAME" fish "$(status filename)" userConfig
|
2024-07-20 03:08:23 +00:00
|
|
|
else
|
2024-07-30 15:42:29 +00:00
|
|
|
systemctl --user enable rclone.service
|
2024-07-20 03:08:23 +00:00
|
|
|
echo "Please complete the setup of your rclone configurations!"
|
2024-09-19 20:26:06 +00:00
|
|
|
mkdir -p ~/.mnt
|
|
|
|
touch ~/.mnt/.trackerignore
|
2024-07-20 11:47:07 +00:00
|
|
|
|
|
|
|
for config in (echo "$configs" | jq '.[]' --raw-output0 | string split0)
|
|
|
|
set -l configKey "$key.$config"
|
|
|
|
set -l duration "$configKey.cacheDuration"
|
|
|
|
|
2024-09-22 15:50:05 +00:00
|
|
|
set -l serviceName "rclone@$config:$(getUserConfig "$name" "$configKey.dirName")"
|
2024-07-20 11:47:07 +00:00
|
|
|
|
2024-09-22 15:50:05 +00:00
|
|
|
if isUserSet "$name" "$duration"
|
|
|
|
set serviceName "$serviceName:$(getUserConfig "$name" "$duration")"
|
2024-07-20 11:47:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
echo "Please create a remote called `$config`."
|
|
|
|
rclone config || true
|
|
|
|
systemctl --user enable "$serviceName" --now || true
|
|
|
|
end
|
2024-09-19 20:27:44 +00:00
|
|
|
|
|
|
|
echo "rclone was configured successfully!"
|
2024-09-19 21:48:29 +00:00
|
|
|
|
|
|
|
if [ -n "$VALHALLA_REQUEST_LOGOUT" ]
|
|
|
|
read -P "Please log out"
|
|
|
|
end
|
2024-07-20 03:08:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-17 12:18:27 +00:00
|
|
|
runInstaller $argv
|
|
|
|
end
|