Skip to content

Commit

Permalink
add curl to sh install method
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeichlersmith committed Jan 4, 2023
1 parent eadd931 commit 0d4a0be
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 42 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ Want to see what tmux sessions are already created on a specific remote, you can

# INSTALLATION

## curl

If you trust me (or have proofread the install script), you can install smux with a one-liner.

curl -s https://raw.githubusercontent.com/tomeichlersmith/smux/main/install | sh

By default, this installs smux to ~/.local if you are a non-root user.
You can define the install prefix (--prefix dir) and
choose to use the HEAD of the main branch rather
than the last release (--next) both of which are optional.

curl -s https://raw.githubusercontent.com/tomeichlersmith/smux/main/install | \
sh -s -- --prefix dir --next

## git

You can install or update smux by obtaining the source code from the repository https://github.com/tomeichlersmith/smux either by cloning it or by downloading one of the releases and then running the installation command.

cd smux
Expand Down
148 changes: 106 additions & 42 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -27,61 +27,68 @@ set -o nounset
# Outputs:
# print usage with examples.
show_help() {
cat << EOF
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)
--prefix/-p: base bath where all files will be deployed (default /usr/local if root, ~/.local if not)
--devel/-d: symlink to install location rather than copy, helpful for testing during development
ignored if not in the repository
--help/-h: show this message
-v: show more verbosity
--next/-n: install HEAD of main branch rather than last release
--help/-h: show this message
-v: show more verbosity
EOF
}

version=v1.0.0
next=0
verbose=0
devel=0
prefix=""

# Parse arguments
while [ "$#" -gt 0 ]; do
case $1 in
-h | --help)
# Call a "show_help" function to display a synopsis, then exit.
show_help
exit
;;
-v | --verbose)
shift
verbose=1
;;
case $1 in
-h | --help)
# Call a "show_help" function to display a synopsis, then exit.
show_help
exit
;;
-v | --verbose)
shift
verbose=1
;;
-d | --devel)
shift
devel=1
;;
-p | --prefix)
if [ -n "$2" ]; then
prefix="$2"
shift
shift
fi
;;
*) # Default case: If no more options then break out of the loop.
break ;;
esac
-n | --next)
shift
next=1
;;
-p | --prefix)
if [ -n "$2" ]; then
prefix="$2"
shift
shift
fi
;;
*) # Default case: If no more options then break out of the loop.
break ;;
esac
done

# set verbosity
if [ "${verbose}" -ne 0 ]; then
set -o xtrace
set -o xtrace
fi

if [ -z "${prefix}" ]; then
prefix="/usr/local"
# in case we're not root, just default to the home directory
if [ "$(id -u || true)" -ne 0 ]; then
prefix="${HOME}/.local"
fi
prefix="/usr/local"
# in case we're not root, just default to the home directory
if [ "$(id -u || true)" -ne 0 ]; then
prefix="${HOME}/.local"
fi
fi
completion_dest_path="${prefix}/share/bash-completion/completions/"
dest_path="${prefix}/bin"
Expand All @@ -96,29 +103,86 @@ if [ -e "${curr_dir}/smux" ]; then
if [ "${devel}" -ne 0 ]; then
copy="ln -sf -t"
if ! ${copy} "${dest_path}" "${PWD}/smux"; then
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
exit 1
fi
else
copy="install -D -m 0644 -t"
if ! install -D -m 0755 -t "${dest_path}" smux; then
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
exit 1
fi
fi
if [ -e "man" ]; then
if [ -e "man" ]; then
for file in "${PWD}"/man/man1/*; do
${copy} "${man_dest_path}" "${file}"
done
fi
if [ -e "completions" ]; then
${copy} "${man_dest_path}" "${file}"
done
fi
if [ -e "completions" ]; then
for file in "${PWD}"/completions/*; do
${copy} "${completion_dest_path}" "${file}"
done
fi
${copy} "${completion_dest_path}" "${file}"
done
fi
else
printf >&2 "\033[1;31m Not inside code repository, cannot install smux\033[0m"
exit 1
printf >&2 "\033[1;31m Checking dependencies...\n\033[0m"
# 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 "\033[1;31m Downloading...\n\033[0m"
if [ "${next}" -eq 0 ]; then
release_ver="tomeichlersmith/smux/archive/refs/tags/${version}.tar.gz"
release_name=$(echo "${release_ver}" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz$')
else
release_ver="tomeichlersmith/smux/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 "\033[1;31m Unpacking...\n\033[0m"
if [ "${verbose}" -ne 0 ]; then
tar xvf "${release_name}"
else
tar xf "${release_name}"
fi
# enter source
cd "smux-$(echo "${release_name}" | sed 's|.tar.gz||' || true)"

# deploy
copy="install -D -m 0644 -t"
if ! install -D -m 0755 -t "${dest_path}" smux; then
printf >&2 "Do you have permission to write to %s?\n" "${dest_path}"
exit 1
fi
if [ -e "man" ]; then
for file in "${PWD}"/man/man1/*; do
${copy} "${man_dest_path}" "${file}"
done
fi
if [ -e "completions" ]; then
for file in "${PWD}"/completions/*; do
${copy} "${completion_dest_path}" "${file}"
done
fi

# securely delete unneeded files
cd
if [ -n "${tmp_dir}" ] && [ -e "${tmp_dir}" ]; then
rm -rf "${tmp_dir}"
fi
fi

[ ! -w "${dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${dest_path}" && exit 1
Expand Down

0 comments on commit 0d4a0be

Please sign in to comment.