-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
naev-confupdate.sh
executable file
·40 lines (32 loc) · 1.32 KB
/
naev-confupdate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
set -e
# This script migrates Naev's local files from deprecated locations to their
# new locations. Currently, this targets just macOS, moving files from XDG
# directories to macOS standard directories.
# Check for macOS.
[[ "$(uname)" == "Darwin" ]] || exit
# Set defaults if XDG variables aren't defined.
test -z "$XDG_DATA_HOME" && XDG_DATA_HOME=$HOME/.local/share
test -z "$XDG_CONFIG_HOME" && XDG_CONFIG_HOME=$HOME/.config
test -z "$XDG_CACHE_HOME" && XDG_CACHE_HOME=$HOME/.cache
# Determine Naev directories.
XDG_DATA="$XDG_DATA_HOME/naev"
XDG_CONFIG="$XDG_CONFIG_HOME/naev"
XDG_CACHE="$XDG_CACHE_HOME/naev"
# Determine Naev directories on macOS.
MAC_DATA="$HOME/Library/Application Support/org.naev.Naev"
MAC_CONFIG="$HOME/Library/Preferences/org.naev.Naev"
MAC_CACHE="$HOME/Library/Caches/org.naev.Naev"
# Attempt to migrate each of the XDG directories to macOS directories.
if compgen -G "$XDG_DATA/*" > /dev/null && mkdir -p $MAC_DATA; then
mv -n "$XDG_DATA"/* "$MAC_DATA/"
fi
rmdir $XDG_DATA 2> /dev/null || true
if compgen -G "$XDG_CONFIG/*" > /dev/null && mkdir -p $MAC_CONFIG; then
mv -n "$XDG_CONFIG"/* "$MAC_CONFIG/"
fi
rmdir $XDG_CONFIG 2> /dev/null || true
if compgen -G "$XDG_CACHE/*" > /dev/null && mkdir -p $MAC_CACHE; then
mv -n "$XDG_CACHE"/* "$MAC_CACHE/"
fi
rmdir $XDG_CACHE 2> /dev/null || true