fix: improve installer compatibility and docs
This commit is contained in:
parent
1ed542c21d
commit
f90d9a49a7
2 changed files with 55 additions and 13 deletions
|
|
@ -76,12 +76,6 @@ Open `http://localhost:5230` and start writing!
|
||||||
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh
|
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
To install a specific version:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh -s -- --version <version>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Try the Live Demo
|
### Try the Live Demo
|
||||||
|
|
||||||
Don't want to install yet? Try our [live demo](https://demo.usememos.com/) first!
|
Don't want to install yet? Try our [live demo](https://demo.usememos.com/) first!
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,20 @@ BIN_NAME="memos"
|
||||||
VERSION="${MEMOS_VERSION:-}"
|
VERSION="${MEMOS_VERSION:-}"
|
||||||
INSTALL_DIR="${MEMOS_INSTALL_DIR:-}"
|
INSTALL_DIR="${MEMOS_INSTALL_DIR:-}"
|
||||||
SKIP_CHECKSUM="${MEMOS_SKIP_CHECKSUM:-0}"
|
SKIP_CHECKSUM="${MEMOS_SKIP_CHECKSUM:-0}"
|
||||||
|
QUIET="${MEMOS_INSTALL_QUIET:-0}"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
Install Memos from GitHub Releases.
|
Install Memos from GitHub Releases.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
install.sh [--version <version>] [--install-dir <dir>] [--skip-checksum]
|
install.sh [--version <version>] [--install-dir <dir>] [--repo <owner/name>] [--skip-checksum]
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
MEMOS_VERSION Version to install without the leading "v". Defaults to latest release.
|
MEMOS_VERSION Version to install. Accepts "0.28.1" or "v0.28.1". Defaults to latest release.
|
||||||
MEMOS_INSTALL_DIR Directory to install the binary into.
|
MEMOS_INSTALL_DIR Directory to install the binary into.
|
||||||
MEMOS_SKIP_CHECKSUM Set to 1 to skip checksum verification.
|
MEMOS_SKIP_CHECKSUM Set to 1 to skip checksum verification.
|
||||||
|
MEMOS_INSTALL_QUIET Set to 1 to reduce log output.
|
||||||
REPO GitHub repository in owner/name form. Defaults to usememos/memos.
|
REPO GitHub repository in owner/name form. Defaults to usememos/memos.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
@ -28,6 +30,9 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
|
if [ "$QUIET" = "1" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
printf '%s\n' "$*"
|
printf '%s\n' "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,12 +46,22 @@ need_cmd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve_latest_version() {
|
resolve_latest_version() {
|
||||||
latest_url="$(curl -fsSL -o /dev/null -w '%{url_effective}' "https://github.com/${REPO}/releases/latest")"
|
latest_tag="$(
|
||||||
latest_tag="${latest_url##*/}"
|
curl -fsSL \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
"https://api.github.com/repos/${REPO}/releases/latest" | awk -F'"' '/"tag_name":/ { print $4; exit }'
|
||||||
|
)"
|
||||||
[ -n "$latest_tag" ] || fail "failed to resolve latest release tag"
|
[ -n "$latest_tag" ] || fail "failed to resolve latest release tag"
|
||||||
printf '%s\n' "${latest_tag#v}"
|
printf '%s\n' "${latest_tag#v}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalize_version() {
|
||||||
|
version="$1"
|
||||||
|
version="${version#v}"
|
||||||
|
[ -n "$version" ] || fail "version cannot be empty"
|
||||||
|
printf '%s\n' "$version"
|
||||||
|
}
|
||||||
|
|
||||||
detect_os() {
|
detect_os() {
|
||||||
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||||
case "$os" in
|
case "$os" in
|
||||||
|
|
@ -102,7 +117,21 @@ resolve_install_dir() {
|
||||||
download() {
|
download() {
|
||||||
src="$1"
|
src="$1"
|
||||||
dest="$2"
|
dest="$2"
|
||||||
curl -fsSL "$src" -o "$dest"
|
if ! curl -fsSL "$src" -o "$dest"; then
|
||||||
|
fail "failed to download ${src}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
download_optional() {
|
||||||
|
src="$1"
|
||||||
|
dest="$2"
|
||||||
|
|
||||||
|
if curl -fsSL "$src" -o "$dest" 2>/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$dest"
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
verify_checksum() {
|
verify_checksum() {
|
||||||
|
|
@ -114,6 +143,11 @@ verify_checksum() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$checksum_path" ]; then
|
||||||
|
log "Warning: checksum file not found for this release; skipping verification"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
archive_name="$(basename "$archive_path")"
|
archive_name="$(basename "$archive_path")"
|
||||||
expected_line="$(grep " ${archive_name}\$" "$checksum_path" || true)"
|
expected_line="$(grep " ${archive_name}\$" "$checksum_path" || true)"
|
||||||
[ -n "$expected_line" ] || fail "checksum entry not found for ${archive_name}"
|
[ -n "$expected_line" ] || fail "checksum entry not found for ${archive_name}"
|
||||||
|
|
@ -176,10 +210,19 @@ parse_args() {
|
||||||
INSTALL_DIR="$2"
|
INSTALL_DIR="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--repo)
|
||||||
|
[ "$#" -ge 2 ] || fail "missing value for --repo"
|
||||||
|
REPO="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--skip-checksum)
|
--skip-checksum)
|
||||||
SKIP_CHECKSUM="1"
|
SKIP_CHECKSUM="1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--quiet)
|
||||||
|
QUIET="1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
|
|
@ -200,6 +243,7 @@ main() {
|
||||||
need_cmd uname
|
need_cmd uname
|
||||||
need_cmd grep
|
need_cmd grep
|
||||||
need_cmd awk
|
need_cmd awk
|
||||||
|
need_cmd mktemp
|
||||||
|
|
||||||
os="$(detect_os)"
|
os="$(detect_os)"
|
||||||
arch="$(detect_arch)"
|
arch="$(detect_arch)"
|
||||||
|
|
@ -207,6 +251,7 @@ main() {
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "$VERSION" ]; then
|
||||||
VERSION="$(resolve_latest_version)"
|
VERSION="$(resolve_latest_version)"
|
||||||
fi
|
fi
|
||||||
|
VERSION="$(normalize_version "$VERSION")"
|
||||||
|
|
||||||
install_dir="$(resolve_install_dir)"
|
install_dir="$(resolve_install_dir)"
|
||||||
tag="v${VERSION}"
|
tag="v${VERSION}"
|
||||||
|
|
@ -230,8 +275,11 @@ main() {
|
||||||
mkdir -p "$extract_dir"
|
mkdir -p "$extract_dir"
|
||||||
|
|
||||||
log "Installing ${BIN_NAME} ${VERSION} for ${os}/${arch}"
|
log "Installing ${BIN_NAME} ${VERSION} for ${os}/${arch}"
|
||||||
|
log "Downloading ${asset_name} from ${REPO}"
|
||||||
download "${base_url}/${asset_name}" "$archive_path"
|
download "${base_url}/${asset_name}" "$archive_path"
|
||||||
download "${base_url}/${checksums_name}" "$checksums_path"
|
if ! download_optional "${base_url}/${checksums_name}" "$checksums_path"; then
|
||||||
|
log "Warning: ${checksums_name} is not published for ${tag}"
|
||||||
|
fi
|
||||||
|
|
||||||
verify_checksum "$archive_path" "$checksums_path"
|
verify_checksum "$archive_path" "$checksums_path"
|
||||||
extract_archive "$archive_path" "$extract_dir"
|
extract_archive "$archive_path" "$extract_dir"
|
||||||
|
|
@ -240,7 +288,7 @@ main() {
|
||||||
install_binary "${extract_dir}/${BIN_NAME}" "$install_dir"
|
install_binary "${extract_dir}/${BIN_NAME}" "$install_dir"
|
||||||
|
|
||||||
log "Installed ${BIN_NAME} to ${install_dir}/${BIN_NAME}"
|
log "Installed ${BIN_NAME} to ${install_dir}/${BIN_NAME}"
|
||||||
if ! command -v "${install_dir}/${BIN_NAME}" >/dev/null 2>&1 && ! printf '%s' ":$PATH:" | grep -q ":${install_dir}:"; then
|
if ! printf '%s' ":$PATH:" | grep -q ":${install_dir}:"; then
|
||||||
log "Add ${install_dir} to your PATH to run ${BIN_NAME} directly"
|
log "Add ${install_dir} to your PATH to run ${BIN_NAME} directly"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue