Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Try to follow XDG specifications #47

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ make install
Currently, there is no uninstallation script, but you can super easily uninstall IndiePKG by running these commands.

```bash
rm -rf ~/.indiepkg
rm -rf ~/.local/share/indiepkg
rm ~/.local/bin/indiepkg
```

Expand Down
18 changes: 17 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"os"
"strings"

"github.com/pelletier/go-toml/v2"
)

var (
mainPath string = home + ".indiepkg/"
mainPath string = chooseDataDir()
srcPath string = mainPath + "data/package_src/"
tmpSrcPath string = mainPath + "tmp/package_src/"
infoPath string = mainPath + "data/installed_packages/"
Expand Down Expand Up @@ -105,3 +106,18 @@ func loadConfig() {
config.Paths.Prefix += "/"
}
}

// chooseDataDir returns the best directory to store data based on $INDIEPKG_DATADIR and $XDG_DATA_HOME,
// using ~/.local/share/indiepkg as the default if neither is set.
func chooseDataDir() string {
home, _ := os.UserHomeDir()
remEnv := os.Getenv("INDIEPKG_DATADIR")
if remEnv != "" {
return remEnv
}
dataHome := os.Getenv("XDG_DATA_HOME")
if dataHome != "" {
return dataHome + "/indiepkg/"
}
return home + "/.local/share/indiepkg/"
}
18 changes: 14 additions & 4 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env bash

if [ -z "$INDIEPKG_DATADIR" ]
then
if [ -n "$XDG_DATA_HOME" ]
then
INDIEPKG_DATADIR="$XDG_DATA_HOME/indiepkg"
else
INDIEPKG_DATADIR="$HOME/.local/share/indiepkg"
fi
fi

log() {
echo -e "$1[.]${RESET} $2"
}
Expand Down Expand Up @@ -58,13 +68,13 @@ chap_log "$MAGENTA=>" "Installing IndiePKG"
chap_log "$BLUE==>" "Cloning source code"

log "$CYAN" "Cloning source code..."
mkdir "$HOME/.indiepkg/"
git clone -b testing https://github.com/talwat/indiepkg.git "$HOME/.indiepkg/src"
mkdir "$INDIEPKG_DATADIR"
git clone -b testing https://github.com/talwat/indiepkg.git "$INDIEPKG_DATADIR/src"

chap_log "$BLUE==>" "Compiling source code"

log "$CYAN" "Compiling source code..."
cd "$HOME/.indiepkg/src" || exit 1
cd "$INDIEPKG_DATADIR/src" || exit 1
make

chap_log "$BLUE==>" "Installing"
Expand All @@ -73,4 +83,4 @@ log "$CYAN" "Installing..."
make install

chap_log "$GREEN=>" "Success"
success_log "$GREEN" "Installation complete!"
success_log "$GREEN" "Installation complete!"