Skip to content

Commit

Permalink
feature: added catalogue for installation method
Browse files Browse the repository at this point in the history
  • Loading branch information
officialasishkumar committed Nov 30, 2023
1 parent d739e7c commit 71b3fab
Showing 1 changed file with 102 additions and 4 deletions.
106 changes: 102 additions & 4 deletions keploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,98 @@ installKeploy (){
alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v '"$HOME"'/.keploy-config:/root/.keploy-config -v '"$HOME"'/keploy-config:/root/keploy-config --rm ghcr.io/keploy/keploy'
}

# Renders a text based list of options that can be selected by the
# user using up, down and enter keys and returns the chosen option.
#
# Arguments : list of options, maximum of 256
# "opt1" "opt2" ...
# Return value: selected index (0 for opt1, 1 for opt2 ...)
select_option() {
ESC=$(printf "\033")

cursor_blink_on() {
printf "$ESC[?25h"
}

cursor_blink_off() {
printf "$ESC[?25l"
}

cursor_to() {
printf "$ESC[$1;${2:-1}H"
}

print_option() {
printf " $1 "
}

print_selected() {
printf " $ESC[7m $1 $ESC[27m"
}

get_cursor_row() {
IFS=';' read -sdR -p $'\E[6n' ROW COL
echo ${ROW#*[}
}

key_input() {
read -s -n3 key 2>/dev/null >&2
if [ "$key" = "$ESC[A" ]; then
echo up
elif [ "$key" = "$ESC[B" ]; then
echo down
elif [ "$key" = "" ]; then
echo enter
fi
}

options="$1"
set -- $options # Set positional parameters
for opt do
printf "\n"
done

local lastrow
lastrow=$(get_cursor_row)
local startrow
startrow=$((lastrow - $#))

trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
cursor_blink_off

local selected=0
while true; do
local idx=0
for opt; do
cursor_to $((startrow + idx))
if [ "$idx" -eq "$selected" ]; then
print_selected "$opt"
else
print_option "$opt"
fi
idx=$((idx + 1))
done

case $(key_input) in
enter) break;;
up) selected=$((selected - 1))
if [ "$selected" -lt 0 ]; then
selected=$(( $# - 1 ))
fi;;
down) selected=$((selected + 1))
if [ "$selected" -ge $# ]; then
selected=0
fi;;
esac
done

cursor_to "$lastrow"
printf "\n"
cursor_blink_on

return "$selected"
}

ARCH=$(uname -m)

if [ "$IS_CI" = false ]; then
Expand Down Expand Up @@ -139,12 +231,18 @@ installKeploy (){
install_colima_docker
return
elif [ "$OS_NAME" = "Linux" ]; then
echo -n "Do you want to install keploy with Linux or Docker? (linux/docker): "
read user_input
echo -n "Do you want to install keploy with Linux or Docker? (select using arrow keys) "
echo

options="linux docker"

select_option "$options"
choice="$?"

if ! sudo mountpoint -q /sys/kernel/debug; then
sudo mount -t debugfs debugfs /sys/kernel/debug
fi
if [ "$user_input" = "linux" ]; then
if [ "$choice" = "0" ]; then
if [ "$ARCH" = "x86_64" ]; then
install_keploy_amd
elif [ "$ARCH" = "aarch64" ]; then
Expand All @@ -153,7 +251,7 @@ installKeploy (){
echo "Unsupported architecture: $ARCH"
return
fi
elif [ "$user_input" = "docker" ]; then
elif [ "$choice" = "1" ]; then
install_docker
else
echo "Please enter a valid command"
Expand Down

0 comments on commit 71b3fab

Please sign in to comment.