release: Use sudo automatically when installing/uninstalling
This commit is contained in:
parent
5e151c1e0a
commit
54311cbf3d
8 changed files with 88 additions and 15 deletions
|
|
@ -450,13 +450,10 @@ uninstall_tala_brew() {
|
||||||
}
|
}
|
||||||
|
|
||||||
is_prefix_writable() {
|
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
|
# The reason for checking whether $INSTALL_DIR is writable is that on macOS you have
|
||||||
# /usr/local owned by root but you don't need root to write to its subdirectories which
|
# /usr/local owned by root but you don't need root to write to its subdirectories which
|
||||||
# is all we want to do.
|
# is all we want to do.
|
||||||
if [ ! -w "$INSTALL_DIR" ]; then
|
is_writable_dir "$INSTALL_DIR"
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_dir() {
|
cache_dir() {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ sh_c cat >./ci/release/template/scripts/lib.sh <<EOF
|
||||||
#
|
#
|
||||||
# - ./ci/sub/lib/rand.sh
|
# - ./ci/sub/lib/rand.sh
|
||||||
# - ./ci/sub/lib/log.sh
|
# - ./ci/sub/lib/log.sh
|
||||||
|
# - ./ci/sub/lib/release.sh
|
||||||
#
|
#
|
||||||
# Generated by ./ci/release/gen_template_lib.sh.
|
# Generated by ./ci/release/gen_template_lib.sh.
|
||||||
# *************
|
# *************
|
||||||
|
|
@ -25,5 +26,6 @@ EOF
|
||||||
sh_c cat \
|
sh_c cat \
|
||||||
./ci/sub/lib/rand.sh \
|
./ci/sub/lib/rand.sh \
|
||||||
./ci/sub/lib/log.sh \
|
./ci/sub/lib/log.sh \
|
||||||
|
./ci/sub/lib/release.sh \
|
||||||
\| sed "-e'/^\. /d'" \>\>./ci/release/template/scripts/lib.sh
|
\| sed "-e'/^\. /d'" \>\>./ci/release/template/scripts/lib.sh
|
||||||
sh_c chmod -w ./ci/release/template/scripts/lib.sh
|
sh_c chmod -w ./ci/release/template/scripts/lib.sh
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
.POSIX:
|
.POSIX:
|
||||||
.SILENT:
|
.SILENT:
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all:
|
||||||
|
(. ./scripts/lib.sh && echoerr "You must provide a target of install or uninstall for this Makefile")
|
||||||
|
exit 1
|
||||||
|
|
||||||
PREFIX = $(DESTDIR)/usr/local
|
PREFIX = $(DESTDIR)/usr/local
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,15 @@ main() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sh_c mkdir -p "$PREFIX/bin"
|
sh_c="sh_c"
|
||||||
sh_c install ./bin/d2 "$PREFIX/bin/d2"
|
if ! is_writable_dir "$PREFIX/bin"; then
|
||||||
sh_c mkdir -p "$PREFIX/share/man/man1"
|
sh_c="sudo_sh_c"
|
||||||
sh_c install ./man/d2.1 "$PREFIX/share/man/man1"
|
fi
|
||||||
|
|
||||||
|
"$sh_c" mkdir -p "$PREFIX/bin"
|
||||||
|
"$sh_c" install ./bin/d2 "$PREFIX/bin/d2"
|
||||||
|
"$sh_c" mkdir -p "$PREFIX/share/man/man1"
|
||||||
|
"$sh_c" install ./man/d2.1 "$PREFIX/share/man/man1"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#
|
#
|
||||||
# - ./ci/sub/lib/rand.sh
|
# - ./ci/sub/lib/rand.sh
|
||||||
# - ./ci/sub/lib/log.sh
|
# - ./ci/sub/lib/log.sh
|
||||||
|
# - ./ci/sub/lib/release.sh
|
||||||
#
|
#
|
||||||
# Generated by ./ci/release/gen_template_lib.sh.
|
# Generated by ./ci/release/gen_template_lib.sh.
|
||||||
# *************
|
# *************
|
||||||
|
|
@ -298,3 +299,56 @@ capcode() {
|
||||||
code=$?
|
code=$?
|
||||||
set -e
|
set -e
|
||||||
}
|
}
|
||||||
|
#!/bin/sh
|
||||||
|
if [ "${LIB_RELEASE-}" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
LIB_RELEASE=1
|
||||||
|
|
||||||
|
goos() {
|
||||||
|
case $1 in
|
||||||
|
macos) echo darwin ;;
|
||||||
|
*) echo $1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
os() {
|
||||||
|
uname=$(uname)
|
||||||
|
case $uname in
|
||||||
|
Linux) echo linux ;;
|
||||||
|
Darwin) echo macos ;;
|
||||||
|
FreeBSD) echo freebsd ;;
|
||||||
|
*) echo "$uname" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
arch() {
|
||||||
|
uname_m=$(uname -m)
|
||||||
|
case $uname_m in
|
||||||
|
aarch64) echo arm64 ;;
|
||||||
|
x86_64) echo amd64 ;;
|
||||||
|
*) echo "$uname_m" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
gh_repo() {
|
||||||
|
gh repo view --json nameWithOwner --template '{{ .nameWithOwner }}'
|
||||||
|
}
|
||||||
|
|
||||||
|
manpath() {
|
||||||
|
if command -v manpath >/dev/null; then
|
||||||
|
command manpath
|
||||||
|
elif man -w 2>/dev/null; then
|
||||||
|
man -w
|
||||||
|
else
|
||||||
|
echo "${MANPATH-}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_writable_dir() {
|
||||||
|
# The path has to exist for -w to succeed.
|
||||||
|
sh_c "mkdir -p '$1' 2>/dev/null" || true
|
||||||
|
if [ ! -w "$1" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,13 @@ main() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sh_c rm -f "$PREFIX/bin/d2"
|
sh_c="sh_c"
|
||||||
sh_c rm -f "$PREFIX/share/man/man1/d2.1"
|
if ! is_writable_dir "$PREFIX/bin"; then
|
||||||
|
sh_c="sudo_sh_c"
|
||||||
|
fi
|
||||||
|
|
||||||
|
"$sh_c" rm -f "$PREFIX/bin/d2"
|
||||||
|
"$sh_c" rm -f "$PREFIX/share/man/man1/d2.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
||||||
2
ci/sub
2
ci/sub
|
|
@ -1 +1 @@
|
||||||
Subproject commit ea5566075122e826293ef3cf98c5fffcbee99341
|
Subproject commit 70a9ad95ea0ae1de83fa3b7f7d4a160db4853c20
|
||||||
13
install.sh
13
install.sh
|
|
@ -480,6 +480,14 @@ manpath() {
|
||||||
echo "${MANPATH-}"
|
echo "${MANPATH-}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_writable_dir() {
|
||||||
|
# The path has to exist for -w to succeed.
|
||||||
|
sh_c "mkdir -p '$1' 2>/dev/null" || true
|
||||||
|
if [ ! -w "$1" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
|
@ -927,13 +935,10 @@ uninstall_tala_brew() {
|
||||||
}
|
}
|
||||||
|
|
||||||
is_prefix_writable() {
|
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
|
# The reason for checking whether $INSTALL_DIR is writable is that on macOS you have
|
||||||
# /usr/local owned by root but you don't need root to write to its subdirectories which
|
# /usr/local owned by root but you don't need root to write to its subdirectories which
|
||||||
# is all we want to do.
|
# is all we want to do.
|
||||||
if [ ! -w "$INSTALL_DIR" ]; then
|
is_writable_dir "$INSTALL_DIR"
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_dir() {
|
cache_dir() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue