11 Commits

Author SHA1 Message Date
e92347d035 temp! 2023-07-25 20:43:04 +01:00
da132c5fb1 Fix become for old 1password keyring removal 2023-07-08 13:53:52 +01:00
ec6cc7013c Don't trust apt_repository: anymore
Still having issues with 1password on Debian based distros due to
mismatching `signed-by` keyring. It appears as if `apt_repository:` is
changing the `signed-by` path even though it was explicitly specified in
the `repo:` setting. Instead switch to using `copy:` for complete
control over the `/etc/apt/sources.list.d/1password.list` file.
2023-07-08 11:43:54 +01:00
31a819e481 Stop using apt_key: module to install keyrings
Fixes #16 by replacing uses of the `apt_key:` module with `get_url:` to
download apt keyrings into `/etc/apt/keyrings`, then used
`signed-by=/etc/path/keyrings/<keyring>` in the appropriate sources.list
file.
2023-06-24 11:25:54 +01:00
026969a32d Add todo to obsidian 2023-06-18 23:59:15 +01:00
65f44a8454 Install webcatalog icon from AppImage 2023-06-18 23:55:01 +01:00
960f853d1f Install obsidian icon from AppImage 2023-06-18 23:54:39 +01:00
5fbc85dade xremap role not currently working on Debian unstable
Only known to work on Fedora 38, service fails to start on Debian
unstable as of today.
2023-06-16 14:11:05 +01:00
befb02bc95 Make RedHat obsidian support work for all Linux 2023-06-16 10:42:13 +01:00
352ef4c8d4 Remove CAD apps because of Autodesk
Autodesk change distribution of Fusion360 to require a login breaking
the Chocolatey package, easier to manage this manually anyway since they
won't be installed on all Windows systems.
2023-06-10 11:18:30 +01:00
878db362cd Add xremap role for macOS bindings on Linux 2023-06-08 23:41:06 +01:00
21 changed files with 1884 additions and 88 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,2 @@
external
modules/win_git*
playbooks/test.yaml

View File

@@ -1,5 +1,5 @@
[defaults]
collections_path = collections
library = modules
library = library
roles_path = roles
stdout_callback = yaml

1194
git.py Normal file

File diff suppressed because it is too large Load Diff

344
library/win_git.ps1 Normal file
View File

@@ -0,0 +1,344 @@
#!powershell
#AnsibleRequires -CSharpUtil Ansible.Basic
#AnsibleRequires -PowerShell Ansible.ModuleUtils.CommandUtil
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{
options = @{
dest = @{ type = 'path' }
repo = @{ required = $true; aliases = @( 'name' ) }
version = @{ default = 'HEAD' }
remote = @{ default = 'origin' }
executable = @{ default = $null; type = 'path' }
}
supports_check_mode = $false
})
$dest = $module.Params.dest
$repo = $module.Params.repo
$version = $module.Params.version
$remote = $module.Params.remote
$git = $module.Params.executable
if ( !$git ) {
$git = Get-ExecutablePath 'git'
}
# ================================= Utilities ==================================
function Test-SshAcceptNewHostKey {
try {
$ssh = Get-ExecutablePath 'ssh'
} catch {
throw 'Remote host is missing ssh command, so you cannot use acceptnewhostkey option.'
}
$result = Run-Command "$ssh -o StrictHostKeyChecking=accept-new -V"
if ( $result.rc -ne 0 ) {
return $false
}
return $true
}
function Get-AbsolutePath {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [String] $path
)
try {
$result = Resolve-Path $path
} catch {
return $_[0].TargetObject
}
return $result
}
function Get-GitDir {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [String] $path
)
$git_dir = Join-Path $path '.git'
# Check if this .git is a file.
if ( [System.IO.File]::Exists($git_dir) ) {
# Extract the gitdir: path from the .git file.
$groups = Get-Content "$git_dir" | `
Select-String '(gitdir:) (.*)' | `
ForEach { $_.Matches[0].Groups[1..2] }
$ref_prefix = $groups[0]
$gitdir = $groups[1]
if ( $ref_prefix -ne 'gitdir:' ) {
$module.FailJson('The .git file has invalid gitdir reference format.')
}
# Check if the repo path is absolute.
if ( [System.IO.Path]::IsPathRooted($gitdir) ) {
$git_dir = $gitdir
} else {
# Join with the input path to construct an absolute path.
$git_dir = Join-Path $path $gitdir
}
if ( ![System.IO.Directory]::Exists($git_dir) ) {
throw "$git_dir is not a directory."
}
}
return $git_dir
}
function Get-GitSshExecutablePath {
if ( $env:GIT_SSH ) {
return $env:GIT_SSH
}
if ( $env:GIT_SSH_COMMAND ) {
return $env:GIT_SSH_COMMAND
}
return Get-ExecutablePath 'ssh'
}
function Test-GitRemoteBranch {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $repository,
[Parameter(Mandatory = $true)] [String] $branch
)
$command = "`"$git`" ls-remote $repository -h refs/heads/$branch"
$result = Run-Command -command $command
if ( $result.stdout.Contains($version) ) {
return $true
}
return $false
}
function Test-GitRemoteTag {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $repository,
[Parameter(Mandatory = $true)] [String] $tag
)
$command = "`"$git`" ls-remote $repository -t refs/tags/$tag"
$result = Run-Command -command $command
if ( $result.stdout.Contains($version) ) {
return $true
}
return $false
}
function Test-GitLocalChanges {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [String] $dest
)
$command = "`"$git`" status --porcelain"
$result = Run-Command -command $command -working_directory $dest
$changes = $result.stdout.Split([System.Environment]::NewLine, `
[System.StringSplitOptions]::RemoveEmptyEntries) | `
Where-Object { -not $_.StartsWith('??') } | Measure-Object -Line
return $changes.Lines -gt 0
}
function Get-GitRemoteHead {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [String] $repo,
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $version,
[Parameter(Mandatory = $true)] [String] $remote
)
$cloning = $false
$cwd = $null
$tag = $false
if ( $remote -eq $repo ) {
$cloning = $true
} else {
$cwd = $dest
}
if ( $version -eq 'HEAD' ) {
if ( $cloning ) {
# Cloning the repo, just get the remote's HEAD version.
$command = "`"$git`" ls-remote $remote -h HEAD"
} else {
$head_branch = Get-GitRemoteHeadBranch $module $dest $remote
$command = "`"$git`" ls-remote $remote -h refs/heads/$head_branch"
}
} elseif ( Test-GitRemoteBranch $dest $remote $version ) {
$command = "`"$git`" ls-remote $remote -h refs/head/$version"
} elseif ( Test-GitRemoteTag $dest $remote $version ) {
$tag = $true
$command = "`"$git`" ls-remote $remote -t refs/tags/$version*"
} else {
# Appears to be a sha1, return as-is since it apparently not possible
# to check for a specific sha1 on remote.
return $version
}
$result = Run-Command -command $command -working_directory $cwd
if ( $result.rc -ne 0 -or $result.stdout.Length -lt 1 ) {
throw "Could not determine remote ref for $vesion"
}
$ref = $result.stdout
if ( $tag ) {
# Find the dereferenced tag if this is an annotated tag.
ForEach ( $tag in $ref.Split([System.Environment]::NewLine) ) {
if ( $tag.EndsWith("$version ^{}") ) {
$ref = $tag
} elseif ( $tag.EndsWith($version) ) {
$ref = $tag
}
}
}
return $ref.Split()[0]
}
function Test-GitDetachedHead {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $dest
)
}
function Get-GitRemoteHeadBranch {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $version,
[Parameter(Mandatory = $true)] [String] $remote
)
$git_dir = Join-Path $dest '.git'
# TODO: Check if the .git is a file. If it is a file, it means that we are
# in a submodule structure.
$head_file = Join-Path $git_dir 'HEAD'
if ( Test-GitDetachedHead $dest ) {
$head_file = Join-Path $git_dir 'refs' 'remotes' $remote 'HEAD'
}
}
function Get-GitCurrentSha {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $dest
)
$command = "`"$git`" rev-parse HEAD"
$result = Run-Command -command $command -working_directory $dest
return $result.stdout.Trim()
}
function Get-GitRemoteUrl {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $remote
)
$command = "`"$git`" ls-remote --get-url $remote"
$result = Run-Command -command $command -working_directory $dest
if ( $result.rc -ne 0 ) {
# There was an issue getting the remote URL, most likely command is not
# available in this version of Git.
return $null
}
return $result.stdout.Trim()
}
function Set-GitRemoteUrl {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $remote,
[Parameter(Mandatory = $true)] [String] $url
)
# Return if remote URL isn't changing.
$remote_url = Get-GitRemoteUrl $dest $remote
if ( $remote_url -eq $repo ) {
return $false
}
$command = "`"$git`" remote set-url $remote $url"
$result = Run-Command -command $command -working_directory $dest
if ( $result.rc -ne 0 ) {
$module.FailJson("Failed to set a new url $url for $remote`: $result.stderr")
}
# Return false if remote_url is null to maintain previous behavior for Git
# versions prior to 1.7.5 that lack required functionality.
return $remote_url -ne $null
}
function Invoke-GitClone {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $repo,
[Parameter(Mandatory = $true)] [String] $remote,
[Parameter(Mandatory = $true)] [String] $dest
)
$dest_parent = Split-Path -Path $dest -Parent
if ( !(Test-Path $dest_parent) ) {
New-Item -Path $dest_parent -ItemType Directory
}
$command = "`"$git`" clone --recursive --origin $remote $repo $dest"
if ( $version -ne "HEAD" ) {
$command += " --branch $version"
}
$result = Run-Command -command $command -working_directory $cwd
if ( $result.rc -ne 0 ) {
$module.FailJson($result.stderr)
}
# Ensure the newly cloned repository has the correct owner
$userName = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$idRef = [System.Security.Principal.NTAccount]::new($userName)
Get-Item $dest | foreach { `
$_ ; $_ | Get-ChildItem -Force -Recurse `
} | foreach { `
$acl = $_ | Get-Acl; $acl.SetOwner($idRef); $_ | Set-Acl -AclObject $acl `
}
}
function Invoke-GitFetch {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $repo,
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $version,
[Parameter(Mandatory = $true)] [String] $remote
)
$command = "`"$git`" fetch --tags $remote"
$result = Run-Command -command $command -working_directory $dest
if ( $result.rc -ne 0 ) {
$module.FailJson("Failed to download remote objects and refs:" + `
"$result.stdout $result.stderr")
}
}
function Invoke-GitCheckout {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [String] $dest,
[Parameter(Mandatory = $true)] [String] $version
)
$result = Run-Command -command "`"$git`" checkout $version" -working_directory $dest
if ( $result.rc -ne 0 ) {
$module.FailJson("Failed to checkout version '$version': " + `
"$result.stdout $result.stderr")
}
}
# ================================ Start logic =================================
if ( !$dest ) {
$module.FailJson('The destination directory must be specified.')
}
$dest = Get-AbsolutePath $dest
$git_dir = Get-GitDir $dest
$gitconfig = Join-Path $git_dir 'config'
$module.Result.before = $null
$local_changes = $false
if ( ($dest -and ![System.IO.File]::Exists($gitconfig)) -or (!$dest -and !$clone) ) {
Invoke-GitClone $repo $remote $dest $version
$module.Result.changed = $true
} else {
$local_changes = Test-GitLocalChanges $dest
$module.Result.before = Get-GitCurrentSha $dest
if ( $local_changes ) {
$module.FailJson('Local modifications exist in repository.')
}
# Checkout branch, if $version is HEAD get HEAD branch
# Pull
}
$module.ExitJson()

64
library/win_git.py Normal file
View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# TODO: copyright
DOCUMENTATION = '''
---
module: win_git
author:
- "Kenneth Benzie (Benie)"
short_description: Deploy software (or files) from git checkouts on Windows
description:
- Manage git checkouts of repositories to deploy files or software on Windows.
options:
data:
description:
- Alternate data to return instead of 'pong'.
- If this parameter is set to C(crash), the module will cause an
exception.
type: str
default: pong
seealso:
- module: ansible.builtin.git
'''
# DOCUMENTATION = r'''
# ---
# module: win_ping
# short_description: A windows version of the classic ping module
# description:
# - Checks management connectivity of a windows host.
# - This is NOT ICMP ping, this is just a trivial test module.
# - For non-Windows targets, use the M(ansible.builtin.ping) module instead.
# options:
# data:
# description:
# - Alternate data to return instead of 'pong'.
# - If this parameter is set to C(crash), the module will cause an exception.
# type: str
# default: pong
# seealso:
# - module: ansible.builtin.ping
# author:
# - Chris Church (@cchurch)
# '''
EXAMPLES = r'''
# Test connectivity to a windows host
# ansible winserver -m ansible.windows.win_ping
- name: Example from an Ansible Playbook
ansible.windows.win_ping:
- name: Induce an exception to see what happens
ansible.windows.win_ping:
data: crash
'''
RETURN = r'''
ping:
description: Value provided with the data parameter.
returned: success
type: str
sample: pong
'''

View File

@@ -3,5 +3,6 @@
- import_playbook: UnixGUI.yaml
- hosts: localhost
roles:
- role: gnome-shell
- role: kitty
- role: xremap
when: ansible_os_family == "RedHat"

View File

@@ -1,9 +1,6 @@
---
- hosts: windows
vars:
install_cad_apps: false
roles:
- role: python
- role: git
@@ -16,6 +13,7 @@
- role: curl
- role: fzf
- role: gh
- role: glab
- role: jq
- role: tree
- role: yq
@@ -29,8 +27,3 @@
- role: obsidian
- role: powertoys
- role: windows-terminal
- role: autodesk-fusion360
when: install_cad_apps
- role: prusaslicer
when: install_cad_apps

View File

@@ -1,16 +1,24 @@
---
- set_fact:
keyring: /etc/apt/trusted.gpg.d/1password-archive-keyring.gpg
- name: set keyring path
set_fact:
keyring: /etc/apt/keyrings/1password.asc
old_keyring: /etc/apt/trusted.gpg.d/1password-archive-keyring.gpg
- name: remove old keyring
become: true
file:
path: '{{old_keyring}}'
state: absent
- name: add apt signing key
when: '"WSL" not in ansible_kernel'
become: true
apt_key:
get_url:
url: https://downloads.1password.com/linux/keys/1password.asc
keyring: '{{keyring}}'
state: present
dest: '{{keyring}}'
- when: ansible_machine == 'x86_64'
- name: set compatible architecture
when: ansible_machine == 'x86_64'
set_fact:
arch: amd64
@@ -21,11 +29,11 @@
- name: add apt repository
when: '"WSL" not in ansible_kernel'
become: true
apt_repository:
repo: >-
copy:
content: >-
deb [arch={{arch}} signed-by={{keyring}}]
https://downloads.1password.com/linux/debian/{{arch}} stable main
filename: 1password
dest: /etc/apt/sources.list.d/1password.list
- name: install gui package
when: '"WSL" not in ansible_kernel'

View File

@@ -1,8 +0,0 @@
---
- assert:
that: ansible_os_family == "Windows"
- name: install chocolatey package
win_chocolatey:
name: autodesk-fusion360
state: latest

View File

@@ -31,17 +31,17 @@
- include_tasks: Windows-installer.yaml
when: git_run_installer
- name: clone config repos
win_git:
repo: '{{item.repo}}'
dest: '{{ansible_env.USERPROFILE}}/.config/{{item.name}}'
version: master
with_items: '{{git_config_repos}}'
- win_owner:
path: '{{ansible_env.USERPROFILE}}/.config/{{item.name}}'
user: Benie
recurse: true
with_items: '{{git_config_repos}}'
# - name: clone config repos
# win_git:
# repo: '{{item.repo}}'
# dest: '{{ansible_env.USERPROFILE}}\.config\{{item.name}}'
# version: master
# with_items: '{{git_config_repos}}'
# - win_owner:
# path: '{{ansible_env.USERPROFILE}}\.config\{{item.name}}'
# user: Benie
# recurse: true
# with_items: '{{git_config_repos}}'
# - TODO: install pip packages
# win_pip:

View File

@@ -1,8 +0,0 @@
---
- dconf:
# key: /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings
key: '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0'
state: read
register: custom_keybindins
- debug: msg={{custom_keybindins}}

View File

@@ -25,11 +25,44 @@
'http://apt.llvm.org/{{ubuntu_codename}}/'
llvm_apt_category:
'llvm-toolchain-{{ubuntu_codename}}-{{llvm_major_version}}'
keyring: '/etc/apt/keyrings/llvm.asc'
- name: remove old keyring
when: '"WSL" not in ansible_kernel'
become: true
apt_key:
url: https://apt.llvm.org/llvm-snapshot.gpg.key
id: 6084F3CF814B57C1CF12EFD515CF4D18AF4F7421
state: absent
- name: remove old upstream deb repository
become: true
apt_repository:
repo: 'deb {{llvm_apt_repo_url}} {{llvm_apt_category}} main'
state: absent
filename: llvm
update_cache: false
- name: remove old upstream deb-src repository
become: true
apt_repository:
repo: 'deb-src {{llvm_apt_repo_url}} {{llvm_apt_category}} main'
state: absent
filename: llvm
update_cache: false
- name: add apt repository key
become: true
get_url:
url: https://apt.llvm.org/llvm-snapshot.gpg.key
dest: '{{keyring}}'
- name: add upstream deb repository
become: true
apt_repository:
repo: 'deb {{llvm_apt_repo_url}} {{llvm_apt_category}} main'
repo: >
deb [signed-by={{keyring}}]
{{llvm_apt_repo_url}} {{llvm_apt_category}} main
state: present
filename: llvm
update_cache: false
@@ -37,18 +70,13 @@
- name: add upstream deb-src repository
become: true
apt_repository:
repo: 'deb-src {{llvm_apt_repo_url}} {{llvm_apt_category}} main'
repo: >
deb-src [signed-by={{keyring}}]
{{llvm_apt_repo_url}} {{llvm_apt_category}} main
state: present
filename: llvm
update_cache: false
- name: add apt repository key
become: true
apt_key:
url: https://apt.llvm.org/llvm-snapshot.gpg.key
id: 6084F3CF814B57C1CF12EFD515CF4D18AF4F7421
state: present
- name: update apt cache
become: true
apt:

View File

@@ -8,20 +8,17 @@
- set_fact:
vim_config_dir: '{{ansible_env.LOCALAPPDATA}}\nvim'
- name: clone config repo
win_git:
repo: git@code.infektor.net:config/vim.git
dest: '{{vim_config_dir}}'
branch: master
# clone: false
update: true
- win_owner:
path: '{{vim_config_dir}}'
user: Benie
recurse: true
- assert:
that: False
# - name: clone config repo
# win_git:
# repo: git@code.infektor.net:config/vim.git
# dest: '{{vim_config_dir}}'
# branch: master
# # clone: false
# update: true
# - win_owner:
# path: '{{vim_config_dir}}'
# user: Benie
# recurse: true
# - TODO: neovim set repo email
# win_git_config:

View File

@@ -1,4 +1,6 @@
---
# TODO: Prefer Flatpak over AppImage if available
- name: stat symlink
stat:
path: '{{ansible_env.HOME}}/.local/bin/Obsidian'
@@ -13,6 +15,7 @@
appimage: 'Obsidian-{{latest.json.name}}.AppImage'
- set_fact:
filepath: '{{ansible_env.HOME}}/.local/bin/{{appimage}}'
iconpath: 'share/icons/hicolor/512x512/apps/obsidian.png'
asset_query: '[?contains(name, `{{appimage}}`)] | [0]'
- set_fact:
needs_installed:
@@ -25,13 +28,37 @@
dest: '{{filepath}}'
mode: '0755'
- name: create directories
file:
path: '{{item}}'
state: directory
with_items:
- '{{ansible_env.HOME}}/.local/bin'
- '{{ansible_env.HOME}}/.local/share/icons/hicolor/512x512/apps'
- name: create symlink
file:
src: '{{filepath}}'
dest: '{{ansible_env.HOME}}/.local/bin/Obsidian'
state: link
# TODO: icon for desktop file
- name: extract squashfs-root for app icon
when: needs_installed
command:
cmd: '{{ansible_env.HOME}}/.local/bin/Obsidian --appimage-extract'
chdir: '/tmp'
- name: copy icon file
when: needs_installed
copy:
src: '/tmp/squashfs-root/usr/{{iconpath}}'
dest: '{{ansible_env.HOME}}/.local/{{iconpath}}'
- name: remove squashfs-root directory
when: needs_installed
file:
path: '/tmp/squashfs-root'
state: absent
- name: create desktop file
template:

View File

@@ -1,2 +1,5 @@
---
- include_tasks: '{{ansible_os_family}}.yaml'
when: ansible_os_family == "Darwin" or ansible_os_family == "Windows"
- include_tasks: 'Linux.yaml'
when: ansible_os_family != "Darwin" and ansible_os_family != "Windows"

View File

@@ -1,14 +0,0 @@
---
- assert:
that: ansible_os_family == "Windows"
- name: install chocolatey package
win_chocolatey:
name: prusaslicer
state: latest
- name: create start menu shortcut
win_shortcut:
src: '{{ansible_env.ProgramData}}/chocolatey/bin/prusa-slicer.exe'
dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/PrusaSlicer.lnk'
icon: '{{ansible_env.ProgramData}}/chocolatey/bin/prusa-slicer.exe,0'

View File

@@ -16,6 +16,7 @@
appimage: 'WebCatalog-{{releases[0].version}}.AppImage'
- set_fact:
filepath: '{{ansible_env.HOME}}/.local/bin/{{appimage}}'
iconpath: 'share/icons/hicolor/512x512/apps/webcatalog.png'
- set_fact:
needs_installed:
@@ -28,13 +29,37 @@
dest: '{{ansible_env.HOME}}/.local/bin/{{appimage}}'
mode: '0755'
- name: create directories
file:
path: '{{item}}'
state: directory
with_items:
- '{{ansible_env.HOME}}/.local/bin'
- '{{ansible_env.HOME}}/.local/share/icons/hicolor/512x512/apps'
- name: create symlink
file:
src: '{{filepath}}'
dest: '{{ansible_env.HOME}}/.local/bin/WebCatalog'
state: link
# TODO: icon for desktop file
- name: extract squashfs-root for app icon
when: needs_installed
command:
cmd: '{{ansible_env.HOME}}/.local/bin/WebCatalog --appimage-extract'
chdir: '/tmp'
- name: copy icon file
when: needs_installed
copy:
src: '/tmp/squashfs-root/usr/{{iconpath}}'
dest: '{{ansible_env.HOME}}/.local/{{iconpath}}'
- name: remove squashfs-root directory
when: needs_installed
file:
path: '/tmp/squashfs-root'
state: absent
- name: create desktop file
template:

View File

@@ -40,15 +40,18 @@
dest: external/ansible-win_git
version: master
- set_fact:
modules_dir: ~/.config/local/modules
- name: create ansible modules directory
file:
dest: ~/.ansible/plugins/modules
dest: '{{modules_dir}}'
state: directory
- name: copy win_git files to ansible modules directory
copy:
src: '~/.config/local/external/ansible-win_git/{{item}}'
dest: '~/.config/local/modules/{{item}}'
dest: '{{modules_dir}}/{{item}}'
with_items:
- win_git.ps1
- win_git.py

View File

@@ -0,0 +1,7 @@
---
- name: restart xremap
systemd:
name: xremap
scope: user
daemon_reload: true
state: restarted

View File

@@ -0,0 +1,123 @@
---
- assert:
that: ansible_env.XDG_CURRENT_DESKTOP == "GNOME" and
ansible_env.XDG_SESSION_TYPE == "wayland"
- set_fact:
install_dir: '{{ansible_env.HOME}}/.local/bin'
config_dir: '{{ansible_env.HOME}}/.config/xremap'
- set_fact:
executable_path: '{{install_dir}}/xremap'
- name: stat executable
stat:
path: '{{executable_path}}'
register: executable
- name: get installed version
when: executable.stat.exists
command: '{{executable_path}} --version'
register: version_command
changed_when: false
- name: extract version from command output
when: executable.stat.exists
set_fact:
installed_version:
'v{{version_command.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
- name: get latest release
uri:
url: https://api.github.com/repos/k0kubun/xremap/releases/latest
register: latest
- name: determine if install needed
set_fact:
needs_installed:
'{{not executable.stat.exists or installed_version != latest.json.name}}'
- name: construct asset query
set_fact:
asset_query: >
[?contains(name, `xremap-linux-{{ansible_architecture}}-{{
ansible_env.XDG_CURRENT_DESKTOP | lower}}.zip`)] | [0]
- name: get release asset
set_fact:
asset: '{{latest.json.assets | to_json | from_json | json_query(asset_query)}}'
- name: create directories
file:
path: '{{item}}'
state: directory
with_items:
- '{{install_dir}}'
- '{{config_dir}}'
- name: download release archive
when: needs_installed
become: true
get_url:
url: '{{asset.browser_download_url}}'
dest: '{{install_dir}}/xremap.zip'
- name: extract release archive
when: needs_installed
become: true
unarchive:
src: '{{install_dir}}/xremap.zip'
dest: '{{install_dir}}'
- name: remove release archive
when: needs_installed
become: true
file:
path: '{{install_dir}}/xremap.zip'
state: absent
- name: add user to input group
become: true
user:
name: '{{ansible_user_id}}'
append: true
groups: input
# TODO: This works for on Fedora, author uses it on Ubuntu so I assume Debian
# will work too. Arch and other distros are potentially different see the docs
# https://github.com/k0kubun/xremap
- name: add udev rule for input access
become: true
copy:
content: |
KERNEL=="uinput", GROUP="input", TAG+="uaccess"
dest: /etc/udev/rules.d/input.rules
- name: clone config repo
git:
repo: git@code.infektor.net:config/xremap.git
dest: '{{config_dir}}'
notify: restart xremap
- name: install xremap systemd unit
template:
src: xremap.service.j2
dest: ~/.config/systemd/user/xremap.service
notify: restart xremap
- name: enable xremap service
systemd:
name: xremap
scope: user
enabled: true
state: started
- name: check if extension is installed
command: gnome-extensions show xremap@k0kubun.com
changed_when: false
failed_when: false
register: extension
- when: extension.rc != 0
debug:
msg: 'install gnome extension then reboot:
https://extensions.gnome.org/extension/5060/xremap'
changed_when: true

View File

@@ -0,0 +1,10 @@
[Unit]
Description=macOS Key Remapping
[Service]
Type=simple
ExecStart={{executable_path}} {{config_dir}}/macOS.yaml
Restart=on-failure
[Install]
WantedBy=default.target