summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore27
-rw-r--r--PROJECT.md111
-rw-r--r--files-config.txt8
-rw-r--r--path-mapping.json5
-rw-r--r--scripts/sync-from-project.ps1137
-rw-r--r--scripts/sync-to-project.ps1223
6 files changed, 511 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0278e95
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+# Fichiers temporaires
+*.tmp
+*.temp
+*.log
+
+# Fichiers système
+.DS_Store
+Thumbs.db
+desktop.ini
+
+# Fichiers d'éditeur
+.vscode/
+.idea/
+*.swp
+*.swo
+*~
+
+# Fichiers de sauvegarde
+*.bak
+*.backup
+
+# Ne pas ignorer les fichiers de configuration et scripts
+!files-config.txt
+!path-mapping.json
+!scripts/
+!configs/
+
diff --git a/PROJECT.md b/PROJECT.md
new file mode 100644
index 0000000..26d8f3b
--- /dev/null
+++ b/PROJECT.md
@@ -0,0 +1,111 @@
+# Projet : Synchronisation de fichiers de configuration
+
+## Objectif
+
+Ce projet permet de centraliser et synchroniser tous les fichiers de configuration (vim, bash, screen, cursor, documentation, etc.) depuis Windows et WSL vers un dépôt git sur chillka.
+
+## Structure du projet
+
+```
+config-files-keyvault/
+├── .git/ # Dépôt git local
+├── configs/
+│ ├── windows/ # Fichiers provenant de Windows
+│ └── wsl/ # Fichiers provenant de WSL
+├── scripts/
+│ ├── sync-to-project.ps1 # Script pour copier fichiers vers le projet
+│ └── sync-from-project.ps1 # Script pour restaurer fichiers depuis le projet
+├── files-config.txt # Liste des fichiers à synchroniser
+├── path-mapping.json # Mapping chemins originaux <-> chemins dans le projet
+└── PROJECT.md # Documentation du projet
+```
+
+## Utilisation
+
+### 1. Ajouter des fichiers à synchroniser
+
+Éditer le fichier `files-config.txt` et ajouter les fichiers au format :
+```
+windows|%USERPROFILE%\.vimrc
+wsl|~/.bashrc
+```
+
+### 2. Copier les fichiers vers le projet
+
+Exécuter le script PowerShell :
+```powershell
+.\scripts\sync-to-project.ps1
+```
+
+Ce script va :
+- Lire `files-config.txt`
+- Copier chaque fichier vers `configs/{system}/`
+- Créer/mettre à jour `path-mapping.json` avec les chemins originaux
+
+### 3. Restaurer les fichiers depuis le projet
+
+Exécuter le script PowerShell :
+```powershell
+.\scripts\sync-from-project.ps1
+```
+
+Ce script va :
+- Lire `path-mapping.json`
+- Copier chaque fichier depuis `configs/{system}/` vers son emplacement original
+- Créer les répertoires parents si nécessaire
+
+### 4. Synchronisation Git
+
+Le dépôt git est configuré avec le remote :
+```
+toshiro@chillka:/var/data/git/repositories/config-files-keyvault.git
+```
+
+Pour synchroniser :
+```powershell
+git add .
+git commit -m "Mise à jour des fichiers de configuration"
+git push origin main
+```
+
+## Format de fichiers-config.txt
+
+Chaque ligne doit suivre le format :
+```
+{système}|{chemin}
+```
+
+Où :
+- `{système}` : `windows` ou `wsl`
+- `{chemin}` : Chemin du fichier avec support des variables d'environnement Windows (`%VAR%`) ou expansion WSL (`~`)
+
+Exemples :
+```
+windows|%USERPROFILE%\.vimrc
+windows|%APPDATA%\Code\User\settings.json
+wsl|~/.bashrc
+wsl|~/.bash_aliases
+wsl|~/.screenrc
+```
+
+## Format de path-mapping.json
+
+Ce fichier est généré automatiquement par le script `sync-to-project.ps1`. Il contient le mapping entre les chemins originaux et les chemins dans le projet :
+
+```json
+{
+ "windows": {
+ "%USERPROFILE%\\.vimrc": "configs/windows/.vimrc"
+ },
+ "wsl": {
+ "~/.bashrc": "configs/wsl/.bashrc"
+ }
+}
+```
+
+## Notes
+
+- Les fichiers sont organisés par système d'origine (windows/wsl) pour faciliter la gestion
+- Le mapping des chemins permet de restaurer les fichiers à leur emplacement exact
+- Les répertoires parents sont créés automatiquement lors de la restauration
+
diff --git a/files-config.txt b/files-config.txt
new file mode 100644
index 0000000..a1c80cf
--- /dev/null
+++ b/files-config.txt
@@ -0,0 +1,8 @@
+# Format: {système}|{chemin}
+# Système: windows ou wsl
+# Chemin: supporte les variables d'environnement Windows (%VAR%) et expansion WSL (~)
+#
+# Exemples:
+# windows|%USERPROFILE%\.vimrc
+# wsl|~/.bashrc
+
diff --git a/path-mapping.json b/path-mapping.json
new file mode 100644
index 0000000..05c07d5
--- /dev/null
+++ b/path-mapping.json
@@ -0,0 +1,5 @@
+{
+ "windows": {},
+ "wsl": {}
+}
+
diff --git a/scripts/sync-from-project.ps1 b/scripts/sync-from-project.ps1
new file mode 100644
index 0000000..45ff258
--- /dev/null
+++ b/scripts/sync-from-project.ps1
@@ -0,0 +1,137 @@
+# Script pour restaurer les fichiers de configuration depuis le projet
+# Lit path-mapping.json et copie chaque fichier vers son emplacement original
+
+param(
+ [string]$MappingFile = "path-mapping.json"
+)
+
+$ErrorActionPreference = "Stop"
+
+# Vérifier que le fichier de mapping existe
+if (-not (Test-Path $MappingFile)) {
+ Write-Error "Le fichier de mapping '$MappingFile' n'existe pas. Exécutez d'abord sync-to-project.ps1"
+ exit 1
+}
+
+# Charger le mapping
+try {
+ $mapping = Get-Content $MappingFile -Raw | ConvertFrom-Json
+} catch {
+ Write-Error "Impossible de charger le fichier de mapping: $_"
+ exit 1
+}
+
+$restoredCount = 0
+$skippedCount = 0
+$errorCount = 0
+
+# Fonction pour résoudre un chemin Windows
+function Resolve-WindowsPath {
+ param([string]$path)
+
+ # Remplacer les variables d'environnement
+ $resolved = $path
+ $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE
+ $resolved = $resolved -replace '%APPDATA%', $env:APPDATA
+ $resolved = $resolved -replace '%LOCALAPPDATA%', $env:LOCALAPPDATA
+ $resolved = $resolved -replace '%HOME%', $env:HOME
+
+ # Remplacer les autres variables d'environnement
+ $resolved = [System.Environment]::ExpandEnvironmentVariables($resolved)
+
+ return $resolved
+}
+
+# Traiter les fichiers Windows
+if ($mapping.windows) {
+ $mapping.windows.PSObject.Properties | ForEach-Object {
+ $originalPath = $_.Name
+ $projectPath = $_.Value
+
+ try {
+ # Vérifier que le fichier source existe dans le projet
+ if (-not (Test-Path $projectPath)) {
+ Write-Warning "Fichier source introuvable dans le projet: $projectPath"
+ $skippedCount++
+ return
+ }
+
+ # Résoudre le chemin de destination
+ $destinationPath = Resolve-WindowsPath $originalPath
+
+ # Créer le répertoire parent si nécessaire
+ $destinationDir = Split-Path $destinationPath -Parent
+ if ($destinationDir -and -not (Test-Path $destinationDir)) {
+ New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null
+ Write-Host "Créé le répertoire: $destinationDir"
+ }
+
+ # Copier le fichier
+ Copy-Item -Path $projectPath -Destination $destinationPath -Force
+
+ Write-Host "Restauré: $projectPath -> $destinationPath"
+ $restoredCount++
+
+ } catch {
+ Write-Error "Erreur lors de la restauration de '$originalPath': $_"
+ $errorCount++
+ }
+ }
+}
+
+# Traiter les fichiers WSL
+if ($mapping.wsl) {
+ $mapping.wsl.PSObject.Properties | ForEach-Object {
+ $originalPath = $_.Name
+ $projectPath = $_.Value
+
+ try {
+ # Vérifier que le fichier source existe dans le projet
+ if (-not (Test-Path $projectPath)) {
+ Write-Warning "Fichier source introuvable dans le projet: $projectPath"
+ $skippedCount++
+ return
+ }
+
+ # Résoudre le chemin de destination WSL
+ $wslDestination = $originalPath
+ if ($wslDestination -match '^~') {
+ $wslDestination = wsl bash -c "echo $wslDestination"
+ }
+
+ # Créer le répertoire parent si nécessaire
+ $wslDir = Split-Path $wslDestination -Parent
+ if ($wslDir) {
+ wsl mkdir -p "$wslDir" 2>$null
+ }
+
+ # Copier le fichier vers WSL
+ # Convertir le chemin Windows en chemin WSL
+ $wslSource = (wsl wslpath -a $projectPath)
+ wsl cp "$wslSource" "$wslDestination"
+
+ if ($LASTEXITCODE -ne 0) {
+ # Fallback: utiliser PowerShell pour copier vers WSL
+ $content = Get-Content $projectPath -Raw -Encoding UTF8
+ $tempFile = [System.IO.Path]::GetTempFileName()
+ Set-Content -Path $tempFile -Value $content -Encoding UTF8
+ $wslTemp = (wsl wslpath -a $tempFile)
+ wsl cp "$wslTemp" "$wslDestination"
+ Remove-Item $tempFile
+ }
+
+ Write-Host "Restauré (WSL): $projectPath -> $wslDestination"
+ $restoredCount++
+
+ } catch {
+ Write-Error "Erreur lors de la restauration WSL de '$originalPath': $_"
+ $errorCount++
+ }
+ }
+}
+
+Write-Host "`nRésumé:"
+Write-Host " Fichiers restaurés: $restoredCount"
+Write-Host " Fichiers ignorés: $skippedCount"
+Write-Host " Erreurs: $errorCount"
+
diff --git a/scripts/sync-to-project.ps1 b/scripts/sync-to-project.ps1
new file mode 100644
index 0000000..5c3fd9c
--- /dev/null
+++ b/scripts/sync-to-project.ps1
@@ -0,0 +1,223 @@
+# Script pour copier les fichiers de configuration vers le projet
+# Lit files-config.txt et copie chaque fichier vers configs/{system}/
+
+param(
+ [string]$ConfigFile = "files-config.txt",
+ [string]$MappingFile = "path-mapping.json"
+)
+
+$ErrorActionPreference = "Stop"
+
+# Vérifier que le fichier de configuration existe
+if (-not (Test-Path $ConfigFile)) {
+ Write-Error "Le fichier de configuration '$ConfigFile' n'existe pas."
+ exit 1
+}
+
+# Créer les répertoires de destination
+$configsDir = "configs"
+$windowsDir = Join-Path $configsDir "windows"
+$wslDir = Join-Path $configsDir "wsl"
+
+foreach ($dir in @($configsDir, $windowsDir, $wslDir)) {
+ if (-not (Test-Path $dir)) {
+ New-Item -ItemType Directory -Path $dir -Force | Out-Null
+ Write-Host "Créé le répertoire: $dir"
+ }
+}
+
+# Charger le mapping existant ou créer un nouveau
+$mapping = @{
+ windows = @{}
+ wsl = @{}
+}
+
+if (Test-Path $MappingFile) {
+ try {
+ $existingMapping = Get-Content $MappingFile -Raw | ConvertFrom-Json
+ if ($existingMapping.windows) {
+ $mapping.windows = @{}
+ $existingMapping.windows.PSObject.Properties | ForEach-Object {
+ $mapping.windows[$_.Name] = $_.Value
+ }
+ }
+ if ($existingMapping.wsl) {
+ $mapping.wsl = @{}
+ $existingMapping.wsl.PSObject.Properties | ForEach-Object {
+ $mapping.wsl[$_.Name] = $_.Value
+ }
+ }
+ } catch {
+ Write-Warning "Impossible de charger le mapping existant, création d'un nouveau mapping."
+ }
+}
+
+# Fonction pour résoudre un chemin Windows
+function Resolve-WindowsPath {
+ param([string]$path)
+
+ # Remplacer les variables d'environnement
+ $resolved = $path
+ $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE
+ $resolved = $resolved -replace '%APPDATA%', $env:APPDATA
+ $resolved = $resolved -replace '%LOCALAPPDATA%', $env:LOCALAPPDATA
+ $resolved = $resolved -replace '%HOME%', $env:HOME
+ $resolved = $resolved -replace '%USERPROFILE%', $env:USERPROFILE
+
+ # Remplacer les autres variables d'environnement
+ $resolved = [System.Environment]::ExpandEnvironmentVariables($resolved)
+
+ return $resolved
+}
+
+# Fonction pour résoudre un chemin WSL
+function Resolve-WSLPath {
+ param([string]$path)
+
+ # Expansion de ~
+ if ($path -match '^~') {
+ $homePath = wsl bash -c "echo ~"
+ $path = $path -replace '^~', $homePath
+ }
+
+ return $path
+}
+
+# Fonction pour obtenir le chemin relatif dans le projet
+function Get-ProjectPath {
+ param(
+ [string]$system,
+ [string]$originalPath
+ )
+
+ # Nettoyer le chemin original pour créer un nom de fichier sûr
+ $safeName = $originalPath -replace '[\\/:*?"<>|]', '_'
+ $safeName = $safeName -replace '^%', '' -replace '%$', ''
+ $safeName = $safeName -replace '^~', 'home'
+
+ # Si le chemin contient des séparateurs, préserver la structure
+ if ($originalPath -match '[\\/]') {
+ $parts = $originalPath -split '[\\/]'
+ $fileName = $parts[-1]
+ $parentDirs = $parts[0..($parts.Length - 2)] -join '_'
+ if ($parentDirs) {
+ $safeName = "${parentDirs}_${fileName}"
+ } else {
+ $safeName = $fileName
+ }
+ }
+
+ return Join-Path "configs" $system $safeName
+}
+
+# Lire et traiter le fichier de configuration
+$lines = Get-Content $ConfigFile | Where-Object {
+ $_ -notmatch '^\s*#' -and $_.Trim() -ne ''
+}
+
+$copiedCount = 0
+$skippedCount = 0
+$errorCount = 0
+
+foreach ($line in $lines) {
+ $line = $line.Trim()
+ if ($line -eq '' -or $line -match '^\s*#') {
+ continue
+ }
+
+ # Parser la ligne: système|chemin
+ if ($line -notmatch '^(\w+)\|(.+)$') {
+ Write-Warning "Ligne ignorée (format invalide): $line"
+ continue
+ }
+
+ $system = $matches[1]
+ $originalPath = $matches[2]
+
+ if ($system -notin @('windows', 'wsl')) {
+ Write-Warning "Système invalide '$system' dans la ligne: $line"
+ continue
+ }
+
+ try {
+ # Résoudre le chemin selon le système
+ if ($system -eq 'windows') {
+ $resolvedPath = Resolve-WindowsPath $originalPath
+ } else {
+ # Pour WSL, utiliser wsl pour résoudre le chemin
+ $wslPath = $originalPath
+ if ($wslPath -match '^~') {
+ $wslPath = wsl bash -c "echo $wslPath"
+ }
+ $resolvedPath = $wslPath
+ }
+
+ # Vérifier que le fichier existe
+ if ($system -eq 'windows') {
+ if (-not (Test-Path $resolvedPath)) {
+ Write-Warning "Fichier introuvable: $resolvedPath (original: $originalPath)"
+ $skippedCount++
+ continue
+ }
+ } else {
+ # Pour WSL, vérifier via wsl
+ $exists = wsl test -f "$resolvedPath" 2>$null
+ if ($LASTEXITCODE -ne 0) {
+ Write-Warning "Fichier introuvable dans WSL: $resolvedPath (original: $originalPath)"
+ $skippedCount++
+ continue
+ }
+ }
+
+ # Obtenir le chemin de destination dans le projet
+ $projectPath = Get-ProjectPath $system $originalPath
+
+ # Créer le répertoire parent si nécessaire
+ $projectDir = Split-Path $projectPath -Parent
+ if (-not (Test-Path $projectDir)) {
+ New-Item -ItemType Directory -Path $projectDir -Force | Out-Null
+ }
+
+ # Copier le fichier
+ if ($system -eq 'windows') {
+ Copy-Item -Path $resolvedPath -Destination $projectPath -Force
+ } else {
+ # Pour WSL, utiliser wsl pour copier
+ $wslSource = $resolvedPath
+ $wslDest = (wsl wslpath -a $projectPath)
+ wsl cp "$wslSource" "$wslDest"
+ if ($LASTEXITCODE -ne 0) {
+ # Fallback: utiliser PowerShell pour copier depuis WSL
+ $tempFile = [System.IO.Path]::GetTempFileName()
+ wsl cat "$wslSource" | Out-File -FilePath $tempFile -Encoding utf8
+ Copy-Item -Path $tempFile -Destination $projectPath -Force
+ Remove-Item $tempFile
+ }
+ }
+
+ # Enregistrer le mapping
+ $mapping[$system][$originalPath] = $projectPath
+
+ Write-Host "Copié: $originalPath -> $projectPath"
+ $copiedCount++
+
+ } catch {
+ Write-Error "Erreur lors du traitement de '$line': $_"
+ $errorCount++
+ }
+}
+
+# Sauvegarder le mapping
+$mappingJson = @{
+ windows = $mapping.windows
+ wsl = $mapping.wsl
+} | ConvertTo-Json -Depth 10
+
+Set-Content -Path $MappingFile -Value $mappingJson -Encoding UTF8
+
+Write-Host "`nRésumé:"
+Write-Host " Fichiers copiés: $copiedCount"
+Write-Host " Fichiers ignorés: $skippedCount"
+Write-Host " Erreurs: $errorCount"
+Write-Host " Mapping sauvegardé dans: $MappingFile"
+