-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): Add installation script (#2569)
## What ❔ Add installation script Readme visualization: https://github.com/matter-labs/zksync-era/blob/matias-zkup/zk_toolbox/zkup/README.md --------- Co-authored-by: Danil <[email protected]> Co-authored-by: Yury Akudovich <[email protected]>
- Loading branch information
1 parent
2a7d566
commit 009cd97
Showing
3 changed files
with
368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# zkup - zk_toolbox Installer | ||
|
||
`zkup` is a script designed to simplify the installation of | ||
[zk_toolbox](https://github.com/matter-labs/zksync-era/tree/main/zk_toolbox). It allows you to install the tool from a | ||
local directory or directly from a GitHub repository. | ||
|
||
## Getting Started | ||
|
||
To install `zkup`, run the following command: | ||
|
||
```bash | ||
curl -L https://raw.githubusercontent.com/matter-labs/zksync-era/main/zk_toolbox/zkup/install | bash | ||
``` | ||
|
||
After installing `zkup`, you can use it to install `zk_toolbox` with: | ||
|
||
```bash | ||
zkup | ||
``` | ||
|
||
## Usage | ||
|
||
The `zkup` script provides various options for installing `zk_toolbox`: | ||
|
||
### Options | ||
|
||
- `-p, --path <path>` | ||
Specify a local path to install `zk_toolbox` from. This option is ignored if `--repo` is provided. | ||
|
||
- `-r, --repo <repo>` | ||
GitHub repository to install from (e.g., "matter-labs/zksync-era"). Defaults to "matter-labs/zksync-era". | ||
|
||
- `-b, --branch <branch>` | ||
Git branch to use when installing from a repository. Ignored if `--commit` or `--version` is provided. | ||
|
||
- `-c, --commit <commit>` | ||
Git commit hash to use when installing from a repository. Ignored if `--branch` or `--version` is provided. | ||
|
||
- `-v, --version <version>` | ||
Git tag to use when installing from a repository. Ignored if `--branch` or `--commit` is provided. | ||
|
||
- `--skip-zk-supervisor` | ||
Skip the installation of the `zk_supervisor` binary. | ||
|
||
### Local Installation | ||
|
||
If you provide a local path using the `-p` or `--path` option, `zkup` will install `zk_toolbox` from that directory. | ||
Note that repository-specific arguments (`--repo`, `--branch`, `--commit`, `--version`) will be ignored in this case to | ||
preserve git state. | ||
|
||
### Repository Installation | ||
|
||
By default, `zkup` installs `zk_toolbox` from the "matter-labs/zksync-era" GitHub repository. You can specify a | ||
different repository, branch, commit, or version using the respective options. If multiple arguments are provided, | ||
`zkup` will prioritize them as follows: | ||
|
||
- `--version` | ||
- `--commit` | ||
- `--branch` | ||
|
||
### Examples | ||
|
||
**Install from a GitHub repository with a specific version:** | ||
|
||
```bash | ||
zkup --repo matter-labs/zksync-era --version 0.1.1 | ||
``` | ||
|
||
**Install from a local path, skipping `zk_supervisor`:** | ||
|
||
```bash | ||
zkup --path /path/to/local/zk_toolbox --skip-zk-supervisor | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
BASE_DIR=${XDG_CONFIG_HOME:-$HOME} | ||
ZKT_DIR=${ZKT_DIR:-"$BASE_DIR/.zkt"} | ||
ZKT_BIN_DIR="$ZKT_DIR/bin" | ||
|
||
BIN_URL="https://raw.githubusercontent.com/matter-labs/zksync-era/main/zk_toolbox/zkup/zkup" | ||
BIN_PATH="$ZKT_BIN_DIR/zkup" | ||
|
||
mkdir -p "$ZKT_BIN_DIR" | ||
curl -sSfL "$BIN_URL" -o "$BIN_PATH" | ||
chmod +x "$BIN_PATH" | ||
|
||
if [[ ":$PATH:" == *":${ZKT_BIN_DIR}:"* ]]; then | ||
echo "zkup: found ${ZKT_BIN_DIR} in PATH" | ||
exit 0 | ||
fi | ||
|
||
case $SHELL in | ||
*/zsh) | ||
PROFILE="${ZDOTDIR-"$HOME"}/.zshenv" | ||
;; | ||
*/bash) | ||
PROFILE="$HOME/.bashrc" | ||
;; | ||
*/fish) | ||
PROFILE="$HOME/.config/fish/config.fish" | ||
;; | ||
*/ash) | ||
PROFILE="$HOME/.profile" | ||
;; | ||
*) | ||
echo "zkup: could not detect shell, manually add ${ZKT_BIN_DIR} to your PATH." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
if [[ ! -f "$PROFILE" ]]; then | ||
echo "zkup: Profile file $PROFILE does not exist, creating it." | ||
touch "$PROFILE" | ||
fi | ||
|
||
if [[ "$SHELL" == *"/fish"* ]]; then | ||
echo -e "\n# Added by zkup\nfish_add_path -a $ZKT_BIN_DIR" >>"$PROFILE" | ||
echo "zkup: Added $ZKT_BIN_DIR to PATH in $PROFILE using fish_add_path." | ||
else | ||
echo -e "\n# Added by zkup\nexport PATH=\"\$PATH:$ZKT_BIN_DIR\"" >>"$PROFILE" | ||
echo "zkup: Added $ZKT_BIN_DIR to PATH in $PROFILE." | ||
fi | ||
|
||
echo | ||
echo "Added zkup to PATH." | ||
echo "Run 'source $PROFILE' or start a new terminal session to use zkup." | ||
echo "Then run 'zkup' to install ZK Toolbox." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
BASE_DIR=${XDG_CONFIG_HOME:-$HOME} | ||
ZKT_DIR=${ZKT_DIR:-"$BASE_DIR/.zkt"} | ||
ZKT_BIN_DIR="$ZKT_DIR/bin" | ||
|
||
ZKUP_SKIP_ZK_SUPERVISOR=0 | ||
ZKUP_ALIAS=0 | ||
|
||
BINS=(zk_inception zk_supervisor) | ||
|
||
main() { | ||
parse_args "$@" | ||
|
||
zktoolbox_banner | ||
|
||
check_prerequisites | ||
mkdir -p "$ZKT_BIN_DIR" | ||
|
||
if [ -n "$ZKUP_PATH" ]; then | ||
install_local | ||
else | ||
install_from_repo | ||
fi | ||
|
||
zktoolbox_banner | ||
|
||
for bin in "${BINS[@]}"; do | ||
success "Installed $bin to $ZKT_BIN_DIR/$bin" | ||
done | ||
|
||
if [ $ZKUP_ALIAS -eq 1 ]; then | ||
create_alias | ||
fi | ||
} | ||
|
||
PREREQUISITES=(cargo git) | ||
|
||
check_prerequisites() { | ||
say "Checking prerequisites" | ||
|
||
failed_prerequisites=() | ||
for prerequisite in "${PREREQUISITES[@]}"; do | ||
if ! check_prerequisite "$prerequisite"; then | ||
failed_prerequisites+=("$prerequisite") | ||
fi | ||
done | ||
if [ ${#failed_prerequisites[@]} -gt 0 ]; then | ||
err "The following prerequisites are missing: ${failed_prerequisites[*]}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_prerequisite() { | ||
command -v "$1" &>/dev/null | ||
} | ||
|
||
parse_args() { | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
--) | ||
shift | ||
break | ||
;; | ||
|
||
-p | --path) | ||
shift | ||
ZKUP_PATH=$1 | ||
;; | ||
-r | --repo) | ||
shift | ||
ZKUP_REPO=$1 | ||
;; | ||
-b | --branch) | ||
shift | ||
ZKUP_BRANCH=$1 | ||
;; | ||
-c | --commit) | ||
shift | ||
ZKUP_COMMIT=$1 | ||
;; | ||
-v | --version) | ||
shift | ||
ZKUP_VERSION=$1 | ||
;; | ||
--skip-zk-supervisor) ZKUP_SKIP_ZK_SUPERVISOR=1 ;; | ||
-a | --alias) ZKUP_ALIAS=1 ;; | ||
-h | --help) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
err "Unknown argument: $1" | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
} | ||
|
||
usage() { | ||
cat <<EOF | ||
zkup - A tool for managing zk_toolbox installation. | ||
Usage: $(basename "$0") [OPTIONS] | ||
Options: | ||
-p, --path <path> Specify a local path to install zk_toolbox from. Ignored if --repo is provided. | ||
-r, --repo <repo> GitHub repository to install from (e.g., "matter-labs/zksync-era"). Defaults to "matter-labs/zksync-era". | ||
-b, --branch <branch> Git branch to use when installing from a repository. Ignored if --commit or --version is provided. | ||
-c, --commit <commit> Git commit hash to use when installing from a repository. Ignored if --branch or --version is provided. | ||
-v, --version <version> Git tag to use when installing from a repository. Ignored if --branch or --commit is provided. | ||
-a, --alias Create aliases zki and zks for zk_inception and zk_supervisor binaries. | ||
--skip-zk-supervisor Skip installation of the zk_supervisor binary. | ||
-h, --help Show this help message and exit. | ||
Examples: | ||
$(basename "$0") --repo matter-labs/zksync-era --version 0.1.1 | ||
$(basename "$0") --path /path/to/local/zk_toolbox --skip-zk-supervisor | ||
EOF | ||
} | ||
|
||
install_local() { | ||
if [ ! -d "$ZKUP_PATH/zk_toolbox" ]; then | ||
err "Path $ZKUP_PATH does not contain zk_toolbox" | ||
exit 1 | ||
fi | ||
|
||
if [ -n "$ZKUP_BRANCH" ] || [ -n "$ZKUP_COMMIT" ] || [ -n "$ZKUP_VERSION" ] || [ -n "$ZKUP_REPO" ]; then | ||
warn "Ignoring --repo, --branch, --commit and --version arguments when installing from local path" | ||
fi | ||
|
||
say "Installing zk_toolbox from $ZKUP_PATH" | ||
ensure cd "$ZKUP_PATH"/zk_toolbox | ||
|
||
if [ $ZKUP_SKIP_ZK_SUPERVISOR -eq 1 ]; then | ||
BINS=(zk_inception) | ||
fi | ||
|
||
for bin in "${BINS[@]}"; do | ||
say "Installing $bin" | ||
ensure cargo install --root $ZKT_DIR --path ./crates/$bin --force | ||
done | ||
} | ||
|
||
install_from_repo() { | ||
if [ -n "$ZKUP_PATH" ]; then | ||
warn "Ignoring --path argument when installing from repository" | ||
fi | ||
|
||
ZKUP_REPO=${ZKUP_REPO:-"matter-labs/zksync-era"} | ||
|
||
say "Installing zk_toolbox from $ZKUP_REPO" | ||
|
||
if [ $ZKUP_SKIP_ZK_SUPERVISOR -eq 1 ]; then | ||
BINS=(zk_inception) | ||
fi | ||
|
||
if [ -n "$ZKUP_VERSION" ]; then | ||
if [ -n "$ZKUP_COMMIT" ] || [ -n "$ZKUP_BRANCH" ]; then | ||
warn "Ignoring --commit and --branch arguments when installing by version" | ||
fi | ||
ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --tag "zk_toolbox-v$ZKUP_VERSION" --locked "${BINS[@]}" --force | ||
elif [ -n "$ZKUP_COMMIT" ]; then | ||
if [ -n "$ZKUP_BRANCH" ]; then | ||
warn "Ignoring --branch argument when installing by commit" | ||
fi | ||
ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --rev "$ZKUP_COMMIT" --locked "${BINS[@]}" --force | ||
elif [ -n "$ZKUP_BRANCH" ]; then | ||
ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --branch "$ZKUP_BRANCH" --locked "${BINS[@]}" --force | ||
else | ||
ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --locked "${BINS[@]}" --force | ||
fi | ||
} | ||
|
||
create_alias() { | ||
say "Creating alias 'zki' for zk_inception" | ||
ensure ln -sf "$ZKT_BIN_DIR/zk_inception" "$ZKT_BIN_DIR/zki" | ||
|
||
if [ $ZKUP_SKIP_ZK_SUPERVISOR -eq 0 ]; then | ||
say "Creating alias 'zks' for zk_supervisor" | ||
ensure ln -sf "$ZKT_BIN_DIR/zk_supervisor" "$ZKT_BIN_DIR/zks" | ||
fi | ||
} | ||
|
||
ensure() { | ||
if ! "$@"; then | ||
err "command failed: $*" | ||
exit 1 | ||
fi | ||
} | ||
|
||
say() { | ||
local action="${1%% *}" | ||
local rest="${1#"$action" }" | ||
|
||
echo -e "\033[1;32m$action\033[0m $rest" | ||
} | ||
|
||
success() { | ||
echo -e "\033[1;32m$1\033[0m" | ||
} | ||
|
||
warn() { | ||
echo -e "\033[1;33mWARNING: $1\033[0m" | ||
} | ||
|
||
err() { | ||
echo -e "\033[1;31mERROR: $1\033[0m" >&2 | ||
} | ||
|
||
zktoolbox_banner() { | ||
printf ' | ||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
███████╗██╗ ██╗ ████████╗ ██████╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ | ||
╚══███╔╝██║ ██╔╝ ╚══██╔══╝██╔═══██╗██╔═══██╗██║ ██╔══██╗██╔═══██╗╚██╗██╔╝ | ||
███╔╝ █████╔╝ ██║ ██║ ██║██║ ██║██║ ██████╔╝██║ ██║ ╚███╔╝ | ||
███╔╝ ██╔═██╗ ██║ ██║ ██║██║ ██║██║ ██╔══██╗██║ ██║ ██╔██╗ | ||
███████╗██║ ██╗ ██║ ╚██████╔╝╚██████╔╝███████╗██████╔╝╚██████╔╝██╔╝ ██╗ | ||
╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ | ||
A Comprehensive Toolkit for Creating and Managing ZK Stack Chains | ||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
Repo : https://github.com/matter-labs/zksync-era/ | ||
Docs : https://docs.zksync.io/ | ||
Contribute : https://github.com/matter-labs/zksync-era/pulls | ||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
' | ||
} | ||
|
||
main "$@" |