-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,61 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo Installing medusaget... | ||
|
||
# Base directories | ||
BASE_DIR=${XDG_CONFIG_HOME:-$HOME} | ||
MEDUSA_DIR=${MEDUSA_DIR-"$BASE_DIR/.medusa"} | ||
MEDUSA_BIN_DIR="$MEDUSA_DIR/bin" | ||
|
||
# URL for medusaget script | ||
BIN_URL="https://raw.githubusercontent.com/crytic/medusa/master/medusaget/medusaget" | ||
BIN_PATH="$MEDUSA_BIN_DIR/medusaget" | ||
|
||
# Create directories if they don't exist | ||
mkdir -p $MEDUSA_BIN_DIR | ||
|
||
# Download medusaget script | ||
curl -# -L $BIN_URL -o $BIN_PATH | ||
chmod +x $BIN_PATH | ||
|
||
# Detect shell and update profile | ||
case $SHELL in | ||
*/zsh) | ||
PROFILE=${ZDOTDIR-"$HOME"}/.zshenv | ||
PREF_SHELL=zsh | ||
;; | ||
*/bash) | ||
PROFILE=$HOME/.bashrc | ||
PREF_SHELL=bash | ||
;; | ||
*/fish) | ||
PROFILE=$HOME/.config/fish/config.fish | ||
PREF_SHELL=fish | ||
;; | ||
*) | ||
echo "Medusaget: could not detect shell, manually add ${MEDUSA_BIN_DIR} to your PATH." | ||
exit 1 | ||
esac | ||
|
||
# Add medusaget to PATH if not already present | ||
if [[ ":$PATH:" != *":${MEDUSA_BIN_DIR}:"* ]]; then | ||
echo >> $PROFILE && echo "export PATH=\"\$PATH:$MEDUSA_BIN_DIR\"" >> $PROFILE | ||
fi | ||
|
||
echo "Detected your preferred shell is ${PREF_SHELL} and added medusaget to PATH." | ||
echo "Run 'source ${PROFILE}' or start a new terminal session to use medusaget." | ||
echo "Then, simply run 'medusaget' to start using it." | ||
function install_medusaget { | ||
echo "Downloading medusaget..." | ||
curl -# -k -L "$1" -o "$2" | ||
chmod +x "$2" | ||
} | ||
|
||
function configure_shell { | ||
local shell_type="$1" | ||
local bin_path="$2" | ||
|
||
case "$shell_type" in | ||
zsh) | ||
echo "export PATH=\$PATH:$bin_path" >> ~/.zshrc | ||
;; | ||
bash) | ||
echo "export PATH=\$PATH:$bin_path" >> ~/.bashrc | ||
;; | ||
*) | ||
echo "Unknown shell. Manually add to PATH." | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
function check_libusb_macos { | ||
if [[ ! -f /usr/local/opt/libusb/lib/libusb-1.0.0.dylib && ! -f /opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib ]]; then | ||
echo "Warning: libusb not found. You may need to install it manually via Homebrew (brew install libusb)." | ||
fi | ||
} | ||
|
||
function main { | ||
# Configurations | ||
base_dir=${XDG_CONFIG_HOME:-$HOME} | ||
root_dir="$base_dir/.medusa" | ||
bin_dir="$root_dir/bin" | ||
fetch_url="https://raw.githubusercontent.com/zachmdsi/medusa/feat/one-line-install/medusaget/medusaget" | ||
fetch_path="$bin_dir/medusaget" | ||
|
||
# Create dir & Download medusaget | ||
mkdir -p "$bin_dir" | ||
install_medusaget "$fetch_url" "$fetch_path" | ||
|
||
# Shell & PATH setup | ||
case "$SHELL" in | ||
*zsh) sh_type="zsh" ;; | ||
*bash) sh_type="bash" ;; | ||
*) sh_type="unknown" ;; | ||
esac | ||
configure_shell "$sh_type" "$bin_dir" | ||
|
||
# MacOS libusb check | ||
[[ "$OSTYPE" =~ ^darwin ]] && check_libusb_macos | ||
|
||
echo "medusaget is ready. Simply run 'medusaget' to get started." | ||
} | ||
|
||
main "$@" | ||
|