bork the Bash-Operated Reconciling Kludge开源项目

我要开发同款
匿名用户2021年11月09日
31阅读
开发技术SHELL
所属分类终端/远程登录、应用工具
授权协议View license

作品详情

Bork-(nolongerunderdevelopment)

Borkputsthe'sh'backintoIT.BorkBorkBork.

Borkisnolongerunderactivedevelopment.Ifyouforkitandyourforkgetssomesteamgoing,pleaseletmeknow,I'mhappytoaddyoutothislist.

KnownActiveForks:SkylarMacDonaldtheSwedishChefPuppetofConfigManagement

BorkisabashDSLformakingdeclarativeassertionsaboutthestateofasystem.

BorkiswrittenagainstBash3.2andcommonunixutilitiessuchassed,awkandgrep.ItisdesignedtoworkonanyUNIX-basedsystemandmaintainawarenessofplatformdifferencesbetweenBSDandGPLversionsofunixutilities.

InstallationFromsource

Clonethisrepository:gitclonehttps://github.com/mattly/bork/usr/local/src/bork

Symlinktheborkbinariesintoyour$PATH:

ln-sf/usr/local/src/bork/bin/bork/usr/local/bin/borkviaHomebrew(MacOSX)InstallviaHomebrew:brewinstallborkUsageandOperations

Runningborkwithoutargumentswilloutputsomehelp:

borkusage:borkoperation[config-file][options]where"operation"isoneof:-check:perform'status'forasinglecommandexample:borkcheckokgithubmattly/dotfiles-compile:compiletheconfigfiletoaself-containedscriptoutputtoSTDOUT--conflicts=(y|yes|n|no)Ifgiven,setsanautomaticanswerforconflictresolution.example:borkcompiledotfiles.sh--conflicts=y>install.sh-do:perform'satisfy'forasinglecommandexample:borkdookgithubmattly/dotfiles-satisfy:satisfytheconfigfile'sconditionsifpossible-status:determineiftheconfigfile'sconditionsaremet-types:listtypesandtheirusageinformation

Let'sexploretheseinmoredepth:

AssertionsandConfigFiles

Attheheartofborkismakingassertionsinadeclarativemannerviatheokfunction.Thatis,youtellitwhatyouwantthesystemtolooklikeinsteadofhowtomakeitlooklikethat.Anassertiontakesatypeandanumberofarguments.Itinvokesthetype'shandlerfunctionwithanactionsuchasstatus,install,orupgrade,whichdeterminestheimperativecommandsneededtotesttheassertionorbringituptodate.Thereareanumberofincludedtypesinthetypesdirectory,andborkmakesiteasytocreateyourown.

Here'sabasicexample:

okbrew#presenceandupdatednessofHomebrewokbrewgit#presenceandupdatednessofHomebrewgitpackageokdirectory$HOME/code#presenceofthe~/codedirectoryokgithub$HOME/code/dotfilesmattly/dotfiles#presence,driftofgitrepositoryin~/code/dotfilescd$HOMEforfilein$HOME/code/dotfiles/configs/.[!.]*do#foreachfilein~/code/dotfiles/configs,oksymlink"$(basename$file)"$file#presenseofasymlinktofilein~withaleadingdotdone

Whenrun,borkwilltesteachokassertionanddetermineifit'smetornot.Ifnot,borkcangoaheadandsatisfytheassertionbyinstalling,upgrading,oralteringtheconfigurationoftheitemtomatchtheassertion.Itwillthentesttheassertionagain.Declarationsareidempotent--iftheassertionisalreadymet,borkwillnotdoanything.

Whenyou'rehappywithyourconfigscript,youcancompileittoastandalonescriptwhichdoesnotrequireborktorun.Thecompiledscriptcanbepassedaroundviacurl,scporthelikeandrunoncompletelynewsystems.

AssertionTypes

Youcanrunborktypesfromthecommandlinetogetalistoftheassertiontypesandsomebasicinformationabouttheirusageandoptions.

Genericassertionscheck:runsagivencommand.OKifreturns0,FAILEDotherwise.FileSystemdirectory:assertspresenceofadirectoryfile:assertsthepresence,checksum,ownerandpermissionsofafiledownload:assertsthepresenceofafilecomparedtoanhttp(s)urlsymlink:assertpresenceandtargetofasymlinkSourceControlgit:assertspresenceandstateofagitrepositorygithub:front-endforgittype,usesgithuburlsLanguagePackageManagersgem:assertsthepresenceofagemintheenvironment'srubynpm:assertsthepresenceofanodejsmoduleinnpm'sglobalinstallationpip:assertspresenceofpackagesinstalledviapippipsi:assertspresenceofpipsiorpackagesinstalledviapipsiapm:assertsthepresenceofanatompackagego-get:assertsthepresenceofagopackageMacOSXspecificbrew:assertspresenceofpackagesinstalledviaHomebrewonMacOSXbrew-tap:assertsaHomebrewformularepositoryhasbeentapped;doesNOTassertupdatednessofatap'sformula.Use`okbrew`forthat.cask:assertspresenceofappsinstalledviacaskroom.ioonMacOSXdefaults:assertssettingsforOSX's'defaults'systemmas:assertsaMacappisinstalledandup-to-datefromtheAppStoreviathe'mas'utilityhttps://github.com/argon/masscutil:verifiesOSXmachinenamewithscutilLinuxspecific:apt:assertspackagesinstalledviaapt-getonDebianorUbuntuLinuxyum:assertspackagesinstalledviayumonCentOSorRedHatLinuxzypper:assertspackagesinstalledviazypper(SUSE)Usermanagement(currentlyLinux-only)group:assertspresenceofaunixgroup(Linuxonly,fornow)user:assertpresenceofauseronthesystemUNIXutilitiesiptables:assertspresenceofiptablesruleRuntimeOperations

Pertheusageguide,borkhasafewmainmodesofoperation:

status:Reportsonthestatusoftheassertionsinaconfigfile.satisfy:Checksthestatusofassertionsinaconfigfile,satisfyingthemwhereneeded.compile:Compilesaconfigfiletoastandalonescript.check:Performsastatusreportonasingleassertion.do:Performsasatisfyoperationonasingleassertion.borkstatusmyconfig.sh

Thestatuscommandwillconfirmthatassertionsaremetornot,andoutputtheirstatus.Itwillnottakeanyactiontosatisfythoseassertions.Thereareahandfulofstatusesanassertioncanreturn,andthissincethismodeistheclosestborkcandotoatruedryrun(*)youcanuseittotestascriptagainstapre-existingmachine.

Sometypes,suchasgit,needtomodifylocalstatebytalkingtothenetwork(suchasperforminggitfetch),withoutmodifyingthethingstheassertionaimstocheck.

Thestatuscommandwillgiveyououtputsuchas:

outdated:brewok:brewgitmissing:brewfishok:directory/Users/mattly/code/mattlyconflict(upgradable):githubmattly/dotfileslocalgitrepositoryhasuncommittedchangesok:symlink/Users/mattly/.gitignore/Users/mattly/code/mattly/dotfiles/configs/gitignoreconflict(clobberrequired):symlink/Users/mattly/.lein/Users/mattly/code/mattly/dotfiles/configs/leinnotasymlink:/Users/mattly/.leinmismatch(upgradable):defaultscom.apple.docktilesizeinteger36expectedtype:integerreceivedtype:floatexpectedvalue:36receivedvalue:55

Eachitemreportsitsstatuslikeso:

ok:Theassertionismetasbestwecandetermine.missing:Theassertionisnotmet,andnotraceofiteverbeingmetwasfound.outdated:Theassertionismet,butcanbeupgradedtoanewerversion.mismatch(upgradable):Theassertionisnotmetasspecified,somethingisdifferent.Itcanbesatisfiedeasily.Anexplanationwillbegiven.conflict(upgradable):Theassertionisnotmetasspecified.Itcanbesatisfiedeasily,butdoingsomayresultindataloss.conflict(clobberrequired):Theassertionisnotmetasspecified.Borkcannotcurrentlysatisfythisassertion.Inthefuture,itwillbeableto,butdoingsomayresultindataloss.borkcheckokgithubmattly/dotfiles

Thecheckcommandwilltakeasingleassertiononthecommandlineandperformastatuscheckasaboveforit.

borksatisfymyconfig.sh

Thesatisfycommandiswheretherealmagichappens.Foreveryassertionintheconfigfile,borkwillcheckitsstatusasdescribedinthestatuscommandabove,andifitisnotokitwillattempttomakeitok,typicallyviainstallingorupgradingsomething--butsometimesaconflictisdetectedwhichcouldlosedata,suchasalocalgitrepositoryhavinguncommittedchanges.Inthatcase,borkwillwarnyouabouttheproblemandaskifyouwanttoproceed.Sometimesconflictsaredetectedwhichborkdoesnotknowhowtoresolve—itwillwarnyouabouttheproblemsoyoucanfixityourself.

borkdookgithubmattly/dotfiles

Thedocommandwilltakeasingleassertiononthecommandlineandperformasatisfyoperationonitasabove.

borkcompilemyconfig.sh

ThecompilecommandwilloutputtoSTDOUTastandaloneshellscriptthatdoesnotrequireborktorun.Youmaypassthisaroundaswithanyfileviacurlorscporwhateveryoulikeandrunit.Anysub-configsviaincludewillbeincludedintheoutput,andanytypethatneedstoincluderesourcestodowhatitdoes,suchasthefiletype,willincludetheirresourcesinthescriptasbase64encodeddata.

CustomTypes

Writingnewtypesisprettystraightforward,andthereisaguidetowritingtheminthedocs/directory.Ifyouwishtouseatypethatisnotinbork'stypesdirectory,youcanletborkknowaboutitwiththeregisterdeclaration:

registeretc/pgdb.shokpgdbmy_app_dbComposingConfigFiles

Youmaycomposeconfigfilesintogreateroperationswiththeincludedirectivewithapathtoascriptrelativetothecurrentscript'sdirectory.

#thisismain.shincludedatabases.shincludeetc/projects.sh#thisisetc/projects.shincludeproject-one.shincludeproject-two.sh#thesewillbereadfromtheetc/directoryTakingFurtherActiononChanges

Borkdoesn'thavecallbacksper-se,butaftereachassertionthereareahandfuloffunctionsyoucancalltotakefurtheraction:

okbrewfishifdid_install;thensudoecho"/usr/local/bin/fish">>/etc/shellschsh-s/usr/local/bin/fishfi

Therearefourfunctionstohelpyoutakefurtheractionsonchange:

did_install:didthepreviousassertionresultintheitembeinginstalledfromscratch?did_upgrade:didthepreviousassertionresultintheexistingitembeingupgraded?did_update:didthepreviousassertionresultineithertheitembeinginstalledorupgraded?did_error:didattemptingtoinstallorupgradethepreviousassertionresultinanerror?ContributingForkitCreateyourfeaturebranch:gitcheckout-bfeature/my-new-featureCommityourchanges:gitcommit-am'Addsomefeature'Pushtothebranch:gitpushoriginfeature/my-new-featureSubmitapullrequestContributionGuidelines

Preferclarityofintentoverbrevity.Bashcanbeanobtuselanguage,butitdoesn'thavetobe.Manypeoplehavesaidborkhassomeoftheclearestbashcodethey'veeverseen,andthat'sastandardtostrivefor.

Favorhelperabstractionsoverarbitraryplatform-specificchecks.Seemd5cmd,http,andpermission_cmd,andlookathowthey'reused.

Typesareindependent,stateless,andatomic.Donotattempttomaintainacacheinatypefileunlessyou'retalkingtothenetwork.Anassertionisthewholeoftheassertion—don'tattempttocreateamulti-stageassertiontypethatdependsonmaintainingstate.Findawaytoexpressthewholeoftheassertioninonego.

LeaveDependencyManagementtotheuser.Isaneededbinarynotinstalledforatype?Return$STATUS_FAILED_PRECONDITIONinyourstatuscheck.Lettheuserdecidethebestwaytosatisfyanydependencies.

Community

FeelfreetojoinusinIRC:

Hostname:irc.freenode.orgChannel:#bork.shWebIRCclientincaseyoudon'thaveanativeoneRequirements/DependenciesBash3.2Version

0.10.0

License

ApacheLicense2.0

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论