Support for $XDG_CONFIG_HOME

master
Lukas Bestle 4 years ago
parent 22ada23b8b
commit e9bd0acd5f

@ -132,12 +132,12 @@ The tool `project_deploy` takes the full path to the project and the Git revisio
You can find example PHP implementations for GitHub, GitLab and Gitea webhooks in `webhook.github.php`, `webhook.gitlab.php` and `webhook.gitea.php`, but you can also create your own if you use a different repository service:
1. Write a script that receives webhooks from the repository and gets the repository URL, commit SHA-1 and branch name of the event from the transmitted data.
2. Read the file `~/.projects`, which contains the paths to all known projects and sites, and iterate through it.
2. Read the projects file at `~/.config/projectr/projects` if it exists (otherwise `~/.projects`), which contains the paths to all known projects and sites, and iterate through it.
3. Open the project's `.origin` and `.branch` files. If they match the web-hook, run `project_deploy <path> <commit-sha1>` and you are done.
### Configuration
If you want to customize specific settings, you can create a Bash file at `~/.project.cnf` to override the default values. These are the possible settings and also the format of the file:
If you want to customize specific settings, you can create a Bash file at `~/.project.cnf` or `$XDG_CONFIG_HOME/projectr/config.sh` (which defaults to `~/.config/projectr/config.sh`) to override the default values. These are the possible settings and also the format of the file:
```bash
# Default branch to set if no one is given to `project_origin`/`site_origin`

@ -35,9 +35,17 @@ if ! (mkdir "$project" && mkdir "$project/data" && touch "$project/.project"); t
fi
echo -e " => \033[32mSuccess.\033[0m"
# Add to ~/.projects
echo -e "\033[1mAdding project to \033[34m~/.projects\033[0;1m...\033[0m"
if ! echo "$(readlink -f "$project")" >> "$HOME/.projects"; then
# Determine the path to the projects file
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/projectr" ]]; then
projectsFile="$configPath/projectr/projects"
else
projectsFile="$HOME/.projects"
fi
# Add to the projects file
echo -e "\033[1mAdding project to \033[34m$projectsFile\033[0;1m...\033[0m"
if ! echo "$(readlink -f "$project")" >> "$projectsFile"; then
echo -e " => \033[31mSomething went wrong.\033[0m" >&2
exit 1
fi

@ -66,7 +66,10 @@ revision="${2:-latest}"
# Load configuration
CONFIG_PRESERVE_VERSIONS=5
CONFIG_HASH_LENGTH=40
if [[ -f "$HOME/.project.cnf" ]]; then
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -f "$configPath/projectr/config.sh" ]]; then
source "$configPath/projectr/config.sh"
elif [[ -f "$HOME/.project.cnf" ]]; then
source "$HOME/.project.cnf"
fi
if [[ $CONFIG_PRESERVE_VERSIONS == 1 ]]; then

@ -8,11 +8,19 @@
# Usage: project_list
########################################################################
# Check if the ~/.project file exists
if [[ ! -f "$HOME/.projects" ]]; then
echo -e "\033[31mThere is no \033[34m~/.projects\033[31m file yet.\033[0m" >&2
# Determine the path to the projects file
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/projectr" ]]; then
projectsFile="$configPath/projectr/projects"
else
projectsFile="$HOME/.projects"
fi
# Check if the projects file exists
if [[ ! -f "$projectsFile" ]]; then
echo -e "\033[31mThere is no \033[34m$projectsFile\033[31m file yet.\033[0m" >&2
exit 1
fi
cat "$HOME/.projects"
cat "$projectsFile"
exit $?

@ -20,7 +20,10 @@ origin="$2"
# Load configuration
CONFIG_DEFAULT_BRANCH="master"
if [[ -f "$HOME/.project.cnf" ]]; then
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -f "$configPath/projectr/config.sh" ]]; then
source "$configPath/projectr/config.sh"
elif [[ -f "$HOME/.project.cnf" ]]; then
source "$HOME/.project.cnf"
fi

@ -32,10 +32,18 @@ if ! rm -Rf $project; then
fi
echo -e " => \033[32mSuccess.\033[0m"
# Remove from ~/.projects
echo -e "\033[1mRemoving project from \033[34m~/.projects\033[0;1m...\033[0m"
# Determine the path to the projects file
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/projectr" ]]; then
projectsFile="$configPath/projectr/projects"
else
projectsFile="$HOME/.projects"
fi
# Remove from the projects file
echo -e "\033[1mRemoving project from \033[34m$projectsFile\033[0;1m...\033[0m"
realpath="$(readlink -f "$project")"
if ! sed -i "/${realpath//\//\/}/d" "$HOME/.projects"; then # Replace / with \/ because of the sed separators
if ! sed -i "/${realpath//\//\/}/d" "$projectsFile"; then # Replace / with \/ because of the sed separators
echo -e " => \033[31mSomething went wrong.\033[0m" >&2
exit 1
fi

@ -136,8 +136,12 @@ $branch = $matches[1];
// Debug
echo "Received commit hash \"$commit\" for repository URL \"$url\" (branch \"$branch\").\n";
// Open ~/.projects and iterate through every project
$listPointer = fopen($_SERVER['HOME'] . '/.projects', 'r');
// Determine the path to the projects file
$xdgProjectsFile = ($_ENV['XDG_CONFIG_HOME'] ?? ($_SERVER['HOME'] . '/.config')) . '/projectr/projects';
$projectsFile = is_file($xdgProjectsFile) === true ? $xdgProjectsFile : $_SERVER['HOME'] . '/.projects';
// Open the projects file and iterate through every project
$listPointer = fopen($projectsFile, 'r');
$exitCode = 0;
while (($project = fgets($listPointer)) !== false) {
// Trim whitespace

@ -139,8 +139,12 @@ $branch = $matches[1];
// Debug
echo "Received commit hash \"$commit\" for repository URL \"$url\" (branch \"$branch\").\n";
// Open ~/.projects and iterate through every project
$listPointer = fopen($_SERVER['HOME'] . '/.projects', 'r');
// Determine the path to the projects file
$xdgProjectsFile = ($_ENV['XDG_CONFIG_HOME'] ?? ($_SERVER['HOME'] . '/.config')) . '/projectr/projects';
$projectsFile = is_file($xdgProjectsFile) === true ? $xdgProjectsFile : $_SERVER['HOME'] . '/.projects';
// Open the projects file and iterate through every project
$listPointer = fopen($projectsFile, 'r');
$exitCode = 0;
while (($project = fgets($listPointer)) !== false) {
// Trim whitespace

@ -108,8 +108,12 @@ $branch = $matches[1];
// Debug
echo "Received commit hash \"$commit\" for repository URL \"$url\" (branch \"$branch\").\n";
// Open ~/.projects and iterate through every project
$listPointer = fopen($_SERVER['HOME'] . '/.projects', 'r');
// Determine the path to the projects file
$xdgProjectsFile = ($_ENV['XDG_CONFIG_HOME'] ?? ($_SERVER['HOME'] . '/.config')) . '/projectr/projects';
$projectsFile = is_file($xdgProjectsFile) === true ? $xdgProjectsFile : $_SERVER['HOME'] . '/.projects';
// Open the projects file and iterate through every project
$listPointer = fopen($projectsFile, 'r');
$exitCode = 0;
while (($project = fgets($listPointer)) !== false) {
// Trim whitespace

Loading…
Cancel
Save