Skip to content

Commit

Permalink
Added skip and notes attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhanu-lab committed Jan 1, 2025
1 parent 7400e89 commit be24093
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
55 changes: 39 additions & 16 deletions config/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
{
"name": "iterm2",
"install_command": "brew install --cask iterm2",
"verify_command": "brew list --cask iterm2"
"verify_command": "brew list --cask iterm2",
"notes": "iTerm2 is a terminal emulator"
},
{
"name": "ghostty",
"install_command": "brew install --cask ghostty",
"verify_command": "brew list --cask ghostty",
"notes": "Ghostty is a terminal emulator"
},
{
"name": "python3",
Expand All @@ -37,7 +44,8 @@
{
"name": "code",
"install_command": "brew install --cask visual-studio-code",
"verify_command": "code --version"
"verify_command": "code --version",
"notes": "Visual Studio Code is a code editor"
},
{
"name": "slack",
Expand All @@ -47,27 +55,33 @@
{
"name": "postman",
"install_command": "brew install --cask postman",
"verify_command": "brew list --cask postman"
"verify_command": "brew list --cask postman",
"notes": "Postman is an API client"
},
{
"name": "jq",
"install_command": "brew install jq",
"verify_command": "jq --version"
"verify_command": "jq --version",
"notes": "jq is a terminal JSON processor"
},
{
"name": "docker",
"install_command": "brew install --cask docker",
"verify_command": "brew list --cask docker"
"verify_command": "brew list --cask docker",
"notes": "Docker Desktop is a containerization platform"
},
{
"name": "rancher",
"install_command": "brew install --cask rancher",
"verify_command": "brew list --cask rancher"
"verify_command": "brew list --cask rancher",
"skip": true,
"notes": "Rancher Desktop is an alternative to Docker Desktop"
},
{
"name": "gh",
"install_command": "brew install gh",
"verify_command": "gh --version"
"verify_command": "gh --version",
"notes": "gh is the GitHub CLI"
},
{
"name": "http",
Expand All @@ -92,7 +106,8 @@
{
"name": "jfrog",
"install_command": "brew install jfrog-cli",
"verify_command": "jfrog --version"
"verify_command": "jfrog --version",
"notes": "jfrog is a CLI for JFrog products"
},
{
"name": "kubectl",
Expand All @@ -102,7 +117,8 @@
{
"name": "arc",
"install_command": "brew install --cask arc",
"verify_command": "brew list --cask arc"
"verify_command": "brew list --cask arc",
"notes": "Arc is a fancy browser"
},
{
"name": "brave",
Expand All @@ -112,7 +128,8 @@
{
"name": "rectangle",
"install_command": "brew install rectangle",
"verify_command": "brew list rectangle"
"verify_command": "brew list rectangle",
"notes": "Rectangle is a window manager"
},
{
"name": "speedtest",
Expand All @@ -122,7 +139,8 @@
{
"name": "bat",
"install_command": "brew install bat",
"verify_command": "bat --version"
"verify_command": "bat --version",
"notes": "bat is a cat clone on steroids"
},
{
"name": "clipper",
Expand All @@ -142,17 +160,20 @@
{
"name": "tree",
"install_command": "brew install tree",
"verify_command": "tree"
"verify_command": "tree",
"notes": "tree is a directory listing program"
},
{
"name": "git-lfs",
"install_command": "brew install git-lfs",
"verify_command": ""
"verify_command": "",
"notes": "git-lfs is a Git extension for large files"
},
{
"name": "lsd",
"install_command": "brew install lsd",
"verify_command": "lsd"
"verify_command": "lsd",
"notes": "lsd is a modern ls command"
},
{
"name": "whatsapp",
Expand All @@ -162,11 +183,13 @@
{
"name": "ffmpeg",
"install_command": "brew install ffmpeg",
"verify_command": "ffmpeg -stats"
"verify_command": "ffmpeg -version",
"notes": "ffmpeg is a multimedia framework"
},
{
"name": "mpv",
"install_command": "brew install mpv",
"verify_command": "mpv --version"
"verify_command": "mpv --version",
"notes": "mpv is a media player"
}
]
49 changes: 24 additions & 25 deletions macsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ install_tools_from_json() {
exit 1
fi

for tool in $tools; do
echo "$tools" | while IFS= read -r tool; do
skip=$(echo "$tool" | jq -r '.skip // false')
if [ "$skip" = true ]; then
echo "Skipping $(echo "$tool" | jq -r '.name')"
continue
fi

name=$(echo "$tool" | jq -r '.name')
install_command=$(echo "$tool" | jq -r '.install_command')
verify_command=$(echo "$tool" | jq -r '.verify_command')
Expand All @@ -156,22 +162,14 @@ install_tools_from_json() {
# Function to check non-available tools
check_non_available_tools() {
non_available_tools=()
non_available_tools=()
while IFS= read -r tool; do
name=$(echo "$tool" | jq -r '.name')
install_command=$(echo "$tool" | jq -r '.install_command')
verify_command=$(echo "$tool" | jq -r '.verify_command')
if [ -z "$name" ] || [ -z "$install_command" ]; then
echo -e "${RED}Error: Missing required fields in JSON file.${NC}"
exit 1
fi
eval "$verify_command" &> /dev/null
if [ $? -ne 0 ] && ! command -v $name &> /dev/null; then
printf "%-20s\n" "$name $install_command"
for tool in "${tools[@]}"; do
IFS=":" read -r tool_name install_command check_command <<< "$tool"
eval "$check_command" &> /dev/null
if [ $? -ne 0 ] && ! command -v $tool_name &> /dev/null; then
printf "%-20s\n" "$tool_name"
non_available_tools+=("$tool")
fi
done <<< "$tools"
echo "non available tools are: ${non_available_tools[@]}"
done
}

# Check and install Homebrew
Expand Down Expand Up @@ -224,7 +222,7 @@ while [[ "$1" != "" ]]; do
fi

# Load tools from tools.json
tools=$(jq -c '.[]?' "$macsetup_dir/tools.json")
tools=$(jq -c '.[]' "$macsetup_dir/tools.json")
if [ $? -ne 0 ]; then
echo -e "${RED}Error: Failed to parse JSON file $macsetup_dir/tools.json.${NC}"
exit 1
Expand All @@ -235,14 +233,17 @@ while [[ "$1" != "" ]]; do
printf "%-20s %s\n" "Tool" "Status"
printf "%-20s %s\n" "--------------------" "--------------------"
echo "$tools" | while IFS= read -r tool; do
name=$(echo "$tool" | jq -r '.name')
install_command=$(echo "$tool" | jq -r '.install_command')
verify_command=$(echo "$tool" | jq -r '.verify_command')
if [ -z "$name" ] || [ -z "$install_command" ]; then
echo -e "${RED}Error: Missing required fields in JSON file.${NC}"
exit 1
skip=$(echo "$tool" | jq -r '.skip // false')
if [ "$skip" = true ]; then
echo "Skipping $(echo "$tool" | jq -r '.name')"
continue
fi
check_and_log "$name" "$verify_command"

tool_name=$(echo "$tool" | jq -r '.name')
echo "Checking tool name [$tool_name]..."
check_command=$(echo "$tool" | jq -r '.verify_command')
echo "Checking [${tool_name}]...[${check_command}]"
check_and_log "${tool_name}" "${check_command}"
done
printf "%-20s %s\n" "--------------------" "--------------------"

Expand All @@ -258,12 +259,10 @@ while [[ "$1" != "" ]]; do
fi
response=$(echo "$response" | tr '[:upper:]' '[:lower:]') # Convert to lowercase
if [[ "$response" =~ ^(yes|y| ) ]] || [[ -z "$response" ]]; then
echo "installing non available toold ${non_available_tools}"
for tool in "${non_available_tools[@]}"; do
tool_name=$(echo "$tool" | jq -r '.name')
install_command=$(echo "$tool" | jq -r '.install_command')
check_command=$(echo "$tool" | jq -r '.verify_command')
echo "installing ${tool_name}"
install_and_log "$tool_name" "$install_command" "$check_command"
done

Expand Down

0 comments on commit be24093

Please sign in to comment.