Borkputsthe'sh'backintoIT.BorkBorkBork.
Borkisnolongerunderactivedevelopment.Ifyouforkitandyourforkgetssomesteamgoing,pleaseletmeknow,I'mhappytoaddyoutothislist.
KnownActiveForks:SkylarMacDonaldtheSwedishChefPuppetofConfigManagementBorkisabashDSLformakingdeclarativeassertionsaboutthestateofasystem.
BorkiswrittenagainstBash3.2andcommonunixutilitiessuchassed,awkandgrep.ItisdesignedtoworkonanyUNIX-basedsystemandmaintainawarenessofplatformdifferencesbetweenBSDandGPLversionsofunixutilities.
InstallationFromsourceClonethisrepository: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:brewinstallborkUsageandOperationsRunningborkwithoutargumentswilloutputsomehelp:
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:listtypesandtheirusageinformationLet'sexploretheseinmoredepth:
AssertionsandConfigFilesAttheheartofborkismakingassertionsinadeclarativemannerviatheokfunction.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~withaleadingdotdoneWhenrun,borkwilltesteachokassertionanddetermineifit'smetornot.Ifnot,borkcangoaheadandsatisfytheassertionbyinstalling,upgrading,oralteringtheconfigurationoftheitemtomatchtheassertion.Itwillthentesttheassertionagain.Declarationsareidempotent--iftheassertionisalreadymet,borkwillnotdoanything.
Whenyou'rehappywithyourconfigscript,youcancompileittoastandalonescriptwhichdoesnotrequireborktorun.Thecompiledscriptcanbepassedaroundviacurl,scporthelikeandrunoncompletelynewsystems.
AssertionTypesYoucanrunborktypesfromthecommandlinetogetalistoftheassertiontypesandsomebasicinformationabouttheirusageandoptions.
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:assertspresenceofiptablesruleRuntimeOperationsPertheusageguide,borkhasafewmainmodesofoperation:
status:Reportsonthestatusoftheassertionsinaconfigfile.satisfy:Checksthestatusofassertionsinaconfigfile,satisfyingthemwhereneeded.compile:Compilesaconfigfiletoastandalonescript.check:Performsastatusreportonasingleassertion.do:Performsasatisfyoperationonasingleassertion.borkstatusmyconfig.shThestatuscommandwillconfirmthatassertionsaremetornot,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:55Eachitemreportsitsstatuslikeso:
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/dotfilesThecheckcommandwilltakeasingleassertiononthecommandlineandperformastatuscheckasaboveforit.
borksatisfymyconfig.shThesatisfycommandiswheretherealmagichappens.Foreveryassertionintheconfigfile,borkwillcheckitsstatusasdescribedinthestatuscommandabove,andifitisnotokitwillattempttomakeitok,typicallyviainstallingorupgradingsomething--butsometimesaconflictisdetectedwhichcouldlosedata,suchasalocalgitrepositoryhavinguncommittedchanges.Inthatcase,borkwillwarnyouabouttheproblemandaskifyouwanttoproceed.Sometimesconflictsaredetectedwhichborkdoesnotknowhowtoresolve—itwillwarnyouabouttheproblemsoyoucanfixityourself.
borkdookgithubmattly/dotfilesThedocommandwilltakeasingleassertiononthecommandlineandperformasatisfyoperationonitasabove.
borkcompilemyconfig.shThecompilecommandwilloutputtoSTDOUTastandaloneshellscriptthatdoesnotrequireborktorun.Youmaypassthisaroundaswithanyfileviacurlorscporwhateveryoulikeandrunit.Anysub-configsviaincludewillbeincludedintheoutput,andanytypethatneedstoincluderesourcestodowhatitdoes,suchasthefiletype,willincludetheirresourcesinthescriptasbase64encodeddata.
CustomTypesWritingnewtypesisprettystraightforward,andthereisaguidetowritingtheminthedocs/directory.Ifyouwishtouseatypethatisnotinbork'stypesdirectory,youcanletborkknowaboutitwiththeregisterdeclaration:
registeretc/pgdb.shokpgdbmy_app_dbComposingConfigFilesYoumaycomposeconfigfilesintogreateroperationswiththeincludedirectivewithapathtoascriptrelativetothecurrentscript'sdirectory.
#thisismain.shincludedatabases.shincludeetc/projects.sh#thisisetc/projects.shincludeproject-one.shincludeproject-two.sh#thesewillbereadfromtheetc/directoryTakingFurtherActiononChangesBorkdoesn'thavecallbacksper-se,butaftereachassertionthereareahandfuloffunctionsyoucancalltotakefurtheraction:
okbrewfishifdid_install;thensudoecho"/usr/local/bin/fish">>/etc/shellschsh-s/usr/local/bin/fishfiTherearefourfunctionstohelpyoutakefurtheractionsonchange:
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-featureSubmitapullrequestContributionGuidelinesPreferclarityofintentoverbrevity.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.
CommunityFeelfreetojoinusinIRC:
Hostname:irc.freenode.orgChannel:#bork.shWebIRCclientincaseyoudon'thaveanativeoneRequirements/DependenciesBash3.2Version0.10.0
LicenseApacheLicense2.0
评论