安装研发服务器
重装服务器真是一个耗精力的过程,尤其是用ghost做数据全盘备份,数据ghost恢复蜗牛一般的速度,再加上ghost居然人生第一次碰到了软件会异常问题,真的是让人痛苦不堪啊。从现在想来,可能不如用imagex来备份数据,imagex至少可以直接mount,省了我不断的恢复过程啊。回想起来,选ghost唯一的理由,应该是:全盘备份,可以必要时候全盘恢复。不过,这个不是这里的重点。这里主要讲服务安装时候,自动化脚本构建。当然,使用构建脚本的方法,可能真的不如直接手动操作,但是,万一需要第二台或第二次再来一遍呢。当然,程序员对于人肉方法,也是倾向于不屑一顾的。
1. 组织架构
公司转向了事业部制,大概的公司结构如下: 基本svn设计是,每个事业部有一个svn库,下面设一级目录,hw/fpga/fw/sw,分别授权不同的工程师访问。
2. 创建用户和用户组
用户归属于事业部,需要创建事业部组,事业部下根据研发性质,在细分成hw/fpga/fw/sw用户组,创建用户用命令“net user”,从excel生成命令脚本使用excel的vba生成,代码如下:
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,需要先执行以下的语句,才能执行ps1脚本 tssmtp.writeline "# execute below command first, then ps1 script will allowed." tssmtp.writeline "# set-executionpolicy -executionpolicy unrestricted -scope currentuser" ' 创建事业部和大的用户性质用户组 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 ' 创建事业部下研发分类用户组,以及列出同类研发事业部组列表 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 & " 硬件""" tsusr.writeline "net localgroup " & grp & "-fpga /add /comment:""" & cmt & " fpga""" tsusr.writeline "net localgroup " & grp & "-fw /add /comment:""" & cmt & " 嵌入""" tsusr.writeline "net localgroup " & grp & "-sw /add /comment:""" & cmt & " 软件""" next row for row = 2 to 1000 usr = trim(range("a" & row).text) grp = trim(range("d" & row).text) ' 行的a列为空,表示处理结束 if usr = "" then exit for ' 非rd的,添加bu前缀 if left(grp, 2) <> "rd" then grp = "bu-" & grp ' 添加用户 tsusr.writeline "net user " & usr & " """ & range("b" & row) & """ /add /active:yes /expires:never /fullname:" & range("c" & row) ' 用户密码永不过期 tsusr.writeline "wmic useraccount where name='" & usr & "' set passwordexpires=false" ' 把用户添加到事业部 tsusr.writeline "net localgroup " & grp & " " & usr & " /add" ' 根据研发内容,添加用户到事业部研发组 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. 安装和配置svn
3.1 建立svn库
安装完毕之后,建立一个demo库,手动添加管理账号的读写访问权限,拷贝出账号认证配置文件,再准备好需要的svn的hook文件。 准备好事业部列表文件“1.svn-repo.txt”,每行只有事业部的名称(从excel拷贝出来即可),用批处理命令,生成svn库,以及离线svn配置。
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 创建一级目录并配置
用svn命令,管理账号,创建各个库的一级目录:
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" )
用类似的循环,用“psgetsid”工具,获取用户的sid信息文件,单个sid信息类似于
sid for my-co-server\whom:
s-1-5-21-316025195-1075053894-3005689260-1012
利用shell脚本,处理sid信息(注意先转换“sidresult.txt”为unix格式)
cat sidresult.txt | egrep "sid\ for|s\-1" | sed -e 'n;s/\n//g' | sed -e 's/^.*\\//g' > sidlist.txt
处理完信息类似于:
whom:s-1-5-21-316025195-1075053894-3005689260-1012
有了sid信息表之后,用excel的vba,处理权限信息:
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\" ' 给负责人添加库的完全权限 for row = 2 to 1000 usr = trim(range("a" & row).text) grp = trim(range("d" & row).text) ' 行的a列为空,表示处理结束 if usr = "" then exit for ' 非rd的,添加bu前缀 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 ' 事业部下研发分类用户组,设置权限 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
将离线的svn配置文件,复制到svn库目录,重启svn服务,svn配置完成。
4. 发送通知邮件
需要把各个账户的密码,通知到各位同仁。将excel的用户名和密码这两列,复制到文本文件。转为unix格式。发送邮件脚本如下:
#!/usr/bin/bash
input="mailaccount.txt"
while ifs= read -r line
do
_usr=`echo -n $line | gawk '{printf "%s",$1}'`
_pwd=`echo -n $line | gawk '{printf "%s",$2}' | ./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"
命令行邮件工具选择了“swithmail”,依据的是7 command line utilities to easily send email using smtp的推荐。当然,用powershell也可以,就是比较麻烦一点点。
下一篇: 微软跨平台ORM框架之EFCore