parent
1ae03fe8e1
commit
17dd64d89d
7 changed files with 441 additions and 171 deletions
|
|
@ -58,6 +58,9 @@ A browser window will open with `out.svg` and live-reload on changes to `in.d2`.
|
|||
|
||||
## Install
|
||||
|
||||
For more detailed installation docs with examples for if you do not wish to use the
|
||||
install script see [./doc/INSTALL.md](./doc/INSTALL.md).
|
||||
|
||||
### Install script
|
||||
|
||||
The recommended way to install is to run our install script, which will figure out the
|
||||
|
|
@ -92,7 +95,7 @@ curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall
|
|||
Alternatively, you can install from source:
|
||||
|
||||
```sh
|
||||
go install oss.terrastruct.com/d2
|
||||
go install oss.terrastruct.com/d2/cmd/d2@latest
|
||||
```
|
||||
|
||||
## D2 as a library
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ usage: $arg0 [--dry-run] [--version vX.X.X] [--edge] [--method detect] [--prefix
|
|||
[--tala latest] [--force] [--uninstall]
|
||||
|
||||
install.sh automates the installation of D2 onto your system. It currently only supports
|
||||
the installation of standalone releases from GitHub. If you pass --edge, it will clone the
|
||||
source, build a release and install from it.
|
||||
the installation of standalone releases from GitHub and via Homebrew on macOS. See the
|
||||
docs for --detect below for more information
|
||||
|
||||
If you pass --edge, it will clone the source, build a release and install from it.
|
||||
--edge is incompatible with --tala and currently unimplemented.
|
||||
|
||||
Flags:
|
||||
|
||||
|
|
@ -29,6 +32,8 @@ Flags:
|
|||
|
||||
--version vX.X.X
|
||||
Pass to have install.sh install the given version instead of the latest version.
|
||||
warn: The version may not be obeyed with package manager installations. Use
|
||||
--method=standalone to enforce the version.
|
||||
|
||||
--edge
|
||||
Pass to build and install D2 from source. This will still use --method if set to detect
|
||||
|
|
@ -36,14 +41,15 @@ Flags:
|
|||
if an unsupported package manager is used. To install from source like a dev would,
|
||||
use go install oss.terrastruct.com/d2
|
||||
note: currently unimplemented.
|
||||
warn: incompatible with --tala as TALA is closed source.
|
||||
|
||||
--method [detect | standalone]
|
||||
--method [detect | standalone | homebrew ]
|
||||
Pass to control the method by which to install. Right now we only support standalone
|
||||
releases from GitHub but later we'll add support for brew, rpm, deb and more.
|
||||
note: currently unimplemented.
|
||||
|
||||
- detect is currently unimplemented but would use your OS's package manager
|
||||
automatically.
|
||||
- detect will use your OS's package manager automatically.
|
||||
So far it only detects macOS and automatically uses homebrew.
|
||||
- homebrew uses https://brew.sh/ which is a macOS and Linux package manager.
|
||||
- standalone installs a standalone release archive into the unix hierarchy path
|
||||
specified by --prefix which defaults to /usr/local
|
||||
Ensure /usr/local/bin is in your \$PATH to use it.
|
||||
|
|
@ -51,16 +57,19 @@ Flags:
|
|||
--prefix /usr/local
|
||||
Controls the unix hierarchy path into which standalone releases are installed.
|
||||
Defaults to /usr/local. You may also want to use ~/.local to avoid needing sudo.
|
||||
Remember that whatever you use, you must have the bin directory of your prefix
|
||||
path in \$PATH to execute the d2 binary. For example, if my prefix directory is
|
||||
We use ~/.local by default on arm64 macOS machines as SIP now disables access to
|
||||
/usr/local. Remember that whatever you use, you must have the bin directory of your
|
||||
prefix path in \$PATH to execute the d2 binary. For example, if my prefix directory is
|
||||
/usr/local then my \$PATH must contain /usr/local/bin.
|
||||
|
||||
--tala [latest]
|
||||
Install Terrastruct's closed source TALA for improved layouts.
|
||||
See https://github.com/terrastruct/TALA
|
||||
See https://github.com/terrastruct/tala
|
||||
It optionally takes an argument of the TALA version to install.
|
||||
Installation obeys all other flags, just like the installation of d2. For example,
|
||||
the d2plugin-tala binary will be installed into /usr/local/bin/d2plugin-tala
|
||||
warn: The version may not be obeyed with package manager installations. Use
|
||||
--method=standalone to enforce the version.
|
||||
|
||||
--force:
|
||||
Force installation over the existing version even if they match. It will attempt a
|
||||
|
|
@ -85,7 +94,6 @@ EOF
|
|||
}
|
||||
|
||||
main() {
|
||||
METHOD=standalone
|
||||
while flag_parse "$@"; do
|
||||
case "$FLAG" in
|
||||
h|help)
|
||||
|
|
@ -113,8 +121,6 @@ main() {
|
|||
method)
|
||||
flag_nonemptyarg && shift "$FLAGSHIFT"
|
||||
METHOD=$FLAGARG
|
||||
echoerr "$FLAGRAW is currently unimplemented"
|
||||
return 1
|
||||
;;
|
||||
prefix)
|
||||
flag_nonemptyarg && shift "$FLAGSHIFT"
|
||||
|
|
@ -149,49 +155,75 @@ main() {
|
|||
PREFIX=${PREFIX:-/usr/local}
|
||||
CACHE_DIR=$(cache_dir)
|
||||
mkdir -p "$CACHE_DIR"
|
||||
METHOD=${METHOD:-detect}
|
||||
INSTALL_DIR=$PREFIX/lib/d2
|
||||
|
||||
case $METHOD in
|
||||
detect)
|
||||
case "$OS" in
|
||||
macos)
|
||||
log "detected macOS, using homebrew for (un)installation"
|
||||
METHOD=homebrew
|
||||
;;
|
||||
*)
|
||||
warn "unrecognized OS $OS, falling back to --method=standalone"
|
||||
METHOD=standalone
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
standalone) ;;
|
||||
homebrew) ;;
|
||||
*)
|
||||
echoerr "unknown (un)installation method $METHOD"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "${UNINSTALL-}" ]; then
|
||||
uninstall
|
||||
return 0
|
||||
else
|
||||
install
|
||||
fi
|
||||
|
||||
VERSION=${VERSION:-latest}
|
||||
if [ "$VERSION" = latest ]; then
|
||||
header "fetching latest release info"
|
||||
fetch_release_info
|
||||
fi
|
||||
|
||||
install
|
||||
}
|
||||
|
||||
install() {
|
||||
install_d2
|
||||
if [ -n "${TALA-}" ]; then
|
||||
# Run in subshell to avoid overwriting VERSION.
|
||||
TALA_VERSION="$( install_tala && echo "$VERSION" )"
|
||||
fi
|
||||
case $METHOD in
|
||||
standalone)
|
||||
install_d2_standalone
|
||||
if [ -n "${TALA-}" ]; then
|
||||
# Run in subshell to avoid overwriting VERSION.
|
||||
TALA_VERSION="$( RELEASE_INFO= install_tala_standalone && echo "$VERSION" )"
|
||||
fi
|
||||
;;
|
||||
homebrew)
|
||||
install_d2_brew
|
||||
if [ -n "${TALA-}" ]; then install_tala_brew; fi
|
||||
;;
|
||||
esac
|
||||
|
||||
FGCOLOR=2 header success
|
||||
FGCOLOR=2 bigheader 'next steps'
|
||||
case $METHOD in
|
||||
standalone) install_post_standalone ;;
|
||||
homebrew) install_post_brew ;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_post_standalone() {
|
||||
log "d2-$VERSION-$OS-$ARCH has been successfully installed into $PREFIX"
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log "tala-$TALA_VERSION-$OS-$ARCH has been successfully installed into $PREFIX"
|
||||
fi
|
||||
log "Rerun this install script with --uninstall to uninstall"
|
||||
log "Rerun this install script with --uninstall to uninstall."
|
||||
log
|
||||
if ! echo "$PATH" | grep -qF "$PREFIX/bin"; then
|
||||
logcat >&2 <<EOF
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
NEXT STEPS
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
Extend your \$PATH to use d2:
|
||||
export PATH=$PREFIX/bin:\$PATH
|
||||
Then run:
|
||||
${TALA+D2_LAYOUT=tala }d2 --help
|
||||
EOF
|
||||
else
|
||||
log " Run ${TALA+D2_LAYOUT=tala }d2 --help for usage."
|
||||
log "Run ${TALA+D2_LAYOUT=tala }d2 --help for usage."
|
||||
fi
|
||||
if ! manpath | grep -qF "$PREFIX/share/man"; then
|
||||
logcat >&2 <<EOF
|
||||
|
|
@ -204,36 +236,61 @@ EOF
|
|||
log " man d2plugin-tala"
|
||||
fi
|
||||
else
|
||||
log " Run man d2 for detailed docs."
|
||||
log "Run man d2 for detailed docs."
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log " Run man d2plugin-tala for detailed docs."
|
||||
log "Run man d2plugin-tala for detailed TALA docs."
|
||||
fi
|
||||
fi
|
||||
logcat >&2 <<EOF
|
||||
|
||||
Something not working? Please let us know:
|
||||
https://github.com/terrastruct/d2/issues/new
|
||||
https://github.com/terrastruct/d2/issues
|
||||
https://github.com/terrastruct/d2/discussions
|
||||
https://discord.gg/NF6X8K4eDq
|
||||
EOF
|
||||
}
|
||||
|
||||
install_d2() {
|
||||
install_post_brew() {
|
||||
log "d2 has been successfully installed with homebrew."
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log "tala has been successfully installed with homebrew."
|
||||
fi
|
||||
log "Rerun this install script with --uninstall to uninstall."
|
||||
log
|
||||
log "Run ${TALA+D2_LAYOUT=tala }d2 --help for usage."
|
||||
log "Run man d2 for detailed docs."
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log "Run man d2plugin-tala for detailed TALA docs."
|
||||
fi
|
||||
logcat >&2 <<EOF
|
||||
|
||||
Something not working? Please let us know:
|
||||
https://github.com/terrastruct/d2/issues
|
||||
https://github.com/terrastruct/d2/discussions
|
||||
https://discord.gg/NF6X8K4eDq
|
||||
EOF
|
||||
}
|
||||
|
||||
install_d2_standalone() {
|
||||
VERSION=${VERSION:-latest}
|
||||
header "installing d2-$VERSION"
|
||||
|
||||
if [ "$VERSION" = latest ]; then
|
||||
fetch_release_info
|
||||
fi
|
||||
|
||||
if command -v d2 >/dev/null; then
|
||||
INSTALLED_VERSION="$(d2 version)"
|
||||
if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then
|
||||
log "skipping installation as version $VERSION is already installed."
|
||||
log "skipping installation as d2 $VERSION is already installed."
|
||||
return 0
|
||||
fi
|
||||
log "uninstalling $INSTALLED_VERSION to install $VERSION"
|
||||
if ! uninstall_d2; then
|
||||
warn "failed to uninstall $INSTALLED_VERSION"
|
||||
log "uninstalling d2 $INSTALLED_VERSION to install $VERSION"
|
||||
if ! uninstall_d2_standalone; then
|
||||
warn "failed to uninstall d2 $INSTALLED_VERSION"
|
||||
fi
|
||||
fi
|
||||
|
||||
header "installing d2-$VERSION"
|
||||
install_standalone_d2
|
||||
}
|
||||
|
||||
install_standalone_d2() {
|
||||
ARCHIVE="d2-$VERSION-$OS-$ARCH.tar.gz"
|
||||
log "installing standalone release $ARCHIVE from github"
|
||||
|
||||
|
|
@ -252,19 +309,39 @@ install_standalone_d2() {
|
|||
"$sh_c" sh -c "'cd \"$INSTALL_DIR/d2-$VERSION\" && make install PREFIX=\"$PREFIX\"'"
|
||||
}
|
||||
|
||||
install_tala() {
|
||||
REPO="${REPO_TALA:-terrastruct/TALA}"
|
||||
VERSION=$TALA
|
||||
RELEASE_INFO=
|
||||
fetch_release_info
|
||||
header "installing tala-$VERSION"
|
||||
install_standalone_tala
|
||||
install_d2_brew() {
|
||||
header "installing d2 with homebrew"
|
||||
sh_c brew tap terrastruct/d2
|
||||
sh_c brew install d2
|
||||
sh_c brew test d2
|
||||
}
|
||||
|
||||
install_standalone_tala() {
|
||||
install_tala_standalone() {
|
||||
REPO="${REPO_TALA:-terrastruct/tala}"
|
||||
VERSION=$TALA
|
||||
|
||||
header "installing tala-$VERSION"
|
||||
|
||||
if [ "$VERSION" = latest ]; then
|
||||
fetch_release_info
|
||||
fi
|
||||
|
||||
if command -v d2plugin-tala >/dev/null; then
|
||||
INSTALLED_VERSION="$(d2plugin-tala --version)"
|
||||
if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then
|
||||
log "skipping installation as tala $VERSION is already installed."
|
||||
return 0
|
||||
fi
|
||||
log "uninstalling tala $INSTALLED_VERSION to install $VERSION"
|
||||
if ! uninstall_tala_standalone; then
|
||||
warn "failed to uninstall tala $INSTALLED_VERSION"
|
||||
fi
|
||||
fi
|
||||
|
||||
ARCHIVE="tala-$VERSION-$OS-$ARCH.tar.gz"
|
||||
log "installing standalone release $ARCHIVE from github"
|
||||
|
||||
fetch_release_info
|
||||
asset_line=$(sh_c 'cat "$RELEASE_INFO" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1')
|
||||
asset_url=$(sh_c 'sed -n $((asset_line-3))p "$RELEASE_INFO" | sed "s/^.*: \"\(.*\)\",$/\1/g"')
|
||||
|
||||
|
|
@ -280,36 +357,43 @@ install_standalone_tala() {
|
|||
"$sh_c" sh -c "'cd \"$INSTALL_DIR/tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'"
|
||||
}
|
||||
|
||||
install_tala_brew() {
|
||||
header "installing tala with homebrew"
|
||||
sh_c brew tap terrastruct/d2
|
||||
sh_c brew install tala
|
||||
sh_c brew test tala
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
# We uninstall tala first as package managers require that it be uninstalled before
|
||||
# uninstalling d2 as TALA depends on d2.
|
||||
if [ "${TALA-}" ]; then
|
||||
if command -v d2plugin-tala >/dev/null; then
|
||||
INSTALLED_VERSION="$(d2plugin-tala --version)"
|
||||
header "uninstalling tala-$INSTALLED_VERSION"
|
||||
case $METHOD in
|
||||
standalone) uninstall_tala_standalone ;;
|
||||
homebrew) uninstall_tala_brew ;;
|
||||
esac
|
||||
else
|
||||
warn "no version of tala installed"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! command -v d2 >/dev/null; then
|
||||
warn "no version of d2 installed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
INSTALLED_VERSION="$(d2 --version)"
|
||||
if ! uninstall_d2; then
|
||||
echoerr "failed to uninstall $INSTALLED_VERSION"
|
||||
return 1
|
||||
fi
|
||||
if [ "${TALA-}" ]; then
|
||||
if ! command -v d2plugin-tala >/dev/null; then
|
||||
warn "no version of tala installed"
|
||||
return 0
|
||||
fi
|
||||
INSTALLED_VERSION="$(d2plugin-tala --version)"
|
||||
if ! uninstall_tala; then
|
||||
echoerr "failed to uninstall tala $INSTALLED_VERSION"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
uninstall_d2() {
|
||||
header "uninstalling d2-$INSTALLED_VERSION"
|
||||
uninstall_standalone_d2
|
||||
case $METHOD in
|
||||
standalone) uninstall_d2_standalone ;;
|
||||
homebrew) uninstall_d2_brew ;;
|
||||
esac
|
||||
}
|
||||
|
||||
uninstall_standalone_d2() {
|
||||
uninstall_d2_standalone() {
|
||||
log "uninstalling standalone release of d2-$INSTALLED_VERSION"
|
||||
|
||||
if [ ! -e "$INSTALL_DIR/d2-$INSTALLED_VERSION" ]; then
|
||||
|
|
@ -327,12 +411,11 @@ uninstall_standalone_d2() {
|
|||
"$sh_c" rm -rf "$INSTALL_DIR/d2-$INSTALLED_VERSION"
|
||||
}
|
||||
|
||||
uninstall_tala() {
|
||||
header "uninstalling tala-$INSTALLED_VERSION"
|
||||
uninstall_standalone_tala
|
||||
uninstall_d2_brew() {
|
||||
sh_c brew remove d2
|
||||
}
|
||||
|
||||
uninstall_standalone_tala() {
|
||||
uninstall_tala_standalone() {
|
||||
log "uninstalling standalone release tala-$INSTALLED_VERSION"
|
||||
|
||||
if [ ! -e "$INSTALL_DIR/tala-$INSTALLED_VERSION" ]; then
|
||||
|
|
@ -350,6 +433,10 @@ uninstall_standalone_tala() {
|
|||
"$sh_c" rm -rf "$INSTALL_DIR/tala-$INSTALLED_VERSION"
|
||||
}
|
||||
|
||||
uninstall_tala_brew() {
|
||||
sh_c brew remove tala
|
||||
}
|
||||
|
||||
is_prefix_writable() {
|
||||
sh_c "mkdir -p '$INSTALL_DIR' 2>/dev/null" || true
|
||||
# The reason for checking whether $INSTALL_DIR is writable is that on macOS you have
|
||||
|
|
|
|||
|
|
@ -111,12 +111,11 @@ printfp() {(
|
|||
if [ -z "${FGCOLOR-}" ]; then
|
||||
FGCOLOR="$(get_rand_color "$prefix")"
|
||||
fi
|
||||
should_color || true
|
||||
if [ $# -eq 0 ]; then
|
||||
should_color || true
|
||||
printf '%s' $(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")
|
||||
printf '%s' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")"
|
||||
else
|
||||
should_color || true
|
||||
printf '%s: %s\n' $(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix") "$(printf "$@")"
|
||||
printf '%s: %s\n' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")" "$(printf "$@")"
|
||||
fi
|
||||
)}
|
||||
|
||||
|
|
@ -219,6 +218,12 @@ header() {
|
|||
logp "/* $1 */"
|
||||
}
|
||||
|
||||
bigheader() {
|
||||
logp "/**
|
||||
* $1
|
||||
**/"
|
||||
}
|
||||
|
||||
# humanpath replaces all occurrences of " $HOME" with " ~"
|
||||
# and all occurrences of '$HOME' with the literal '$HOME'.
|
||||
humanpath() {
|
||||
|
|
|
|||
2
ci/sub
2
ci/sub
|
|
@ -1 +1 @@
|
|||
Subproject commit 8f9a24045546e76e39175ed148fdadd770c750ba
|
||||
Subproject commit 55e97e5416c5a63737c44d9123441340bc4b210b
|
||||
83
docs/INSTALL.md
Normal file
83
docs/INSTALL.md
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# install
|
||||
|
||||
This file documents how the install.sh script installs d2 and how you can
|
||||
manually install yourself.
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [install.sh](#installsh)
|
||||
- [Standalone](#standalone)
|
||||
- [macOS (Homebrew)](#macos-homebrew)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## install.sh
|
||||
|
||||
```sh
|
||||
# With --dry-run the install script will print the commands it will use
|
||||
# to install without actually installing so you know what it's going to do.
|
||||
curl -fsSL https://d2lang.com/install.sh | sh -s -- --dry-run
|
||||
# If things look good, install for real.
|
||||
curl -fsSL https://d2lang.com/install.sh | sh -s --
|
||||
```
|
||||
|
||||
For help on the terminal run including the supported package managers
|
||||
and detection methods see:
|
||||
|
||||
```sh
|
||||
curl -fsSL https://d2lang.com/install.sh | sh -s -- --help
|
||||
```
|
||||
|
||||
## Standalone
|
||||
|
||||
We publish standalone release archives with every release on github.
|
||||
Download the `.tar.gz` release for your OS/ARCH combination and then run:
|
||||
|
||||
```sh
|
||||
make install
|
||||
```
|
||||
|
||||
Inside the extracted directory to install.
|
||||
|
||||
```sh
|
||||
make uninstall
|
||||
```
|
||||
|
||||
To uninstall. You will be prompted for sudo/su/doas if root permissions
|
||||
are required for installation. You can control the unix hierarchy installation
|
||||
path with `PREFIX=`. For example:
|
||||
|
||||
```
|
||||
# Install under ~/.local.
|
||||
# Binaries will be at ~/.local/bin
|
||||
# And manpages will be under ~/.local/share/man
|
||||
# And supporting data like icons and fonts at ~/.local/share/d2
|
||||
make install PREFIX=$HOME/.local
|
||||
```
|
||||
|
||||
The install script places the standalone release into `$PREFIX/lib/d2/d2-<version>`
|
||||
and we recommend doing the same with manually installed releases so that you
|
||||
know where the release directory is for easy uninstall.
|
||||
|
||||
We have releases with identical process for tala at https://github.com/terrastruct/TALA/releases
|
||||
|
||||
## macOS (Homebrew)
|
||||
|
||||
For macOS you may install as so:
|
||||
|
||||
```sh
|
||||
brew tap terrastruct/d2
|
||||
brew install d2
|
||||
brew test d2
|
||||
```
|
||||
|
||||
For closed source TALA [https://github.com/terrastruct/tala]:
|
||||
|
||||
```sh
|
||||
brew tap terrastruct/d2
|
||||
brew install tala
|
||||
brew test tala
|
||||
```
|
||||
|
||||
You don't have to run the `brew test` command but we recommend it to ensure d2 is
|
||||
functioning correctly after installation.
|
||||
260
install.sh
260
install.sh
|
|
@ -117,12 +117,11 @@ printfp() {(
|
|||
if [ -z "${FGCOLOR-}" ]; then
|
||||
FGCOLOR="$(get_rand_color "$prefix")"
|
||||
fi
|
||||
should_color || true
|
||||
if [ $# -eq 0 ]; then
|
||||
should_color || true
|
||||
printf '%s' $(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")
|
||||
printf '%s' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")"
|
||||
else
|
||||
should_color || true
|
||||
printf '%s: %s\n' $(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix") "$(printf "$@")"
|
||||
printf '%s: %s\n' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")" "$(printf "$@")"
|
||||
fi
|
||||
)}
|
||||
|
||||
|
|
@ -225,6 +224,12 @@ header() {
|
|||
logp "/* $1 */"
|
||||
}
|
||||
|
||||
bigheader() {
|
||||
logp "/**
|
||||
* $1
|
||||
**/"
|
||||
}
|
||||
|
||||
# humanpath replaces all occurrences of " $HOME" with " ~"
|
||||
# and all occurrences of '$HOME' with the literal '$HOME'.
|
||||
humanpath() {
|
||||
|
|
@ -477,8 +482,11 @@ usage: $arg0 [--dry-run] [--version vX.X.X] [--edge] [--method detect] [--prefix
|
|||
[--tala latest] [--force] [--uninstall]
|
||||
|
||||
install.sh automates the installation of D2 onto your system. It currently only supports
|
||||
the installation of standalone releases from GitHub. If you pass --edge, it will clone the
|
||||
source, build a release and install from it.
|
||||
the installation of standalone releases from GitHub and via Homebrew on macOS. See the
|
||||
docs for --detect below for more information
|
||||
|
||||
If you pass --edge, it will clone the source, build a release and install from it.
|
||||
--edge is incompatible with --tala and currently unimplemented.
|
||||
|
||||
Flags:
|
||||
|
||||
|
|
@ -488,6 +496,8 @@ Flags:
|
|||
|
||||
--version vX.X.X
|
||||
Pass to have install.sh install the given version instead of the latest version.
|
||||
warn: The version may not be obeyed with package manager installations. Use
|
||||
--method=standalone to enforce the version.
|
||||
|
||||
--edge
|
||||
Pass to build and install D2 from source. This will still use --method if set to detect
|
||||
|
|
@ -495,14 +505,15 @@ Flags:
|
|||
if an unsupported package manager is used. To install from source like a dev would,
|
||||
use go install oss.terrastruct.com/d2
|
||||
note: currently unimplemented.
|
||||
warn: incompatible with --tala as TALA is closed source.
|
||||
|
||||
--method [detect | standalone]
|
||||
--method [detect | standalone | homebrew ]
|
||||
Pass to control the method by which to install. Right now we only support standalone
|
||||
releases from GitHub but later we'll add support for brew, rpm, deb and more.
|
||||
note: currently unimplemented.
|
||||
|
||||
- detect is currently unimplemented but would use your OS's package manager
|
||||
automatically.
|
||||
- detect will use your OS's package manager automatically.
|
||||
So far it only detects macOS and automatically uses homebrew.
|
||||
- homebrew uses https://brew.sh/ which is a macOS and Linux package manager.
|
||||
- standalone installs a standalone release archive into the unix hierarchy path
|
||||
specified by --prefix which defaults to /usr/local
|
||||
Ensure /usr/local/bin is in your \$PATH to use it.
|
||||
|
|
@ -510,16 +521,19 @@ Flags:
|
|||
--prefix /usr/local
|
||||
Controls the unix hierarchy path into which standalone releases are installed.
|
||||
Defaults to /usr/local. You may also want to use ~/.local to avoid needing sudo.
|
||||
Remember that whatever you use, you must have the bin directory of your prefix
|
||||
path in \$PATH to execute the d2 binary. For example, if my prefix directory is
|
||||
We use ~/.local by default on arm64 macOS machines as SIP now disables access to
|
||||
/usr/local. Remember that whatever you use, you must have the bin directory of your
|
||||
prefix path in \$PATH to execute the d2 binary. For example, if my prefix directory is
|
||||
/usr/local then my \$PATH must contain /usr/local/bin.
|
||||
|
||||
--tala [latest]
|
||||
Install Terrastruct's closed source TALA for improved layouts.
|
||||
See https://github.com/terrastruct/TALA
|
||||
See https://github.com/terrastruct/tala
|
||||
It optionally takes an argument of the TALA version to install.
|
||||
Installation obeys all other flags, just like the installation of d2. For example,
|
||||
the d2plugin-tala binary will be installed into /usr/local/bin/d2plugin-tala
|
||||
warn: The version may not be obeyed with package manager installations. Use
|
||||
--method=standalone to enforce the version.
|
||||
|
||||
--force:
|
||||
Force installation over the existing version even if they match. It will attempt a
|
||||
|
|
@ -544,7 +558,6 @@ EOF
|
|||
}
|
||||
|
||||
main() {
|
||||
METHOD=standalone
|
||||
while flag_parse "$@"; do
|
||||
case "$FLAG" in
|
||||
h|help)
|
||||
|
|
@ -572,8 +585,6 @@ main() {
|
|||
method)
|
||||
flag_nonemptyarg && shift "$FLAGSHIFT"
|
||||
METHOD=$FLAGARG
|
||||
echoerr "$FLAGRAW is currently unimplemented"
|
||||
return 1
|
||||
;;
|
||||
prefix)
|
||||
flag_nonemptyarg && shift "$FLAGSHIFT"
|
||||
|
|
@ -608,49 +619,75 @@ main() {
|
|||
PREFIX=${PREFIX:-/usr/local}
|
||||
CACHE_DIR=$(cache_dir)
|
||||
mkdir -p "$CACHE_DIR"
|
||||
METHOD=${METHOD:-detect}
|
||||
INSTALL_DIR=$PREFIX/lib/d2
|
||||
|
||||
case $METHOD in
|
||||
detect)
|
||||
case "$OS" in
|
||||
macos)
|
||||
log "detected macOS, using homebrew for (un)installation"
|
||||
METHOD=homebrew
|
||||
;;
|
||||
*)
|
||||
warn "unrecognized OS $OS, falling back to --method=standalone"
|
||||
METHOD=standalone
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
standalone) ;;
|
||||
homebrew) ;;
|
||||
*)
|
||||
echoerr "unknown (un)installation method $METHOD"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "${UNINSTALL-}" ]; then
|
||||
uninstall
|
||||
return 0
|
||||
else
|
||||
install
|
||||
fi
|
||||
|
||||
VERSION=${VERSION:-latest}
|
||||
if [ "$VERSION" = latest ]; then
|
||||
header "fetching latest release info"
|
||||
fetch_release_info
|
||||
fi
|
||||
|
||||
install
|
||||
}
|
||||
|
||||
install() {
|
||||
install_d2
|
||||
if [ -n "${TALA-}" ]; then
|
||||
# Run in subshell to avoid overwriting VERSION.
|
||||
TALA_VERSION="$( install_tala && echo "$VERSION" )"
|
||||
fi
|
||||
case $METHOD in
|
||||
standalone)
|
||||
install_d2_standalone
|
||||
if [ -n "${TALA-}" ]; then
|
||||
# Run in subshell to avoid overwriting VERSION.
|
||||
TALA_VERSION="$( RELEASE_INFO= install_tala_standalone && echo "$VERSION" )"
|
||||
fi
|
||||
;;
|
||||
homebrew)
|
||||
install_d2_brew
|
||||
if [ -n "${TALA-}" ]; then install_tala_brew; fi
|
||||
;;
|
||||
esac
|
||||
|
||||
FGCOLOR=2 header success
|
||||
FGCOLOR=2 bigheader 'next steps'
|
||||
case $METHOD in
|
||||
standalone) install_post_standalone ;;
|
||||
homebrew) install_post_brew ;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_post_standalone() {
|
||||
log "d2-$VERSION-$OS-$ARCH has been successfully installed into $PREFIX"
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log "tala-$TALA_VERSION-$OS-$ARCH has been successfully installed into $PREFIX"
|
||||
fi
|
||||
log "Rerun this install script with --uninstall to uninstall"
|
||||
log "Rerun this install script with --uninstall to uninstall."
|
||||
log
|
||||
if ! echo "$PATH" | grep -qF "$PREFIX/bin"; then
|
||||
logcat >&2 <<EOF
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
NEXT STEPS
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
Extend your \$PATH to use d2:
|
||||
export PATH=$PREFIX/bin:\$PATH
|
||||
Then run:
|
||||
${TALA+D2_LAYOUT=tala }d2 --help
|
||||
EOF
|
||||
else
|
||||
log " Run ${TALA+D2_LAYOUT=tala }d2 --help for usage."
|
||||
log "Run ${TALA+D2_LAYOUT=tala }d2 --help for usage."
|
||||
fi
|
||||
if ! manpath | grep -qF "$PREFIX/share/man"; then
|
||||
logcat >&2 <<EOF
|
||||
|
|
@ -663,36 +700,61 @@ EOF
|
|||
log " man d2plugin-tala"
|
||||
fi
|
||||
else
|
||||
log " Run man d2 for detailed docs."
|
||||
log "Run man d2 for detailed docs."
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log " Run man d2plugin-tala for detailed docs."
|
||||
log "Run man d2plugin-tala for detailed TALA docs."
|
||||
fi
|
||||
fi
|
||||
logcat >&2 <<EOF
|
||||
|
||||
Something not working? Please let us know:
|
||||
https://github.com/terrastruct/d2/issues/new
|
||||
https://github.com/terrastruct/d2/issues
|
||||
https://github.com/terrastruct/d2/discussions
|
||||
https://discord.gg/NF6X8K4eDq
|
||||
EOF
|
||||
}
|
||||
|
||||
install_d2() {
|
||||
install_post_brew() {
|
||||
log "d2 has been successfully installed with homebrew."
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log "tala has been successfully installed with homebrew."
|
||||
fi
|
||||
log "Rerun this install script with --uninstall to uninstall."
|
||||
log
|
||||
log "Run ${TALA+D2_LAYOUT=tala }d2 --help for usage."
|
||||
log "Run man d2 for detailed docs."
|
||||
if [ -n "${TALA-}" ]; then
|
||||
log "Run man d2plugin-tala for detailed TALA docs."
|
||||
fi
|
||||
logcat >&2 <<EOF
|
||||
|
||||
Something not working? Please let us know:
|
||||
https://github.com/terrastruct/d2/issues
|
||||
https://github.com/terrastruct/d2/discussions
|
||||
https://discord.gg/NF6X8K4eDq
|
||||
EOF
|
||||
}
|
||||
|
||||
install_d2_standalone() {
|
||||
VERSION=${VERSION:-latest}
|
||||
header "installing d2-$VERSION"
|
||||
|
||||
if [ "$VERSION" = latest ]; then
|
||||
fetch_release_info
|
||||
fi
|
||||
|
||||
if command -v d2 >/dev/null; then
|
||||
INSTALLED_VERSION="$(d2 version)"
|
||||
if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then
|
||||
log "skipping installation as version $VERSION is already installed."
|
||||
log "skipping installation as d2 $VERSION is already installed."
|
||||
return 0
|
||||
fi
|
||||
log "uninstalling $INSTALLED_VERSION to install $VERSION"
|
||||
if ! uninstall_d2; then
|
||||
warn "failed to uninstall $INSTALLED_VERSION"
|
||||
log "uninstalling d2 $INSTALLED_VERSION to install $VERSION"
|
||||
if ! uninstall_d2_standalone; then
|
||||
warn "failed to uninstall d2 $INSTALLED_VERSION"
|
||||
fi
|
||||
fi
|
||||
|
||||
header "installing d2-$VERSION"
|
||||
install_standalone_d2
|
||||
}
|
||||
|
||||
install_standalone_d2() {
|
||||
ARCHIVE="d2-$VERSION-$OS-$ARCH.tar.gz"
|
||||
log "installing standalone release $ARCHIVE from github"
|
||||
|
||||
|
|
@ -711,19 +773,39 @@ install_standalone_d2() {
|
|||
"$sh_c" sh -c "'cd \"$INSTALL_DIR/d2-$VERSION\" && make install PREFIX=\"$PREFIX\"'"
|
||||
}
|
||||
|
||||
install_tala() {
|
||||
REPO="${REPO_TALA:-terrastruct/TALA}"
|
||||
VERSION=$TALA
|
||||
RELEASE_INFO=
|
||||
fetch_release_info
|
||||
header "installing tala-$VERSION"
|
||||
install_standalone_tala
|
||||
install_d2_brew() {
|
||||
header "installing d2 with homebrew"
|
||||
sh_c brew tap terrastruct/d2
|
||||
sh_c brew install d2
|
||||
sh_c brew test d2
|
||||
}
|
||||
|
||||
install_standalone_tala() {
|
||||
install_tala_standalone() {
|
||||
REPO="${REPO_TALA:-terrastruct/tala}"
|
||||
VERSION=$TALA
|
||||
|
||||
header "installing tala-$VERSION"
|
||||
|
||||
if [ "$VERSION" = latest ]; then
|
||||
fetch_release_info
|
||||
fi
|
||||
|
||||
if command -v d2plugin-tala >/dev/null; then
|
||||
INSTALLED_VERSION="$(d2plugin-tala --version)"
|
||||
if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then
|
||||
log "skipping installation as tala $VERSION is already installed."
|
||||
return 0
|
||||
fi
|
||||
log "uninstalling tala $INSTALLED_VERSION to install $VERSION"
|
||||
if ! uninstall_tala_standalone; then
|
||||
warn "failed to uninstall tala $INSTALLED_VERSION"
|
||||
fi
|
||||
fi
|
||||
|
||||
ARCHIVE="tala-$VERSION-$OS-$ARCH.tar.gz"
|
||||
log "installing standalone release $ARCHIVE from github"
|
||||
|
||||
fetch_release_info
|
||||
asset_line=$(sh_c 'cat "$RELEASE_INFO" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1')
|
||||
asset_url=$(sh_c 'sed -n $((asset_line-3))p "$RELEASE_INFO" | sed "s/^.*: \"\(.*\)\",$/\1/g"')
|
||||
|
||||
|
|
@ -739,36 +821,43 @@ install_standalone_tala() {
|
|||
"$sh_c" sh -c "'cd \"$INSTALL_DIR/tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'"
|
||||
}
|
||||
|
||||
install_tala_brew() {
|
||||
header "installing tala with homebrew"
|
||||
sh_c brew tap terrastruct/d2
|
||||
sh_c brew install tala
|
||||
sh_c brew test tala
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
# We uninstall tala first as package managers require that it be uninstalled before
|
||||
# uninstalling d2 as TALA depends on d2.
|
||||
if [ "${TALA-}" ]; then
|
||||
if command -v d2plugin-tala >/dev/null; then
|
||||
INSTALLED_VERSION="$(d2plugin-tala --version)"
|
||||
header "uninstalling tala-$INSTALLED_VERSION"
|
||||
case $METHOD in
|
||||
standalone) uninstall_tala_standalone ;;
|
||||
homebrew) uninstall_tala_brew ;;
|
||||
esac
|
||||
else
|
||||
warn "no version of tala installed"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! command -v d2 >/dev/null; then
|
||||
warn "no version of d2 installed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
INSTALLED_VERSION="$(d2 --version)"
|
||||
if ! uninstall_d2; then
|
||||
echoerr "failed to uninstall $INSTALLED_VERSION"
|
||||
return 1
|
||||
fi
|
||||
if [ "${TALA-}" ]; then
|
||||
if ! command -v d2plugin-tala >/dev/null; then
|
||||
warn "no version of tala installed"
|
||||
return 0
|
||||
fi
|
||||
INSTALLED_VERSION="$(d2plugin-tala --version)"
|
||||
if ! uninstall_tala; then
|
||||
echoerr "failed to uninstall tala $INSTALLED_VERSION"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
uninstall_d2() {
|
||||
header "uninstalling d2-$INSTALLED_VERSION"
|
||||
uninstall_standalone_d2
|
||||
case $METHOD in
|
||||
standalone) uninstall_d2_standalone ;;
|
||||
homebrew) uninstall_d2_brew ;;
|
||||
esac
|
||||
}
|
||||
|
||||
uninstall_standalone_d2() {
|
||||
uninstall_d2_standalone() {
|
||||
log "uninstalling standalone release of d2-$INSTALLED_VERSION"
|
||||
|
||||
if [ ! -e "$INSTALL_DIR/d2-$INSTALLED_VERSION" ]; then
|
||||
|
|
@ -786,12 +875,11 @@ uninstall_standalone_d2() {
|
|||
"$sh_c" rm -rf "$INSTALL_DIR/d2-$INSTALLED_VERSION"
|
||||
}
|
||||
|
||||
uninstall_tala() {
|
||||
header "uninstalling tala-$INSTALLED_VERSION"
|
||||
uninstall_standalone_tala
|
||||
uninstall_d2_brew() {
|
||||
sh_c brew remove d2
|
||||
}
|
||||
|
||||
uninstall_standalone_tala() {
|
||||
uninstall_tala_standalone() {
|
||||
log "uninstalling standalone release tala-$INSTALLED_VERSION"
|
||||
|
||||
if [ ! -e "$INSTALL_DIR/tala-$INSTALLED_VERSION" ]; then
|
||||
|
|
@ -809,6 +897,10 @@ uninstall_standalone_tala() {
|
|||
"$sh_c" rm -rf "$INSTALL_DIR/tala-$INSTALLED_VERSION"
|
||||
}
|
||||
|
||||
uninstall_tala_brew() {
|
||||
sh_c brew remove tala
|
||||
}
|
||||
|
||||
is_prefix_writable() {
|
||||
sh_c "mkdir -p '$INSTALL_DIR' 2>/dev/null" || true
|
||||
# The reason for checking whether $INSTALL_DIR is writable is that on macOS you have
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package version
|
||||
|
||||
// Pre-built binaries will have version set during build time.
|
||||
var Version = "master (built from source)"
|
||||
var Version = "????"
|
||||
|
|
|
|||
Loading…
Reference in a new issue