mirror of
https://github.com/89luca89/distrobox.git
synced 2026-08-17 16:34:42 -05:00
feat(install): make install/uninstall scripts work with v2
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
committed by
Alessio Biancalana
parent
4acf784a7d
commit
a4d2217a57
@@ -18,223 +18,170 @@
|
||||
# along with distrobox; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# POSIX
|
||||
# install.sh — fetch the v2 distrobox binary from GitHub releases for the
|
||||
# detected architecture, then pull man pages, shell completions, and icons
|
||||
# from the source archive at the same tag. To undo, run ./uninstall.
|
||||
#
|
||||
# Intended as a one-liner curl install for users who don't want to build
|
||||
# from source. If you have Go and a checkout, prefer `make install`.
|
||||
|
||||
next=0
|
||||
REPO="89luca89/distrobox"
|
||||
# Bump on every release. Override with --version to install a different tag.
|
||||
VERSION="2.0.0-rc.1"
|
||||
prefix=""
|
||||
no_color=0
|
||||
verbose=0
|
||||
version=1.8.2.5
|
||||
|
||||
# show_help will print usage to stdout.
|
||||
# Arguments:
|
||||
# None
|
||||
# Outputs:
|
||||
# print usage with examples.
|
||||
show_help()
|
||||
{
|
||||
cat << EOF
|
||||
install --prefix /usr/local
|
||||
|
||||
Options:
|
||||
--prefix/-P: base bath where all files will be deployed (default /usr/local if root, ~/.local if not)
|
||||
--next/-N: install latest development version from git, instead of the latest stable release.
|
||||
--no-color: disable color formatting
|
||||
--help/-h: show this message
|
||||
-v: show more verbosity
|
||||
--prefix/-P: base path where files will be deployed
|
||||
(default: /usr/local if root, ~/.local otherwise)
|
||||
--version/-V: release tag to install (default: ${VERSION})
|
||||
--no-color: disable color formatting
|
||||
--help/-h: show this message
|
||||
-v/--verbose: show more verbosity
|
||||
|
||||
Requires: tar plus either curl or wget. Detected architecture must be
|
||||
amd64 or arm64 (matching the published release artefacts).
|
||||
|
||||
To uninstall, use the companion ./uninstall script.
|
||||
EOF
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
while :; do
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
# Call a "show_help" function to display a synopsis, then exit.
|
||||
show_help
|
||||
exit
|
||||
;;
|
||||
--no-color)
|
||||
shift
|
||||
no_color=1
|
||||
exit 0
|
||||
;;
|
||||
-v | --verbose)
|
||||
shift
|
||||
verbose=1
|
||||
;;
|
||||
-N | --next)
|
||||
shift
|
||||
next=1
|
||||
;;
|
||||
--no-color)
|
||||
no_color=1
|
||||
shift
|
||||
;;
|
||||
-P | --prefix)
|
||||
if [ -n "$2" ]; then
|
||||
if [ -n "${2:-}" ]; then
|
||||
prefix="$2"
|
||||
shift
|
||||
shift
|
||||
shift 2
|
||||
else
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*) # Default case: If no more options then break out of the loop.
|
||||
break ;;
|
||||
-V | --version)
|
||||
if [ -n "${2:-}" ]; then
|
||||
VERSION="$2"
|
||||
shift 2
|
||||
else
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
printf >&2 "Error: unknown argument %s\n" "$1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# if we're in not a tty, don't use colors
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
BOLD_GREEN=""
|
||||
BOLD_RED=""
|
||||
CLEAR=""
|
||||
if [ -t 0 ] && [ -t 1 ] && [ "${no_color}" -ne 1 ]; then
|
||||
# we're in a tty, use colors
|
||||
BOLD_GREEN='\033[1;32m'
|
||||
BOLD_RED='\033[1;31m'
|
||||
CLEAR='\033[0m'
|
||||
fi
|
||||
|
||||
if [ -z "${prefix}" ]; then
|
||||
prefix="/usr/local"
|
||||
# in case we're not root, just default to the home directory
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
prefix="${HOME}/.local"
|
||||
fi
|
||||
fi
|
||||
dest_path="${prefix}/bin"
|
||||
man_dest_path="${prefix}/share/man/man1"
|
||||
icon_dest_path="${prefix}/share/icons/hicolor"
|
||||
completion_bash_dest_path="${prefix}/share/bash-completion/completions/"
|
||||
completion_zsh_dest_path="${prefix}/share/zsh/site-functions/"
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
# set verbosity
|
||||
if [ "${verbose}" -ne 0 ]; then
|
||||
set -o xtrace
|
||||
fi
|
||||
|
||||
# get current dir
|
||||
curr_dir=$(dirname "$0")
|
||||
cd "${curr_dir}" || exit 1
|
||||
if [ -z "${prefix}" ]; then
|
||||
prefix="/usr/local"
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
prefix="${HOME}/.local"
|
||||
fi
|
||||
fi
|
||||
|
||||
# if files are available, install files in dest directory
|
||||
# else download targz and uncompress it
|
||||
if [ -e "${curr_dir}/distrobox-enter" ]; then
|
||||
if ! install -d "${dest_path}" "${man_dest_path}" "${completion_bash_dest_path}" \
|
||||
"${completion_zsh_dest_path}" "${icon_dest_path}/scalable/apps"; then
|
||||
printf >&2 "Do you have permission to write to %s?\n" "${prefix}"
|
||||
exit 1
|
||||
fi
|
||||
for file in distrobox*; do
|
||||
if ! install -m 0755 "${file}" "${dest_path}"; then
|
||||
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ -e "man" ]; then
|
||||
for file in man/man1/*; do
|
||||
install -m 0644 "${file}" "${man_dest_path}"
|
||||
done
|
||||
fi
|
||||
if [ -e "completions" ]; then
|
||||
for file in completions/bash/*; do
|
||||
install -m 0644 "${file}" "${completion_bash_dest_path}"
|
||||
done
|
||||
fi
|
||||
if [ -e "completions" ]; then
|
||||
for file in completions/zsh/*; do
|
||||
install -m 0644 "${file}" "${completion_zsh_dest_path}"
|
||||
done
|
||||
fi
|
||||
if [ -e icons/terminal-distrobox-icon.svg ]; then
|
||||
install -m 0644 icons/terminal-distrobox-icon.svg "${icon_dest_path}/scalable/apps"
|
||||
for sz in 16 22 24 32 36 48 64 72 96 128 256; do
|
||||
install -d "${icon_dest_path}/${sz}x${sz}/apps"
|
||||
install -m 0644 icons/hicolor/"${sz}x${sz}"/apps/terminal-distrobox-icon.png \
|
||||
"${icon_dest_path}/${sz}x${sz}/apps"
|
||||
done
|
||||
fi
|
||||
bindir="${prefix}/bin"
|
||||
mandir="${prefix}/share/man/man1"
|
||||
bashdir="${prefix}/share/bash-completion/completions"
|
||||
zshdir="${prefix}/share/zsh/site-functions"
|
||||
icondir="${prefix}/share/icons/hicolor"
|
||||
|
||||
icon_sizes="16 22 24 32 36 48 64 72 96 128 256"
|
||||
|
||||
if command -v curl > /dev/null 2>&1; then
|
||||
download="curl -sLfo"
|
||||
elif command -v wget > /dev/null 2>&1; then
|
||||
download="wget -qO"
|
||||
else
|
||||
printf >&2 "%b Checking dependencies...\n%b" "${BOLD_GREEN}" "${CLEAR}"
|
||||
# check that we have base dependencies
|
||||
if ! {
|
||||
command -v curl > /dev/null || command -v wget > /dev/null
|
||||
} || ! command -v tar > /dev/null; then
|
||||
printf >&2 "Online install depends on tar and either curl or wget\n"
|
||||
printf >&2 "Ensure you have all dependencies installed.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v curl > /dev/null 2>&1; then
|
||||
download="curl -sLo"
|
||||
elif command -v wget > /dev/null 2>&1; then
|
||||
download="wget -qO"
|
||||
fi
|
||||
|
||||
printf >&2 "%b Downloading...\n%b" "${BOLD_RED}" "${CLEAR}"
|
||||
if [ "${next}" -eq 0 ]; then
|
||||
release_ver="89luca89/distrobox/archive/refs/tags/${version}.tar.gz"
|
||||
release_name=$(basename "${release_ver}")
|
||||
else
|
||||
release_ver="89luca89/distrobox/archive/refs/heads/main.tar.gz"
|
||||
release_name="main"
|
||||
fi
|
||||
# go in tmp
|
||||
tmp_dir="$(mktemp -d)"
|
||||
cd "${tmp_dir}"
|
||||
# download our target
|
||||
${download} "${release_name}" "https://github.com/${release_ver}"
|
||||
# uncompress
|
||||
printf >&2 "%b Unpacking...\n%b" "${BOLD_RED}" "${CLEAR}"
|
||||
if [ "${verbose}" -ne 0 ]; then
|
||||
tar xvf "${release_name}"
|
||||
else
|
||||
tar xf "${release_name}"
|
||||
fi
|
||||
# deploy our files
|
||||
if ! install -d "${dest_path}" "${man_dest_path}" "${completion_bash_dest_path}" \
|
||||
"${completion_zsh_dest_path}" "${icon_dest_path}/scalable/apps"; then
|
||||
printf >&2 "Do you have permission to write to %s?\n" "${prefix}"
|
||||
exit 1
|
||||
fi
|
||||
for file in "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/distrobox*; do
|
||||
if ! install -m 0755 "${file}" "${dest_path}"; then
|
||||
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ -e "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')/man/" ]; then
|
||||
for file in "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/man/man1/*; do
|
||||
install -m 0644 "${file}" "${man_dest_path}"
|
||||
done
|
||||
fi
|
||||
if [ -e "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')/completions/bash/" ]; then
|
||||
for file in "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/completions/bash/*; do
|
||||
install -m 0644 "${file}" "${completion_bash_dest_path}"
|
||||
done
|
||||
fi
|
||||
if [ -e "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')/completions/zsh/" ]; then
|
||||
for file in "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/completions/zsh/*; do
|
||||
install -m 0644 "${file}" "${completion_zsh_dest_path}"
|
||||
done
|
||||
fi
|
||||
if [ -e "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/icons/terminal-distrobox-icon.svg ]; then
|
||||
install -m 0644 "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')"/icons/terminal-distrobox-icon.svg \
|
||||
"${icon_dest_path}/scalable/apps"
|
||||
for sz in 16 22 24 32 36 48 64 72 96 128 256; do
|
||||
install -d "${icon_dest_path}/${sz}x${sz}/apps"
|
||||
install -m 0644 "distrobox-$(echo "${release_name}" | sed 's/.tar.gz//g')/icons/hicolor/${sz}x${sz}/apps/terminal-distrobox-icon.png" \
|
||||
"${icon_dest_path}/${sz}x${sz}/apps"
|
||||
done
|
||||
fi
|
||||
|
||||
# securely delete unneeded files
|
||||
cd
|
||||
if [ -n "${tmp_dir}" ] && [ -e "${tmp_dir}" ]; then
|
||||
rm -rf "${tmp_dir}"
|
||||
fi
|
||||
printf >&2 "Error: need either curl or wget on PATH\n"
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v tar > /dev/null 2>&1; then
|
||||
printf >&2 "Error: need tar on PATH\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ ! -w "${dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${dest_path}" && exit 1
|
||||
[ ! -w "${man_dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${man_dest_path}" && exit 1
|
||||
case "$(uname -m)" in
|
||||
x86_64 | amd64) arch="amd64" ;;
|
||||
aarch64 | arm64) arch="arm64" ;;
|
||||
*)
|
||||
printf >&2 "Error: unsupported architecture %s (release artefacts are linux-amd64 and linux-arm64)\n" "$(uname -m)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
printf >&2 "%b Installation successful!\n%b" "${BOLD_GREEN}" "${CLEAR}"
|
||||
printf >&2 "%b Shell scripts are located in %b%s\n%b" "${CLEAR}" "${BOLD_RED}" "${dest_path}" "${CLEAR}"
|
||||
printf >&2 "%b Manpages are located in %b%s\n%b" "${CLEAR}" "${BOLD_RED}" "${man_dest_path}" "${CLEAR}"
|
||||
printf >&2 "%b Installing distrobox %s for linux-%s into %s%b\n" \
|
||||
"${BOLD_GREEN}" "${VERSION}" "${arch}" "${prefix}" "${CLEAR}"
|
||||
|
||||
if ! echo "${PATH}" | grep -q "${dest_path}"; then
|
||||
printf >&2 "%b Be sure that %b%s%b is in your %b\$PATH%b environment variable to be able to use distrobox without specifying the full path.\n%s" "${CLEAR}" "${BOLD_RED}" "${dest_path}" "${CLEAR}" "${BOLD_RED}" "${CLEAR}" "${CLEAR}"
|
||||
tmp="$(mktemp -d)"
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -rf '${tmp}'" EXIT
|
||||
cd "${tmp}"
|
||||
|
||||
printf >&2 "%b Downloading binary...%b\n" "${BOLD_RED}" "${CLEAR}"
|
||||
# shellcheck disable=SC2086
|
||||
${download} distrobox "https://github.com/${REPO}/releases/download/${VERSION}/distrobox-linux-${arch}"
|
||||
|
||||
printf >&2 "%b Downloading man pages, completions, and icons...%b\n" "${BOLD_RED}" "${CLEAR}"
|
||||
# shellcheck disable=SC2086
|
||||
${download} src.tar.gz "https://github.com/${REPO}/archive/refs/tags/${VERSION}.tar.gz"
|
||||
mkdir -p src
|
||||
tar -xzf src.tar.gz -C src --strip-components=1
|
||||
|
||||
if ! install -d "${bindir}" "${mandir}" "${bashdir}" "${zshdir}"; then
|
||||
printf >&2 "Do you have permission to write to %s?\n" "${prefix}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install -m 0755 distrobox "${bindir}/distrobox"
|
||||
install -m 0644 src/man/man1/*.1 "${mandir}/"
|
||||
install -m 0644 src/completions/bash/distrobox "${bashdir}/distrobox"
|
||||
install -m 0644 src/completions/zsh/_distrobox "${zshdir}/_distrobox"
|
||||
|
||||
install -d "${icondir}/scalable/apps"
|
||||
install -m 0644 src/icons/terminal-distrobox-icon.svg "${icondir}/scalable/apps/"
|
||||
for sz in ${icon_sizes}; do
|
||||
install -d "${icondir}/${sz}x${sz}/apps"
|
||||
install -m 0644 "src/icons/hicolor/${sz}x${sz}/apps/terminal-distrobox-icon.png" \
|
||||
"${icondir}/${sz}x${sz}/apps/"
|
||||
done
|
||||
|
||||
printf >&2 "%b Installation successful!%b\n" "${BOLD_GREEN}" "${CLEAR}"
|
||||
printf >&2 "%b distrobox is at %s%b\n" "${CLEAR}" "${bindir}/distrobox" "${CLEAR}"
|
||||
if ! echo "${PATH}" | grep -q "${bindir}"; then
|
||||
printf >&2 "%b Note:%b add %s to your \$PATH\n" "${BOLD_RED}" "${CLEAR}" "${bindir}"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# This file is part of the distrobox project: https://github.com/89luca89/distrobox
|
||||
#
|
||||
# Copyright (C) 2021 distrobox contributors
|
||||
#
|
||||
# distrobox is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 3
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# distrobox is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with distrobox; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# POSIX
|
||||
# uninstall.sh — remove distrobox (v2) plus any leftover v1 split-script
|
||||
# artefacts from the given prefix. The prefix must match the one used at
|
||||
# install time (default: /usr/local for root, ~/.local otherwise).
|
||||
|
||||
prefix=""
|
||||
no_color=0
|
||||
verbose=0
|
||||
|
||||
show_help()
|
||||
{
|
||||
cat << EOF
|
||||
uninstall --prefix /usr/local
|
||||
|
||||
Options:
|
||||
--prefix/-P: base path where distrobox was installed
|
||||
(default: /usr/local if root, ~/.local otherwise)
|
||||
--no-color: disable color formatting
|
||||
--help/-h: show this message
|
||||
-v/--verbose: show more verbosity
|
||||
EOF
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-h | --help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
-v | --verbose)
|
||||
verbose=1
|
||||
shift
|
||||
;;
|
||||
--no-color)
|
||||
no_color=1
|
||||
shift
|
||||
;;
|
||||
-P | --prefix)
|
||||
if [ -n "${2:-}" ]; then
|
||||
prefix="$2"
|
||||
shift 2
|
||||
else
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
printf >&2 "Error: unknown argument %s\n" "$1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
BOLD_GREEN=""
|
||||
CLEAR=""
|
||||
if [ -t 0 ] && [ -t 1 ] && [ "${no_color}" -ne 1 ]; then
|
||||
BOLD_GREEN='\033[1;32m'
|
||||
CLEAR='\033[0m'
|
||||
fi
|
||||
if [ "${verbose}" -ne 0 ]; then
|
||||
set -o xtrace
|
||||
fi
|
||||
|
||||
if [ -z "${prefix}" ]; then
|
||||
prefix="/usr/local"
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
prefix="${HOME}/.local"
|
||||
fi
|
||||
fi
|
||||
|
||||
bindir="${prefix}/bin"
|
||||
mandir="${prefix}/share/man/man1"
|
||||
bashdir="${prefix}/share/bash-completion/completions"
|
||||
zshdir="${prefix}/share/zsh/site-functions"
|
||||
icondir="${prefix}/share/icons/hicolor"
|
||||
|
||||
icon_sizes="16 22 24 32 36 48 64 72 96 128 256"
|
||||
|
||||
rm -f "${bindir}/distrobox"
|
||||
# v1 installed split shell scripts (distrobox-create, distrobox-enter, …,
|
||||
# plus the in-container distrobox-init/export/host-exec) at ${bindir}.
|
||||
# v2 ships none of those at ${bindir}, so this glob only catches v1 leftovers.
|
||||
rm -f "${bindir}"/distrobox-*
|
||||
rm -f "${mandir}/distrobox.1" "${mandir}"/distrobox-*.1
|
||||
rm -f "${bashdir}/distrobox"
|
||||
rm -f "${zshdir}/_distrobox"
|
||||
rm -f "${icondir}/scalable/apps/terminal-distrobox-icon.svg"
|
||||
for sz in ${icon_sizes}; do
|
||||
rm -f "${icondir}/${sz}x${sz}/apps/terminal-distrobox-icon.png"
|
||||
done
|
||||
|
||||
printf >&2 "%b Uninstalled distrobox from %s%b\n" "${BOLD_GREEN}" "${prefix}" "${CLEAR}"
|
||||
Reference in New Issue
Block a user