This commit is contained in:
2023-05-28 21:35:02 +00:00
parent 46dce5ebad
commit bde200bd5c
10 changed files with 255 additions and 34 deletions

View File

@@ -1,9 +1,9 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the // For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/alpine // README at: https://github.com/devcontainers/templates/tree/main/src/alpine
{ {
"name": "Alpine", "name": "Manjaro",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:alpine-3.17", "image": "manjarolinux/build",
"features": { "features": {
"ghcr.io/devcontainers/features/nix:1": {} "ghcr.io/devcontainers/features/nix:1": {}
}, },
@@ -30,11 +30,12 @@
"eamodio.gitlens", "eamodio.gitlens",
"streetsidesoftware.code-spell-checker", "streetsidesoftware.code-spell-checker",
"timonwong.shellcheck", "timonwong.shellcheck",
"foxundermoon.shell-format" "foxundermoon.shell-format",
"yzhang.markdown-all-in-one"
] ]
} }
} },
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root" "remoteUser": "builder"
} }

12
.shellspec Normal file
View File

@@ -0,0 +1,12 @@
--require spec_helper
## Default kcov (coverage) options
# --kcov-options "--include-path=. --path-strip-level=1"
# --kcov-options "--include-pattern=.sh"
# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/"
## Example: Include script "myprog" with no extension
# --kcov-options "--include-pattern=.sh,myprog"
## Example: Only specified files/directories
# --kcov-options "--include-pattern=myprog,/lib/"

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022 stubbfel Copyright (c) 2023 stubbfel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@@ -1,4 +1,48 @@
# manjaro-sway-mirror-arm-patch # patch-manjaro-sway-mirror-for-arm
The `patch-manjaro-sway-mirror-for-arm` package is a specialized package designed for Manjaro Linux users running the Sway window manager on ARM-based systems.
This package provides a convenient solution for patching or modifying mirror configurations specific to the Manjaro Sway environment.
## Features
- Observes the `/usr/bin/manjaro-sway-mirrors` file for changes.
- Automatically executes a sed command to modify mirror configurations.
- Changes the output of `$(pacman-mirrors -G)` from "arm-stable" to "stable".
## Usage
The package includes a POSIX-compatible script, `patch-manjaro-sway-mirror-for-arm.sh`, which offers a command-line interface with various options:
```
Usage: patch-manjaro-sway-mirror-for-arm.sh [OPTIONS] [FILE] [SEARCH_PATTERN] [REPLACE_PATTERN]
Options:
-t, --target-file Specify the target file (default: /usr/bin/manjaro-sway-mirrors)
-s, --search-pattern Specify the search pattern (default: $(pacman-mirrors -G))
-r, --replace-pattern Specify the replace pattern (default: $(pacman-mirrors -G | sed 's/^arm-//'))
--dry-run Perform a dry run without modifying the file
--help Display usage information
```
## Installation
To install `patch-manjaro-sway-mirror-for-arm`, follow these steps:
1. Clone the repository or download the package.
2. Run the installation command:
```
sudo pacman -U patch-manjaro-sway-mirror-for-arm.pkg.tar.zst
```
## License
This package is licensed under the [MIT License](LICENSE).
## Contributions
Contributions to the project are welcome!
If you find any issues or have suggestions for improvements, please open an issue or submit a merge request.
## Nix Flake commands ## Nix Flake commands

4
alias.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/env sh
alias nixe='nix --experimental-features "nix-command flakes"'
alias ulock='nixe run .#devTasks.updateFlakeLock'

View File

@@ -1,10 +1,13 @@
{ {
description = ""; description = ''
With `patch-manjaro-sway-mirror-for-arm`, users can easily observe the `/usr/bin/manjaro-sway-mirrors` file for changes and automatically execute a sed command to modify its contents.
This ensures that the desired mirror configuration, specifically changing the output of `$(pacman-mirrors -G)` from "arm-stable" to "stable," is consistently maintained
'';
inputs.nixpkgs.url = "nixpkgs/nixos-22.05-small"; inputs.nixpkgs.url = "nixpkgs/nixos-22.05-small";
outputs = { self, nixpkgs }: outputs = { self, nixpkgs }:
let let
name = "manjaro-sway-mirror-arm-patch"; name = "patch-manjaro-sway-mirror-for-arm";
version = "0.0.1"; version = "0.0.1";
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
@@ -24,7 +27,7 @@
name = name; name = name;
src = self; src = self;
buildPhase = "echo nothing todo"; buildPhase = "echo nothing todo";
installPhase = "mkdir -p $out/bin; install -t $out/bin src/hello.sh"; installPhase = "mkdir -p $out/bin; install -t $out/bin src/patch-manjaro-sway-mirror-for-arm.sh";
}; };
}); });
@@ -36,7 +39,7 @@
''; '';
in in
{ {
default = { type = "app"; program = "${packages.${system}.default}/bin/hello.sh"; }; default = { type = "app"; program = "${packages.${system}.default}/bin/patch-manjaro-sway-mirror-for-arm.sh"; };
devTasks = { devTasks = {
updateFlakeLock = { type = "app"; program = "${updateLockScript}/bin/update_flake_lock.sh"; }; updateFlakeLock = { type = "app"; program = "${updateLockScript}/bin/update_flake_lock.sh"; };
autoTag = { type = "app"; program = "${devTaskScripts.${system}.autoTag}"; }; autoTag = { type = "app"; program = "${devTaskScripts.${system}.autoTag}"; };
@@ -47,30 +50,11 @@
{ {
default = nixpkgsFor.${system}.mkShell { default = nixpkgsFor.${system}.mkShell {
name = "dev-shell"; name = "dev-shell";
packages = [ ]; packages = [ nixpkgsFor.${system}.nixpkgs-fmt nixpkgsFor.${system}.shellspec ];
shellHook = '' shellHook = ''
alias nixe="nix --experimental-features 'nix-command flakes'" alias nixe="nix --experimental-features 'nix-command flakes'"
''; '';
}; };
}); });
hydraJobs = {
tarball = nixpkgsFor.x86_64-linux.releaseTools.sourceTarball {
name = name;
src = self;
version = version;
officialRelease = true;
bootstrapBuildInputs = [ ];
distPhase = ''
mkdir $out/tarballs
tar -czvf $out/tarballs/${name}-${version}.tar.gz *
'';
};
runCommandHook = {
recurseForDerivations = { };
autoTag = devTaskScripts.x86_64-linux.autoTag;
};
};
}; };
} }

View File

@@ -0,0 +1,79 @@
#!/bin/env sh
Describe "patch-manjaro-sway-mirror-for-arm.sh - Test Suite"
test_root=$(mktemp -d)
target_file="${test_root}/usr/bin/manjaro-sway-mirrors"
custom_file="${target_file}-custom"
custom_replace_pattern="replaced"
# shellcheck disable=SC2016
test_content='curl -s "https://pkg.manjaro-sway.download/$(pacman-mirrors -G)/testing"'
setup_test_data() {
export MSMAP_TARGET_ROOT="${test_root}"
mkdir -p "${test_root}/usr/bin"
echo "${test_content}" > "${target_file}"
cp -f "${target_file}" "${custom_file}"
}
teardown_test_data() {
unset MSMAP_TARGET_ROOT
rm -rf "${test_root}"
}
BeforeEach 'setup_test_data'
AfterEach 'teardown_test_data'
Describe "Help message"
It "should display the usage information"
When run src/patch-manjaro-sway-mirror-for-arm.sh --help
The output should include "Usage: patch-manjaro-sway-mirror-for-arm.sh"
The status should be success
End
End
Describe "Dry run"
It "should perform a dry run without modifying the target file"
When run src/patch-manjaro-sway-mirror-for-arm.sh --dry-run
The status should be success
The contents of file "${target_file}" should equal "${test_content}"
# shellcheck disable=SC2016
The output should equal "sed -i \"s|\\\$(pacman-mirrors -G)|\\\$(pacman-mirrors -G \| sed \\\"s/^arm-//\\\")|g\" \"${target_file}\"
curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G | sed \"s/^arm-//\")/testing\""
End
End
Describe "Default values"
It "should modify the target file with default values"
When run src/patch-manjaro-sway-mirror-for-arm.sh
The output should equal ""
The status should be success
The contents of file "${target_file}" should equal "curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G | sed \"s/^arm-//\")/testing\""
End
End
Describe "Custom target file and replace pattern"
It "should modify the custom target file with the provided replace pattern"
When run src/patch-manjaro-sway-mirror-for-arm.sh "${custom_file}" -r "${custom_replace_pattern}"
The output should equal ""
The status should be success
The contents of file "${target_file}" should equal "${test_content}"
The contents of file "$custom_file" should equal "curl -s \"https://pkg.manjaro-sway.download/replaced/testing\""
End
End
Describe "Positional arguments"
custom_search_pattern="testing"
It "should modify the target file with positional arguments"
When run src/patch-manjaro-sway-mirror-for-arm.sh "$custom_file" "${custom_search_pattern}" "${custom_replace_pattern}"
The output should equal ""
The status should be success
The contents of file "${target_file}" should equal "${test_content}"
The contents of file "$custom_file" should equal "curl -s \"https://pkg.manjaro-sway.download/\$(pacman-mirrors -G)/replaced\""
End
End
End

24
spec/spec_helper.sh Normal file
View File

@@ -0,0 +1,24 @@
# shellcheck shell=sh
# Defining variables and functions here will affect all specfiles.
# Change shell options inside a function may cause different behavior,
# so it is better to set them here.
# set -eu
# This callback function will be invoked only once before loading specfiles.
spec_helper_precheck() {
# Available functions: info, warn, error, abort, setenv, unsetenv
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION
: minimum_version "0.28.1"
}
# This callback function will be invoked after a specfile has been loaded.
spec_helper_loaded() {
:
}
# This callback function will be invoked after core modules has been loaded.
spec_helper_configure() {
# Available functions: import, before_each, after_each, before_all, after_all
: import 'support/custom_matcher'
}

View File

@@ -1,3 +0,0 @@
#!/bin/env bash
echo "hello world"

View File

@@ -0,0 +1,76 @@
#!/bin/env sh
usage() {
echo "Usage: patch-manjaro-sway-mirror-for-arm.sh [OPTIONS]"
echo "Options:"
echo " -t, --target-file Path to the target file (default: /usr/bin/manjaro-sway-mirrors)"
echo " -s, --search-pattern Search pattern to replace (default: $(pacman-mirrors -G)"
echo " -r, --replace-pattern Replace pattern (default: \$(pacman-mirrors -G \| sed 's/^arm-//'))"
echo " --dry-run Run the sed command without modifying the file"
echo " --help Display this help message"
exit 0
}
# Default values
dry_run=false
# Parse command-line options
while [ $# -gt 0 ]; do
case "$1" in
-t | --target-file)
shift
target_file="$1"
;;
-s | --search-pattern)
shift
search_pattern="$1"
;;
-r | --replace-pattern)
shift
replace_pattern="$1"
;;
--dry-run)
dry_run=true
;;
--help)
usage
;;
*)
# Check if positional arguments are provided
if [ -z "$target_file" ]; then
target_file="$1"
elif [ -z "$search_pattern" ]; then
search_pattern="$1"
elif [ -z "$replace_pattern" ]; then
replace_pattern="$1"
else
echo "Invalid argument: $1"
usage
fi
;;
esac
shift
done
if [ -z "$target_file" ]; then
target_file="${MSMAP_TARGET_ROOT}/usr/bin/manjaro-sway-mirrors"
fi
if [ -z "$search_pattern" ]; then
# shellcheck disable=SC2016
search_pattern='\$(pacman-mirrors -G)'
fi
if [ -z "$replace_pattern" ]; then
# shellcheck disable=SC2016
replace_pattern='\$(pacman-mirrors -G \| sed \"s/^arm-//\")'
fi
sed_command="sed -i \"s|${search_pattern}|${replace_pattern}|g\" \"${target_file}\""
# Perform the sed command
if $dry_run; then
echo "$sed_command"
sed "s|${search_pattern}|${replace_pattern}|g" "${target_file}"
else
eval "${sed_command}"
fi