Skip to content

Commit

Permalink
add uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Aug 28, 2023
1 parent 161dbca commit c60a0c2
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 73 deletions.
3 changes: 0 additions & 3 deletions op.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ shfmt: shfmt -ci -i 2 -d rush setup && echo "PASS"
man: bashly render :mandoc doc
#? Render the man pages

man-link: for file in doc/*.1; do sudo ln -sf "$(realpath "$file")" /usr/share/man/man1/; done
#? Symlink all man pages

version: \
sed -i "s/$(rush --version)/$1/g" README.md src/bashly.yml && \
bashly g && \
Expand Down
158 changes: 121 additions & 37 deletions setup
Original file line number Diff line number Diff line change
@@ -1,39 +1,123 @@
#!/usr/bin/env bash

# Figure out if we need sudo or not
sudo=''
if [[ $EUID -ne 0 ]]; then
sudo='sudo'
fi

# Download script from Github
echo "=== Saving executable to /usr/local/bin/rush"
curl_command="curl -s https://raw.githubusercontent.com/DannyBen/rush-cli/master/rush > /usr/local/bin/rush"
$sudo bash -c "$curl_command"
$sudo chmod a+x /usr/local/bin/rush

# Install completions
if [[ -d "/usr/share/bash-completion/completions" ]]; then
compdir="/usr/share/bash-completion/completions"
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then
compdir="/usr/local/etc/bash_completion.d"
else
compdir=''
fi

if [[ -n $compdir ]]; then
echo "=== Installing autocompletions to $compdir"
echo "eval \"\$(rush completions)\"" | $sudo tee "${compdir}/rush" >/dev/null
else
echo "=== Completion script was not installed"
echo " To install it manually add this to your startup script:"
echo " eval \"\$(rush completions)\""
fi

# Verify
if type rush >/dev/null; then
echo "=== Done. Type 'rush --help' for more info."
else
echo "=== Setup failed."
exit 1
fi
print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
fi
}

red() { print_in_color "\e[31m" "$*"; }
green() { print_in_color "\e[32m" "$*"; }
green_bold() { print_in_color "\e[1;32m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }

section() {
printf "\n=== %s\n" "$(green_bold "$@")"
}

copy() {
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2"
cp "$origin/$1" "$2"
}

sudo_copy() {
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2"
$sudo cp "$origin/$1" "$2"
}

copy_executable() {
sudo_copy "$1" "/usr/local/bin/"
$sudo chmod a+x "/usr/local/bin/$1"
}

copy_man() {
if [[ ! -d "/usr/local/share/man/man1/" ]]; then return; fi

for file in "$1"/*.1; do
sudo_copy "$file" "/usr/local/share/man/man1/"
done

if command_exist makewhatis; then
$sudo makewhatis /usr/local/man
fi
}

install_completions() {
cmd="$1"
dir="$2"

if [[ -d "/usr/share/bash-completion/completions" ]]; then
compdir="/usr/share/bash-completion/completions"
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then
compdir="/usr/local/etc/bash_completion.d"
else
compdir=''
fi

if [[ -n $compdir ]]; then
printf "copying to %s\n" "$compdir"
echo "eval \"\$($cmd)\"" | $sudo tee "${compdir}/${dir}" >/dev/null
else
printf "%s %s\n" "$(red WARN)" "skipping completions installation, compdir not found"
echo " install it manually by adding this to your startup script:"
echo " eval \"\$($cmd)\""
fi
}

command_exist() {
[[ -x "$(command -v "$1")" ]]
}

need() {
command_exist "$1" || fail "Cannot run $1"
printf "%s found\n" "$(blue " $1")"
}

onerror() {
local exit_status=$?
printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")"
exit $exit_status
}

fail() {
printf "$(red 'ERR') %s\n" "$*"
return 1
}

initialize() {
set -e
trap 'onerror' ERR

# Figure out if we need sudo or not
sudo=''
if [[ $EUID -ne 0 ]]; then
sudo='sudo'
fi

repo="$1"
repo_url="https://github.com/${repo}.git"
origin=$(mktemp -d)
}

section "Initializing"
initialize "DannyBen/rush-cli"

section "Checking for pre-requisites"
need git

section "Cloning $repo"
git clone --depth 1 "$repo_url" "$origin"

section "Copying files"
copy_executable 'rush'
copy_man 'doc'

section "Installing bash completions"
install_completions "rush_completions" "rush"

section "Done"
rush --version
1 change: 1 addition & 0 deletions test/approvals/rush_add_h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rush add

Register a local repository.

This command adds the specified path to the configuration file.

Alias: a
Expand Down
8 changes: 6 additions & 2 deletions test/approvals/rush_clone_h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
rush clone

Clone a GitHub package repository.
This command clones the repository and registers it in the
configuration file.

This command clones the repository and registers it in the configuration file.

Usage:
rush clone GITHUB_USER [PATH] [OPTIONS]
Expand All @@ -17,6 +17,7 @@ rush clone

--name, -n NAME
Name to use in the config file.

Default: GitHub user

--shallow, -w
Expand All @@ -31,11 +32,14 @@ rush clone
Arguments:
GITHUB_USER
Github user.

This user is expected to have a repository named `rush-repo`.

If you need to use a different name, use the `user/repo` syntax.

PATH
Local path to clone the repository into.

Default: ~/rush-repos/<github_user>/<github_repo>

Examples:
Expand Down
17 changes: 9 additions & 8 deletions test/approvals/rush_copy_h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ rush copy - Copy a package between local repositories.
Arguments:
SOURCE_PACKAGE
Source package name.
This can either be the package name without the repository name (in
this case, the default repository will be used) or in the form of
`repo:package`.

This can either be the package name without the repository name (in this
case, the default repository will be used) or in the form of `repo:package`.

TARGET_PACKAGE
Target package name.
This can either be the package name without the repository name (in
this case, the default repository will be used) or in the form of
`repo:package`.
If left empty, the package will be copied with the same name to the
default repository.

This can either be the package name without the repository name (in this
case, the default repository will be used) or in the form of `repo:package`.

If left empty, the package will be copied with the same name to the default
repository.

Examples:
rush copy james:python
Expand Down
1 change: 1 addition & 0 deletions test/approvals/rush_default_h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rush default

Set a default repository.

This command adds (or updates) a repository named `default` to the
configuration file, and copies the path from the provided repo.

Expand Down
6 changes: 3 additions & 3 deletions test/approvals/rush_edit_h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Alias: e
Arguments:
PACKAGE
Package name.
This can either be the package name without the repository name (in
this case, the default repository will be used) or in the form of
`repo:package`.

This can either be the package name without the repository name (in this
case, the default repository will be used) or in the form of `repo:package`.

FILE
File to edit.
Expand Down
17 changes: 10 additions & 7 deletions test/approvals/rush_get_h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
rush get

Install a package.

This command runs the main script in the package directory.

This is the default command, which means that running `rush package` is
the same as running `rush get package`.
This is the default command, which means that running `rush package` is the
same as running `rush get package`.

Alias: g

Expand All @@ -15,11 +16,13 @@ Alias: g
Options:
--clone, -c
Clone the repository if it is not found locally.
This flag will look for a GitHub user with the same name as the
repository, and attempt to clone their rush-repo repository.

This flag will look for a GitHub user with the same name as the repository,
and attempt to clone their rush-repo repository.

--force, -f
Force installation.

This may mean different things in different packages.

--verbose, -v
Expand All @@ -31,9 +34,9 @@ Alias: g
Arguments:
PACKAGE
Package name.
This can either be the package name without the repository name (in
this case, the default repository will be used) or in the form of
`repo:package`.

This can either be the package name without the repository name (in this
case, the default repository will be used) or in the form of `repo:package`.

Examples:
rush ruby
Expand Down
1 change: 1 addition & 0 deletions test/approvals/rush_help
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ rush - Personal package manager.
Environment Variables:
RUSH_CONFIG
Location of the rush config file.

Default: ~/rush.ini
7 changes: 4 additions & 3 deletions test/approvals/rush_info_h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rush info

Show information about a package.

This command shows the info file from the package directory.

Alias: i
Expand All @@ -16,9 +17,9 @@ Alias: i
Arguments:
PACKAGE
Package name.
This can either be the package name without the repository name (in
this case, the default repository will be used) or in the form of
`repo:package`.

This can either be the package name without the repository name (in this
case, the default repository will be used) or in the form of `repo:package`.

Examples:
rush info ruby
Expand Down
7 changes: 5 additions & 2 deletions test/approvals/rush_list_h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ Alias: l
Arguments:
REPO_OR_PACKAGE
Repository name or package name.

Leave blank to show all packages in all repositories.

Provide a repository name to show only packages in this repository.
Provide a package name (may be in the form of `repo:package`) to
show nested packages.

Provide a package name (may be in the form of `repo:package`) to show nested
packages.

Examples:
rush list
Expand Down
1 change: 1 addition & 0 deletions test/approvals/rush_remove_h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rush remove

Unregister a local repository.

This command removes the specified path to the configuration file.

Alias: r
Expand Down
6 changes: 3 additions & 3 deletions test/approvals/rush_show_h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ rush show - Show package files.
Arguments:
PACKAGE
Package name.
This can either be the package name without the repository name (in
this case, the default repository will be used) or in the form of
`repo:package`.

This can either be the package name without the repository name (in this
case, the default repository will be used) or in the form of `repo:package`.

FILE
File to show (show all if not specified).
9 changes: 7 additions & 2 deletions test/approvals/rush_snatch_h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
rush snatch

Install a package from a remote repo.

This command is a shortcut to running clone followed by get.
It will clone the repository to a temporary directory and run the main
package script.

It will clone the repository to a temporary directory and run the main package
script.

Usage:
rush snatch GITHUB_USER PACKAGE [OPTIONS]
Expand All @@ -12,6 +14,7 @@ rush snatch
Options:
--force, -f
Force installation.

This may mean different things in different packages.

--verbose, -v
Expand All @@ -23,7 +26,9 @@ rush snatch
Arguments:
GITHUB_USER
Github user.

This user is expected to have a repository named `rush-repo`.

If you need to use a different name, use the `user/repo` syntax.

PACKAGE
Expand Down
Loading

0 comments on commit c60a0c2

Please sign in to comment.