Änderungen von Dokument Eigene Autoconf-Rolle erstellen

Zuletzt geändert von Tom Altenbrunn am 2023/03/17 08:03

Von Version 27.1
bearbeitet von Jonas Mayer
am 2023/03/16 07:48
Änderungskommentar: Es gibt keinen Kommentar für diese Version
Auf Version 29.1
bearbeitet von Jonas Mayer
am 2023/03/16 07:58
Änderungskommentar: Es gibt keinen Kommentar für diese Version

Zusammenfassung

Details

Seiteneigenschaften
Inhalt
... ... @@ -96,14 +96,6 @@
96 96  ----
97 97  
98 98  
99 -
100 -
101 -
102 -
103 -
104 -
105 -
106 -
107 107  = (% style="font-size:22px" %)__**Weiteres, funktionsfertiges Beispiel: Rolle „WLAN Profil mit PSK anlegen“**__(%%) =
108 108  
109 109  
... ... @@ -126,7 +126,7 @@
126 126   license: SBE
127 127  (% style="color:#8e44ad" %) uuid:(%%) 52318636-c4f5-11ea-baf9-0bff00c66ff4
128 128   visible: true
129 - (% style="color:#19177c" %)priority:(%%) 0
121 +(% style="color:#19177c" %) priority:(%%) 0
130 130   applyAlways: false
131 131  (% style="color:#f1c40f" %) tags:(%%)
132 132   - CUSTOM
... ... @@ -166,16 +166,17 @@
166 166  
167 167  == (% style="font-size:16px" %)**Inhalt des PowerShell-Skripts main.ps1, das die Variablen entgegennimmt**(%%) ==
168 168  
169 -Im Unterverzeichnis {{box}} win/ {{/box}} oder {{box}} lin/ {{/box}} der Autoconf-Rolle können sich unterschiedliche PowerShell-Skripte zur Ausführung in den Phasen befinden. In dieser Rolle liegt das allgemeingültige Skript {{box}}main.ps1{{/box}} vor, welches die Variablen als Parameter ##$ssid## und ##$psk## intern verwendet.
161 +Im Unterverzeichnis {{box}} win/ {{/box}} oder {{box}} lin/ {{/box}} der Autoconf-Rolle können sich wie erläutert unterschiedliche PowerShell-Skripte zur Ausführung in den verschiedenen Phasen befinden.
162 +In dieser Rolle liegt konkret das allgemeingültige Skript {{box}}main.ps1{{/box}} vor, welches die Variablen als Parameter ##$ssid## und ##$psk## intern verwendet.
170 170  
171 -(% class="box" %)
172 -(((
173 -(% style="color:#27ae60" %)# Windows Variante(%%)
174 -root@ctrl-g1:~~ # cat /usr/lib/ld-autoconf/logodidact/roles/ld_wlan_psk/win/main.ps1
175 -)))
176 176  
165 +(% style="color:#19177c" %)**Windows Variante**
177 177  
178 -{{code width="50%"}}
167 +{{code language="text" width="50%"}}
168 +root@ctrl-g1:~ # cat /usr/lib/ld-autoconf/logodidact/roles/ld_wlan_psk/win/main.ps1
169 +{{/code}}
170 +
171 +{{code width="50%" language="powershell"}}
179 179  Param
180 180  (
181 181   [parameter(Mandatory=$false)]
... ... @@ -230,18 +230,69 @@
230 230  }
231 231  {{/code}}
232 232  
233 -==== ====
234 234  
235 -==== ====
227 +(% style="color:#19177c" %)**Linux Variante (Network Manager)**
236 236  
237 -==== ====
229 +{{code language="text" width="50%"}}
230 +root@ctrl-g1:~ # cat /usr/lib/ld-autoconf/logodidact/roles/ld_wlan_psk/lin/main.ps1
231 +{{/code}}
238 238  
239 -==== ====
233 +{{code language="powershell" width="50%"}}
234 +Param
235 +(
236 + [parameter(Mandatory=$false)]
237 + [String]
238 + $ssid,
239 + [parameter(Mandatory=$false)]
240 + [String]
241 + $psk
242 +)
240 240  
241 -==== ====
244 +if ($ssid -ne '' -and $psk -ne '') {
245 + if (Get-Command "nmcli" -ErrorAction SilentlyContinue) {
246 + # Check if kernel modules are up
247 + nmcli dev wifi rescan
248 + if ($LASTEXITCODE -ne 0) {
249 + Start-Sleep -Seconds 30
250 + }
251 +
252 + # Check again
253 + nmcli dev wifi rescan
254 + if ($LASTEXITCODE -ne 0) {
255 + Write-Verbose "Skipping role. There might be no WiFi device installed."
256 + exit 0
257 + }
258 +
259 + $config = "/etc/NetworkManager/system-connections/$ssid"
242 242  
243 -==== ====
261 + if (Test-Path -Path $config) {
262 + Write-Verbose "Removing '$config'"
263 + Remove-Item -Path $config -Recurse -Force
264 + }
244 244  
245 -==== ====
266 + Write-Verbose "Connecting to '$ssid'"
267 +
268 + nmcli device wifi connect """$ssid""" password """$psk"""
269 +
270 + if ($LASTEXITCODE -eq 0) {
271 + Start-Sleep -Seconds 5
272 + nmcli con up """$ssid"""
246 246  
247 -==== ====
274 + if ($LASTEXITCODE -ne 0) {
275 + Write-Verbose "Error: Credentials wrong?"
276 +
277 + if (Test-Path -Path $config) {
278 + Write-Verbose "Removing '$config'"
279 + Remove-Item -Path $config -Recurse -Force
280 + }
281 + }
282 + }
283 +
284 + Write-Verbose "Exiting with code: $LASTEXITCODE"
285 + exit $LASTEXITCODE
286 + }
287 +
288 + Write-Verbose "No suitable implementation found"
289 + exit 1
290 +}
291 +{{/code}}