It's really a process of energy consuming to reinstall the server, especially the whole data backup with ghost, the snail like speed of data recovery with ghost, and the abnormal problem of software for the first time in ghost's life. It's really painful. From now on, maybe it's better to use imagex to back up data. At least imagex can mount directly, which saves my continuous recovery process. In retrospect, the only reason for choosing ghost should be: full backup, full recovery when necessary. But that's not the point here. This mainly talks about the automatic script construction during service installation. Of course, using the method of building scripts may not be as good as direct manual operation, but in case a second or second time is needed. Of course, programmers tend to be dismissive of human methods.
1. Organizational structure
The company has shifted to the business unit system, and the approximate company structure is as follows:The basic SVN design is that each business unit has an SVN library, under which there is a level-1 directory, HW/FPGA/FW/SW, which is authorized to access by different engineers.
2. Create users and user groups
The user belongs to the business unit and needs to create a business unit group. According to the nature of research and development, the business unit is subdivided into HW/FPGA/FW/SW user groups. The user is created with the command "net user". The command script generated from Excel is generated with VBA of Excel. The code is as follows:
Sub CreateScript() Dim row As Integer, i As Integer Dim tsUsr As TextStream, tsSmtp As TextStream Dim usr As String, grp As String, cmt As String Dim outFolder As String Set fso = CreateObject("Scripting.FileSystemObject") outFolder = "D:\BYHX\Server\" Set tsUsr = fso.OpenTextFile(outFolder & "0.servadmin.cmd", ForWriting, True) Set tsSmtp = fso.OpenTextFile(outFolder & "0.sendmail.ps1", ForWriting, True) ' PowerShell,The following statements need to be executed before execution ps1 Script tsSmtp.WriteLine "# Execute below command first, then ps1 script will allowed." tsSmtp.WriteLine "# Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser" ' Create business units and large user groups For row = 2 To 18 grp = Range("L" & row) If Left(grp, 2) <> "RD" Then grp = "BU-" & grp tsUsr.WriteLine "net localgroup " & grp & " /add /comment:""" & Range("M" & row) & """" Next row ' Create R & D classified user groups under the business unit, and list similar R & D business unit groups For row = 2 To 13 grp = Range("L" & row) cmt = Range("M" & row) If Left(grp, 2) <> "RD" Then grp = "BU-" & grp tsUsr.WriteLine "net localgroup " & grp & "-HW /add /comment:""" & cmt & " Hardware""" tsUsr.WriteLine "net localgroup " & grp & "-FPGA /add /comment:""" & cmt & " FPGA""" tsUsr.WriteLine "net localgroup " & grp & "-FW /add /comment:""" & cmt & " embed""" tsUsr.WriteLine "net localgroup " & grp & "-SW /add /comment:""" & cmt & " Software""" Next row For row = 2 To 1000 usr = Trim(Range("A" & row).Text) grp = Trim(Range("D" & row).Text) ' Row A Column is empty, indicating the end of processing If usr = "" Then Exit For ' wrong RD Add BU prefix If Left(grp, 2) <> "RD" Then grp = "BU-" & grp ' Add user tsUsr.WriteLine "net user " & usr & " """ & Range("B" & row) & """ /add /active:yes /expires:never /fullname:" & Range("C" & row) ' User password never expires tsUsr.WriteLine "wmic useraccount where name='" & usr & "' set passwordexpires=false" ' Add users to the business unit tsUsr.WriteLine "net localgroup " & grp & " " & usr & " /add" ' Add users to the R & D team of the business unit according to the R & D content If Range("E" & row).Text = "Y" Then tsUsr.WriteLine "net localgroup " & grp & "-HW " & usr & " /add" & vbCrLf & "net localgroup RD-AllHW " & usr & " /add" If Range("F" & row).Text = "Y" Then tsUsr.WriteLine "net localgroup " & grp & "-FPGA " & usr & " /add" & vbCrLf & "net localgroup RD-AllFPGA " & usr & " /add" If Range("G" & row).Text = "Y" Then tsUsr.WriteLine "net localgroup " & grp & "-FW " & usr & " /add" & vbCrLf & "net localgroup RD-AllFW " & usr & " /add" If Range("H" & row).Text = "Y" Then tsUsr.WriteLine "net localgroup " & grp & "-SW " & usr & " /add" & vbCrLf & "net localgroup RD-AllSW " & usr & " /add" If Range("I" & row).Text = "Y" Then tsUsr.WriteLine "net localgroup BU-Leader " & usr & " /add" Next row tsUsr.Close tsSmtp.Close MsgBox "OK" End Sub
3. Install and configure SVN
3.1 establish SVN Library
After the installation, create a Demo library, manually add the read-write access rights of the management account, copy the account authentication configuration file, and then prepare the hook file of the required SVN. Prepare the list file "1.svn-repo.txt" of the business unit. Each line only has the name of the business unit (copy from Excel). Use batch command to generate SVN library and offline SVN configuration.
for /f %%i in (1.svn-repo.txt) do ( svnadmin create E:\Repositories\%%i mkdir %%i\conf\ mkdir %%i\hooks\ copy /y VisualSVN-WinAuthz.ini %%i\conf\ copy /y pre-commit.cmd %%i\hooks\ )
3.2 create primary directory and configure
Use the svn command to manage the account and create the first level directory of each library:
for /f %%i in (1.svn-repo.txt) do ( svn mkdir https://BYHX-MasterServ:8443/svn/%%i/hw -m "Create hardware folder" svn mkdir https://BYHX-MasterServ:8443/svn/%%i/fpga -m "Create FPGA folder" svn mkdir https://BYHX-MasterServ:8443/svn/%%i/fw -m "Create firmware folder" svn mkdir https://BYHX-MasterServ:8443/svn/%%i/sw -m "Create software folder" )
Use a similar loop and the "PsGetsid" tool to obtain the user's SID information file. A single SID information is similar to
SID for my-co-server\whom: S-1-5-21-316025195-1075053894-3005689260-1012
Use shell script to process SID information (note to convert "sidresult.txt" to unix format first)
cat sidresult.txt | egrep "SID\ for|S\-1" | sed -e 'N;s/\n//g' | sed -e 's/^.*\\//g' > sidlist.txt
The processed information is similar to:
whom:S-1-5-21-316025195-1075053894-3005689260-1012
With SID information table, use VBA of Excel to process permission information:
Function GetSID(sName As String) Dim sidFile As TextStream Dim outFolder As String Dim str As String, s1 As String Dim pos As Integer outFolder = "D:\BYHX\Server\" Set sidFile = fso.OpenTextFile(outFolder & "sidlist.txt", ForReading) Do While Not sidFile.AtEndOfStream str = sidFile.ReadLine pos = InStr(str, ":") s1 = Left(str, pos - 1) If s1 = sName Then GetSID = mid(str, pos + 1) Exit Do End If Loop End Function Sub ModiPrivilege() Dim row As Integer, i As Integer Dim outFolder As String Dim authFile As TextStream Dim str As String, s1 As String Dim usr As String, grp As String Set fso = CreateObject("Scripting.FileSystemObject") outFolder = "D:\BYHX\Server\" ' Add full permissions for the library to the owner For row = 2 To 1000 usr = Trim(Range("A" & row).Text) grp = Trim(Range("D" & row).Text) ' Row A Column is empty, indicating the end of processing If usr = "" Then Exit For ' wrong RD Add BU prefix If Left(grp, 2) <> "RD" Then grp = "BU-" & grp If Range("I" & row).Text = "Y" Then str = outFolder & grp & "\conf\VisualSVN-WinAuthz.ini" Set authFile = fso.OpenTextFile(str, ForAppending) authFile.WriteLine GetSID(usr) & "=rw" authFile.Close End If Next row ' R & D classification user group under the business unit, setting authority For row = 2 To 13 grp = Range("L" & row) If Left(grp, 2) <> "RD" Then grp = "BU-" & grp Set authFile = fso.OpenTextFile(outFolder & grp & "\conf\VisualSVN-WinAuthz.ini", ForAppending) authFile.WriteLine vbCrLf & "[/hw]" authFile.WriteLine GetSID(grp & "-HW") & "=rw" authFile.WriteLine vbCrLf & "[/fpga]" authFile.WriteLine GetSID(grp & "-FPGA") & "=rw" authFile.WriteLine vbCrLf & "[/fw]" authFile.WriteLine GetSID(grp & "-FW") & "=rw" authFile.WriteLine vbCrLf & "[/sw]" authFile.WriteLine GetSID(grp & "-SW") & "=rw" authFile.Close Next row MsgBox "OK" End Sub
Copy the offline SVN configuration file to the SVN database directory, restart the SVN service, and the SVN configuration is completed.
4. Send notification email
It is necessary to inform all colleagues of the password of each account. Copy the user name and password columns of Excel to a text file. Switch to unix format. The sending email script is as follows:
#!/usr/bin/bash input="mailaccount.txt" while IFS= read -r line do _usr=`echo -n $line | gawk ''` _pwd=`echo -n $line | gawk '' | ./htmlenc.exe` cat SwithMailSettings.xml | sed -e "s/__to_person__/$_usr/g" -e "s/__password__/$_pwd/g" > account.xml ./SwithMail.exe /s /x account.xml done < "$input"
The command line mail tool selects "SwithMail" based on 7 Command Line Utilities to Easily Send Email Using SMTP Recommendation. Of course, it's OK to use PowerShell, but it's a little bit troublesome.
dabbler_zhu Published 35 original articles, won praise 2, visited 70000+ Private letter follow