2023-01-25 15:59:43 +01:00
# ------------------------------------------------------------------------------------------------------------------------------
# AUTEUR : Fran<61> ois ALBERT le 28/06/2022
# ------------------------------------------------------------------------------------------------------------------------------
#
# Param<61> tres possibles <20> l'ex<65> cution :
#
# -UnInstall = D<> sinstallation
# -Install = Installation
# -PostInstall = PostInstallation
# -Trace = D<> bogage
#
Param (
[ Parameter ( Mandatory = $False ) ]
[ Switch ] $UnInstall ,
[ Parameter ( Mandatory = $False ) ]
[ Switch ] $Install ,
[ Parameter ( Mandatory = $False ) ]
[ Switch ] $PostInstall ,
[ Parameter ( Mandatory = $False ) ]
[ Switch ] $RollBack ,
[ Parameter ( Mandatory = $False ) ]
[ Switch ] $Trace
)
# ------------------------------------------------------------------------------------------------------------------------------
# PACKAGE / VERSION
# ------------------------------------------------------------------------------------------------------------------------------
[ String ] $AppName = 'Duplicati - IPR Foton'
[ String ] $AppVersion = '2.0.6.3'
# ------------------------------------------------------------------------------------------------------------------------------
# SCRIPT
# ------------------------------------------------------------------------------------------------------------------------------
Try {
# Positionnement du D<> bogage (Trace) si demand<6E>
If ( $Trace ) {
$Global:EnableDebugMessage = $True
}
# -----------------
# INITIALISATIONS
# -----------------
$ScriptTime = [ Diagnostics.Stopwatch ] :: StartNew ( )
[ String ] $CurrentScript = $MyInvocation . MyCommand . Definition # Chemin complet de ce script
[ String ] $CurrentPath = Split-Path -Path $CurrentScript -Parent # Dossier parent de ce script
[ String ] $ScriptParameters = ( $MyInvocation . BoundParameters . Keys | Out-String ) -Replace ( " `r `n " , " " ) # Liste des param<61> tres
[ String ] $LogPath = $ ( $ENV:SystemRoot + '\Logs\UR1_Software' ) # Dossier parent du fichier de log
[ String ] $Global:LogFile = $ ( $LogPath + '\' + $AppName + '-' + $AppVersion + '-' + $ ( Get-Date -UFormat '%Y%m%d-%Hh%M' ) + '.log' ) # Chemin complet du fichier de log
If ( $RollBack ) {
[ String ] $Global:LogFile = $ ( $LogPath + '\RollBack - ' + $AppName + '-' + $AppVersion + '-' + $ ( Get-Date -UFormat '%Y%m%d-%Hh%M' ) + '.log' ) # Chemin complet du fichier de log du RollBack
}
# ---------------------
# IMPORT DE MODULE(S)
# ---------------------
Import-Module " $CurrentPath \Bin\Module_UR1.psd1 " -ErrorAction 'Stop'
# -----------------------
# INITIALISATION DU LOG
# -----------------------
Write-Log -Message " **************************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " D<EFBFBD> but d'ex<65> cution de ' $AppName - $AppVersion ' " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " Script : $CurrentScript " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " Param<EFBFBD> tres : $ScriptParameters " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " **************************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
# -------------------------------------------
# D<> FINITION DES VARIABLES SYST<53> ME & SCRIPT
# -------------------------------------------
Set-ScriptVariables
# Variables disponibles : variables syst<73> me standard +
# $Arch, $CommonProgFiles, $CommonProgFiles86, $Default, $Desktop, $HomeDrive, $Msiexec, $OS, $OSName, $OSServicePack, $OSVersion,
# $ProgFiles, $ProgFiles86, $ProcessArch, $Public, $Reg, $SchTasks, $StartMenu, $UserDesktop, $UsersProfile, $UserStartMenu
#
# ------------------------------------------------------------------------------------------------------------------------------
# UNINSTALL
# ------------------------------------------------------------------------------------------------------------------------------
If ( $UnInstall ) {
[ String ] $Step = 'D<> sinstallation'
Write-Verbose " $( Get-Date -UFormat '%H:%M:%S' ) - $Step en cours... `r `n "
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message " ***** $( $Step . ToUpper ( ) ) ********************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
#
# D<> but des commandes de D<> sinstallation
# --------------------------------------
#
# Interaction avec un utilisateur <20> ventuellement connect<63> si process en cours
#
$Process = Invoke-KillProcessWithPopUp -AppName $AppName -PackageVersion $AppVersion -Process $ ( 'Duplicati.GUI.TrayIcon' )
If ( $Process -gt '1' ) {
# Le code retour de l'interaction est sup<75> rieur <20> 1, on sort du script
$ExitUR1 = 1000
Throw " Script annul<75> par l'utilisateur ou Process ouvert "
}
#
# Le code retour de l'interaction est 0 ou 1, on poursuit
# D<> sinstallation toutes versions
#
[ HashTable[] ] $Versions =
@ { Version = " 2.0.5.1 " ; Guid = " {FC1F2B24-1783-4352-98E9-669896601613} " } ,
@ { Version = " 2.0.6.3 " ; Guid = " {D2A5D819-4FA0-493B-8D37-9531C659D95A} " }
ForEach ( $Version in $Versions ) {
# Si ex<65> cutable
Foreach ( $Uninst in $Version . Uninst ) {
If ( $Uninst -ne $null ) {
If ( Test-Path -Path $Uninst -PathType 'Leaf' ) {
If ( ! ( $Version . ExitCode ) ) { $Version . ExitCode = '0' }
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message $ ( 'D<> sinstallation EXECUTABLE de la version : ' + $Version . Version ) -Component $CurrentScript -LogFile $LogFile
Write-Log -Message $ ( ' --> D<> sinstalleur : "' + $Uninst + '"' ) -Component $CurrentScript -LogFile $LogFile
Write-Log -Message $ ( ' --> Arguments : "' + $Version . Arguments + '"' ) -Component $CurrentScript -LogFile $LogFile
Write-Log -Message $ ( ' --> ExitCode attendu : "' + $Version . ExitCode + '"' ) -Component $CurrentScript -LogFile $LogFile
Invoke-LaunchProcess -Path $Uninst -ArgumentList $Version . Arguments -WorkingDirectory $ ( Split-Path -Path $Uninst -Parent ) -ExitCode $Version . ExitCode -NoNewWindow -LogFile $LogFile | Out-Null
}
}
}
# Si MSI
$RegUninst64 = 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\'
$RegUninst = 'Registry::HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
ForEach ( $Guid in $Version . Guid ) {
If ( $Guid -ne $null ) {
If ( ( Test-Path -Path $ ( " $RegUninst64 " + " $Guid " ) ) -or ( Test-Path -Path $ ( " $RegUninst " + " $Guid " ) ) ) {
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message $ ( 'D<> sinstallation MSI de la version : ' + $Version . Version ) -Component $CurrentScript -LogFile $LogFile
Write-Log -Message $ ( ' --> Guid : "' + $Guid + '"' ) -Component $CurrentScript -LogFile $LogFile
Write-Log -Message $ ( ' --> ExitCode attendu : "' + $Version . ExitCode + '"' ) -Component $CurrentScript -LogFile $LogFile
Invoke-MsiInstall -Action 'Uninstall' -ProductCode $Guid -ExitCode $Version . ExitCode -NoLog | Out-Null
If ( Test-Path -Path $ ( " $RegUninst64 " + " $Guid " ) ) {
Write-Log -Message $ ( 'Suppression dans le registre : ' + $ ( " $RegUninst64 " + " $Guid " ) ) -Component $CurrentScript -LogFile $LogFile
Remove-Item -Path $ ( " $RegUninst64 " + " $Guid " ) -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
}
If ( Test-Path -Path $ ( " $RegUninst " + " $Guid " ) ) {
Write-Log -Message $ ( 'Suppression dans le registre : ' + $ ( " $RegUninst " + " $Guid " ) ) -Component $CurrentScript -LogFile $LogFile
Remove-Item -Path $ ( " $RegUninst " + " $Guid " ) -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
}
}
}
}
}
Write-Log -Message " " -LogFile $LogFile
# Suppression de la cl<63> de registre indiquant la pr<70> sence de l'application
#
Remove-RegistryKey -Key " HKEY_LOCAL_MACHINE\SOFTWARE\UR1_Software\ $AppName " -Recurse -LogFile $LogFile
#
# Fin des commandes de D<> sinstallation
# ------------------------------------
#
}
# ------------------------------------------------------------------------------------------------------------------------------
# INSTALL
# ------------------------------------------------------------------------------------------------------------------------------
If ( $Install ) {
[ String ] $Step = 'Installation'
Write-Verbose " $( Get-Date -UFormat '%H:%M:%S' ) - $Step en cours... `r `n "
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message " ***** $( $Step . ToUpper ( ) ) ************************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
#
# D<> but des commandes d'Installation
# ----------------------------------
#
Invoke-MsiInstall -Path " $Currentpath \Sources\duplicati-2.0.6.3_beta_2021-06-17-x64.msi " -LogFile $LogFile | Out-Null
#
# Fin des commandes d'Installation
# --------------------------------
#
}
# ------------------------------------------------------------------------------------------------------------------------------
# POSTINSTALL
# ------------------------------------------------------------------------------------------------------------------------------
If ( $PostInstall ) {
[ String ] $Step = 'PostInstallation'
Write-Verbose " $( Get-Date -UFormat '%H:%M:%S' ) - $Step en cours... `r `n "
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message " ***** $( $Step . ToUpper ( ) ) ******************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
#
# D<> but des commandes de PostInstallation
# ---------------------------------------
#
[ String ] $NOMMACHINE = " $ENV:COMPUTERNAME "
[ String ] $ENTITE = 'IPR'
2023-02-06 15:33:18 +01:00
[ String ] $CurrentUser = ( Get-WmiObject -Class win32_computersystem | Select-Object -ExpandProperty username ) . split ( '\' ) [ 1 ]
2023-01-25 15:59:43 +01:00
# M<> nage
#
[ String[] ] $AllItems = " $Desktop \Duplicati 2.lnk "
ForEach ( $Item in $AllItems ) {
If ( Test-Path -Path $Item -PathType 'Container' ) {
Write-Log -Message $ ( 'Suppression de dossier : ' + $Item ) -Component $CurrentScript -LogFile $LogFile
Remove-Item -Path $Item -Recurse -Force -ErrorAction Stop | Out-Null
} Else {
If ( Test-Path -Path $Item -PathType 'Leaf' ) {
Write-Log -Message $ ( 'Suppression de fichier : ' + $Item ) -Component $CurrentScript -LogFile $LogFile
Remove-Item -Path $Item -Force -ErrorAction Stop | Out-Null
}
}
}
# ----------------------------------------
# Creation et copie du fichier de config
# ----------------------------------------
if ( ! ( test-path " D:\Home\ $CurrentUser \Duplicati\ " ) )
{
New-Item " D:\Home\ $CurrentUser \Duplicati\ " -itemType Directory
}
if ( ! ( test-path " D:\Home\ $CurrentUser \Duplicati\.ssh\ " ) )
{
New-Item " D:\Home\ $CurrentUser \Duplicati\.ssh\ " -itemType Directory
}
$Fichier = get-content " $Currentpath \Files\sauvegarde.duplicati.config.json "
#Detection si la machine fait partie de l'entit<69> e FOTON sinon on fait la config pour l'IPR
if ( ( " $ENV:COMPUTERNAME " ) . Substring ( 2 , 3 ) -eq " 034 " )
{
$ENTITE = " FOTON "
}
switch ( $ENTITE )
{
IPR
{
if ( ! ( test-path " D:\Home\ $CurrentUser \Duplicati\.ssh\duplicati_id_ed25519 " ) )
{
ssh-keygen -t ed25519 -f " D:\Home\ $CurrentUser \Duplicati\.ssh\duplicati_id_ed25519 " -q -N '""'
Write-Log -Message " Cr<EFBFBD> ation des clefs SSH ed25519 IPR " -Component $CurrentScript -LogFile $LogFile
2023-03-13 10:58:13 +01:00
Send-MailMessage -SmtpServer smtpint . univ-rennes1 . fr -From " $CurrentUser @univ-rennes1.fr " -To IPR . ADMIN . EMAIL @listes . univ-rennes . fr -Subject " $Hostname $CurrentUser - Nouvelle clef Duplicati " -Attachments D: \ Home \ $CurrentUser \ Duplicati \ . ssh \ duplicati_id_ed25519 . pub
2023-01-25 15:59:43 +01:00
}
$fichier = $fichier -replace " TARGETURLUR " , " ssh://duplicati.ipr.univ-rennes1.fr//home// $CurrentUser // $NOMMACHINE //?auth-username= $CurrentUser &ssh-fingerprint=ssh-ed25519 32 4A:2D:A0:5F:66:7A:D5:3A:F4:B2:63:EC:EE:1E:D0:21&ssh-keyfile=D:\\Home\\ $CurrentUser \\Duplicati\\.ssh\\duplicati_id_ed25519 "
}
2023-03-13 10:58:13 +01:00
2023-01-25 15:59:43 +01:00
FOTON
2023-03-13 10:58:13 +01:00
{
if ( ! ( test-path " D:\Home\ $CurrentUser \Duplicati\.ssh\duplicati_id_ed25519 " ) )
{
ssh-keygen -t ed25519 -f " D:\Home\ $CurrentUser \Duplicati\.ssh\duplicati_id_ed25519 " -q -N '""'
Write-Log -Message " Cr<EFBFBD> ation des clefs SSH ed25519 FOTON " -Component $CurrentScript -LogFile $LogFile
Send-MailMessage -SmtpServer smtpint . univ-rennes1 . fr -From " $CurrentUser @univ-rennes1.fr " -To FOTON . ADMIN . EMAIL @univ -rennes . fr -Subject " $Hostname $CurrentUser - Nouvelle clef Duplicati " -Attachments D: \ Home \ $CurrentUser \ Duplicati \ . ssh \ duplicati_id_ed25519 . pub
}
$fichier = $fichier -replace " TARGETURLUR " , " ssh://bkpdop.univ-rennes1.fr//mnt//datastore_backuppc//duplicati// $CurrentUser . $NOMMACHINE //?auth-username= $CurrentUser &ssh-fingerprint=ssh-ed25519 32 1E:EC:EB:7D:52:A3:54:5A:48:EA:59:6A:CF:8C:74:48&ssh-keyfile=D:\\Home\\ $CurrentUser \\Duplicati\\.ssh\\duplicati_id_ed25519 "
}
<# FOTON
2023-01-25 15:59:43 +01:00
{
if ( ! ( test-path " D:\Home\ $CurrentUser \Duplicati\.ssh\id_rsa_duplicati " ) )
{
ssh-keygen -t rsa -f " D:\Home\ $CurrentUser \Duplicati\.ssh\id_rsa_duplicati " -q -N '""'
Write-Log -Message " Cr<EFBFBD> ation des clefs SSH RSA FOTON " -Component $CurrentScript -LogFile $LogFile
2023-02-06 15:33:18 +01:00
Send-MailMessage -SmtpServer smtpint . univ-rennes1 . fr -From " $CurrentUser @univ-rennes1.fr " -To FOTON . ADMIN . EMAIL @univ -rennes . fr -Subject " $Hostname $CurrentUser - Nouvelle clef Duplicati " -Attachments D: \ Home \ $CurrentUser \ Duplicati \ . ssh \ duplicati_id_ed25519 . pub
2023-01-25 15:59:43 +01:00
}
2023-03-13 10:58:13 +01:00
$fichier = $fichier -replace " TARGETURLUR " , " ssh://bkpdop.univ-rennes1.fr//mnt//datastore_backuppc//duplicati// $CurrentUser . $NOMMACHINE //?auth-username= $CurrentUser &ssh-fingerprint=ssh-ed25519 32 1E:EC:EB:7D:52:A3:54:5A:48:EA:59:6A:CF:8C:74:48&ssh-keyfile=D:\\Home\\ $CurrentUser \\Duplicati\\.ssh\\id_rsa_duplicati "
2023-01-25 15:59:43 +01:00
2023-03-13 10:58:13 +01:00
#$fichier = $fichier -replace "TARGETURLUR", "ssh://bkpdop.univ-rennes1.fr//mnt//datastore_backuppc//duplicati//$CurrentUser.$NOMMACHINE//?auth-username=$CurrentUser&ssh-fingerprint=ssh-rsa 2048 02:b9:38:a6:17:66:ba:90:e0:be:bb:7e:fb:a7:e6:14&ssh-keyfile=D:\\Home\\$CurrentUser\\Duplicati\\.ssh\\id_rsa_duplicati"
2023-01-25 15:59:43 +01:00
}
2023-03-13 10:58:13 +01:00
#>
2023-01-25 15:59:43 +01:00
}
2023-02-06 15:33:18 +01:00
#Donne les droits <20> l'utilisateur courant aux cl<63> s ssh g<> n<EFBFBD> r<EFBFBD> es.
get-acl " D:\Home\ $CurrentUser " | set-acl D: \ Home \ $CurrentUser \ Duplicati \ . ssh \ *
2023-01-25 15:59:43 +01:00
$fichier = $fichier -replace " SESAME " , $CurrentUser
$Fichier | set-content " D:\Home\ $CurrentUser \Duplicati\sauvegarde.duplicati.config.json "
Write-Log -Message " Creation du fichier de configuration pour l'entit<69> e $entite , Utilisateur : $CurrentUser " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " " -Component $CurrentScript -LogFile $LogFile
Invoke-LaunchProcess -Path " $ProgFiles \Duplicati 2\Duplicati.GUI.TrayIcon.exe " -Argumentlist " --webservice-interface=loopback " -nowait -NoNewWindow -LogFile $LogFile | Out-Null
# Cr<43> ation de la cl<63> de registre indiquant la pr<70> sence de l'application ("Version" <20> utiliser en m<> thode de d<> tection avec SCCM)
#
Set-RegistryKey -Key " HKEY_LOCAL_MACHINE\SOFTWARE\UR1_Software\ $AppName " -Name " Version " -Type String -Value $AppVersion -LogFile $LogFile
Set-RegistryKey -Key " HKEY_LOCAL_MACHINE\SOFTWARE\UR1_Software\ $AppName " -Name " Date " -Type String -Value $ ( Get-Date -UFormat '%Y%m%d' ) -LogFile $LogFile
#
# Fin des commandes de PostInstallation
# -------------------------------------
#
}
}
# ------------------------------------------------------------------------------------------------------------------------------
# SCRIPT EN ERREUR
# ------------------------------------------------------------------------------------------------------------------------------
Catch {
Write-Log -Message $ ( ' -- Erreur : ' + $_ + ' --' ) -Severity '2' -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " " -Component $CurrentScript -LogFile $LogFile
#
If ( ! ( $RollBack ) ) {
If ( $Step -ne 'D<> sinstallation' ) {
Write-Log -Message 'RollBack lanc<6E> ' -Severity '2' -Component $CurrentScript -LogFile $LogFile
Invoke-AppRollback -FileName $CurrentScript
Write-Log -Message 'RollBack termin<69> ' -Severity '2' -Component $CurrentScript -LogFile $LogFile
}
Else {
Write-Log -Message 'RollBack non lanc<6E> , erreur dans la partie D<> sinstallation' -Severity '3' -Component $CurrentScript -LogFile $LogFile
}
}
Else {
Write-Log -Message 'Erreur dans la partie D<> sinstallation du script de RollBack' -Severity '3' -Component $CurrentScript -LogFile $LogFile
}
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message " **************************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " $Step EN ERREUR pour ' $AppName - $AppVersion ' " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " A la ligne : $( $_ . InvocationInfo . ScriptLineNumber ) " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " **************************************************************************************************** " -Component $CurrentScript -LogFile $LogFile
Throw $_ . Exception . ErrorRecord
}
# ------------------------------------------------------------------------------------------------------------------------------
# FIN
# ------------------------------------------------------------------------------------------------------------------------------
Finally {
$ScriptTime . Stop ( )
$ScriptDuration = $ ( [ String ] :: Format ( " {0:d2}:{1:d2}:{2:d2} " , $ScriptTime . Elapsed . Hours , $ScriptTime . Elapsed . Minutes , $ScriptTime . Elapsed . Seconds ) )
Write-Log -Message " " -LogFile $LogFile
Write-Log -Message '****************************************************************************************************' -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " Fin d'ex<65> cution de ' $AppName - $AppVersion ' " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " Script : $CurrentScript " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " Param<EFBFBD> tres : $ScriptParameters " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message " Dur<EFBFBD> e d'ex<65> cution : $ScriptDuration " -Component $CurrentScript -LogFile $LogFile
Write-Log -Message '****************************************************************************************************' -Component $CurrentScript -LogFile $LogFile
#
If ( $ExitUR1 ) {
Exit $ExitUR1
}
}