Giter VIP home page Giter VIP logo

zero.sh's Introduction

Build Status Latest Release

Zero.sh - Start with a clean slate

Create an identical installation on any Mac with a single command.

This lets you to restore a machine without having to deal with the mess that was the state of a previous installation, or painstakingly babysit the process step-by-step.

Unlike other solutions, this approach is extremely simple. It's just a small tool with a pre-defined directory structure. No additional configuration files or complex commands are necessary.

Usage

Instead, just run the following:

# Clone your configuration repo to your preferred location. For example:
git clone --recursive <YOUR_REPO> ~/.dotfiles

# If on a new machine, once finished, restart and run again to ensure system 
# settings are applied correctly.
zero setup

... and you'll be back up and running, with all of your applications and command line utilities re-installed (and configurations restored).

Note: By default, zero assumes your configuration directory is located in one of following locations. This can be changed with the --directory flag.

  1. $XDG_CONFIG_HOME/zero/dotfiles
  2. $HOME/.config/zero/dotfiles
  3. $HOME/.dotfiles

During setup, you may be asked for your password as some commands require admin privileges. Each of these will be printed before running.

The setup command will do the following, in order:

  1. Check for system and application updates via softwareupdate, brew, brew cask, and mas.
  2. Install packages and applications via Homebrew Bundle.
  3. Run any scripts under run/before in alphabetical order.
  4. Apply system defaults described in defaults.yaml via apply-user-defaults.
  5. Symlink configuration files listed under symlinks to the home directory.
  6. Run the remaining scripts under run/after in alphabetical order.

This command is idempotent, and can be safely invoked again to update tools and ensure everything has been installed correctly.

It will not wipe over files that already exist when symlinking or at any other point in the process, aside from what is done by system upgrade tools or in your own custom before & after scripts.

In addition, there is no magic done by this tool. Each command is printed before it is run.

Initially, this was encapsulated in a Python library called Cider, but now that Homebrew added back Brewfile support it has been migrated to this simple utility and directory structure instead.

Directory Structure

The directory structure in ~/.dotfiles (or wherever you choose to store it) is expected to look like this:

- Brewfile # Homebrew Bundle dependency file.
- defaults.yaml # macOS defaults to be set by apply-user-defaults command.
- symlinks/
    -> name/ # Arbitrary alias, for example "zsh", "vim", etc.
        => file or directory # Exact name of file or directory to symlink.
- run/
    -> before/
        => [ ... executable scripts ... ]
    -> after/
        => [ ... executable scripts ... ]

Workspaces

Multiple machine configurations can be managed via the following directory structure:

- workspaces/
  -> shared/
  -> home/
  -> work/

This will first apply the setup described in shared, followed by home or work when specifying a workspace argument via:

~/.dotfiles/zero/setup [home|work]

It can also recurse, for example:

- workspaces/
  -> shared/
  -> home/
    => workspaces/
      -> shared/
      -> desktop/
      -> laptop/
  -> work/

This describes three workspaces, home.desktop, and home.laptop, and work.

It will run the same series of steps as before, but first setup the workspace described in shared of the parent or sister directory. For example, when running zero/setup home.desktop, it will do the following:

  1. Check for system and application updates.
  2. For each workspace in workspaces/shared, workspaces/home/workspaces/shared, then workspaces/home/workspaces/desktop:
    • Install packages and applications via Homebrew Bundle.
    • Run any scripts under run/before in alphabetical order.
    • Apply system defaults described in defaults.yaml via apply-user-defaults.

... etc., for each of the steps listed above.

Additional Features

Zero also supports running any of the above steps independently.

Usage: zero <command> [options]

Radically simple personal bootstrapping tool for macOS.

Commands:
  setup             Setup a workspace, or directory if none is given
  update            Check for system and application updates
  bundle            Run brew bundle on a workspace
  apply-defaults    Apply user defaults for a workplace
  apply-symlinks    Apply symlinks for a workplace
  run-scripts       Run before & after scripts for a workplace
  help              Prints help information
  version           Prints the current version of this app

Installation

Homebrew

Homebrew is the preferred way to install:

$ brew install zero-sh/tap/zero

Alternatively, pre-compiled binaries are available on the releases page.

Building from Source

To build from source, run:

$ git clone https://github.com/zero-sh/zero.sh.git zero
$ cd zero
$ make archive
# make install

To develop locally, instead use swift run zero.

Submodule

Since zero requires Homebrew for installation, it needs a helper script for the initial setup. This repo contains one that can either be copied or included as a submodule:

cd ~/.dotfiles
git submodule add https://github.com/zero-sh/zero.sh zero

Then, to pin to the latest stable version, run:

git submodule update --init --remote zero
git -C zero checkout <VERSION>
git commit

Now when bootstrapping your new machine, you can simply run:

git clone --recursive <YOUR_REPO> ~/.dotfiles
~/.dotfiles/zero/setup

This gives you a single script that can be used to fully setup your new machine.

It is equivalent to running the zero setup command (and will accept any respective arguments, e.g. workspaces), only it first installs Homebrew and zero. Just like zero setup, it is idempotent and can be safely run again.

Note that it may be necessary run git submodule update --init later when pulling in the new submodule into an existing repo, unless the --recursive flag is included when cloning as shown above.

Working examples

To see how this works out in practice, here are some repos that use zero.sh:

Add yours here โ€” send a PR.

Roadmap & missing features

  • Linux support. This should be pretty straightforward, but requires accounting for additional system update tools and package managers that I haven't had time for yet. It will also be limited to distributions that support Swift.

  • Currently it's not possible to specify a target for symlinks; they are just all expanded to the home directory, matching the nested directory structure they are contained in under symlinks/. This works fine for my use-case but not sure if it will be enough for others.

  • GNU Stow is a neat tool, but doesn't offer the same level of utility or error handling that Cider previously did. It would be nice to offer a more modern alternative.

Note: zero.sh is a work-in-progress, but it's fairly well-tested and should be kind to your machine.

Dependencies

The following dependencies are required & installed when building the brew formula:

In addition, Homebrew and Xcode Command Line Tools are required.

Non-Goals

This tool is intended to be a very minimal approach to personal system configuration. If you are looking for something more full-featured, e.g. that provides a complex CLI or additional features for managing many machines at once, there are other solutions available. In my experience just dealing with my own machines, this was all that was necessary.

Contributing

If you are interested in this project, please consider contributing. Here are a few ways you can help:

  • Report issues.
  • Fix bugs and submit pull requests.
  • Write, clarify, or fix documentation.
  • Suggest or add new features.
  • Star this repository so it can be added to upstream Homebrew.

Inspiration

This is partly inspired by @gerhard's setup, in addition to this blog post on GNU Stow by Brandon Invergo. It is structurally based on (and the spiritual successor to) Cider.

License

Zero.sh is licensed under the MIT License. See LICENSE for more information.

zero.sh's People

Contributors

buckleyc avatar jjlauterbach avatar msanders avatar pghk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zero.sh's Issues

Verbose flag for commands

Hey, thanks for putting this together! I was running it on an older device and brew bundle seemed to be hanging/frozen, when in fact it was just taking a while to install Python. I would find it useful to have a verbose flag for Zero (i.e. how brew bundle -v works) to monitor the status of commands in detail as well as run sub-commands(?) in verbose mode. Something like zero setup -v would run brew bundle -v once it got to the bundle step. There may be other cases where verbosity could be useful, but I haven't looked around too much yet.

Crash when scripts don't have the execute bit

Some of my scripts were created as text files by accident. Obviously it makes sense to fail somehow in this case, but the error is fairly cryptic.

~ chmod -x ~/.dotfiles/run/before/000-no-escape.sh 
~ zero run-scripts
==> Running scripts in run/before
==> ./000-no-escape.sh
2020-04-10 15:41:12.454 zero[1669:33328] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'launch path not accessible'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff2edced07 __exceptionPreprocess + 250
	1   libobjc.A.dylib                     0x00007fff679595bf objc_exception_throw + 48
	2   Foundation                          0x00007fff3148b06d -[NSConcreteTask launchWithDictionary:error:] + 5229
	3   zero                                0x000000010c7e4810 zero + 292880
	4   zero                                0x000000010c7e4ca8 zero + 294056
	5   zero                                0x000000010c7f3a5b zero + 354907
	6   zero                                0x000000010c7f0275 zero + 340597
	7   zero                                0x000000010c7efd68 zero + 339304
	8   zero                                0x000000010c7f0549 zero + 341321
	9   zero                                0x000000010c7b9648 zero + 116296
	10  zero                                0x000000010c7b91cb zero + 115147
	11  zero                                0x000000010c7b9159 zero + 115033
	12  zero                                0x000000010c7f5034 zero + 360500
	13  libdyld.dylib                       0x00007fff68b00cc9 start + 1
	14  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
fish: 'zero run-scripts' terminated by signal SIGABRT (Abort)
~ 

Why the domain Zero.sh ?

Hey there, I own and I'm about to launch my startup called Zero.sh. Why this project uses this domain if you don't own it? Isn't it confusing for both my clients & your users?

Costantin

Setup stuck at the brew install step

Hello.

I am experiencing a freeze for zero setup [env] at the step of brew installing programmes from Brewfile, specifically brew [something] lines (everything seems ok with cask [something] lines).

I've tried installing directly with brew bundle --file path/to/Brewfile and it's working with no problems, so I think it could be something with the way zero runs brew bundle.

Would appreciate any help, thanks.

Setup scripts fails to install zero from brew

Related to #5... the setup script reference was not updated so the setup script fails to install zero.

Installing Zero...
Updating Homebrew...
Error: No available formula with the name "zero-sh/tap/zero-sh"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.

Symlink generation fails during setup when file already exists

When running setup stow fails to overwrite already existing symlinks. Also if file already exists in home directory stow will fail to create new symlink from .dotfiles folder. Application should perform force update on existing symlinks and ask user if he wants to remove or adopt file (see stow --adopt).

Software update not prompting for credentials

Hi,
I was testing your tool and I got stuck on software update for macOS. It seems that zero is not correctly prompting for credentials to install the update on non-root shell. If executed with sudo zero setup -d <dotfiles> it works correctly.

Log

zero setup
Software Update Tool

Finding available software
Software Update found the following new or updated software:
* Label: macOS Catalina 10.15.4 Update-

Install system updates? This will restart your machine if necessary. [Y/n]: y

^C
Password:
sudo: unable to read password: Input/output error

Delete missing items from Brewfile

Hi there !

I love the tool and use it as a setup as code for my macs.
I would like to know if there is any possibility to delete missing brew items from the mac if there are not in the Brewfile anymore ?

Thanks for the work !

Linux support

Not an active Linux user, so uncertain of all that's involved here. It will likely require accounting for various package managers and system update tools in different distributions. There's also Linuxbrew, but not sure how popular that is or worth using over something like Nix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.