Skip to content

Commit

Permalink
Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gvatsal60 committed Oct 27, 2024
1 parent ab855a4 commit 09ea57e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ jobs:
uses: actions/checkout@v4
- name: Run Test
run: |
zsh update-all.sh || { echo "The script exited with an error."; exit 1; }
set -x # Enable Execution Logs
zsh install.sh || { echo "The script exited with an error."; exit 1; }
echo "The script executed successfully."
ZSHRC_PATH="${HOME}/.zshrc"
source ${ZSHRC_PATH}
UPDATE_ALIAS_SEARCH_STR="curl -fsSL https://raw.githubusercontent.com/andmpel/MacOS-All-In-One-Update-Script/HEAD/update-all.sh | ${SHELL}"
if ! grep -qxF "${UPDATE_ALIAS_SEARCH_STR}" "${ZSHRC_PATH}"; then
echo "Error: Test Failed!!!"
exit 1
fi
echo "TEST PASSED"
37 changes: 30 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@ set -e

readonly FILE_NAME="update-all.sh"
readonly UPDATE_SCRIPT_SOURCE_URL="https://raw.githubusercontent.com/andmpel/MacOS-All-In-One-Update-Script/HEAD/${FILE_NAME}"
readonly UPDATE_ALIAS_SEARCH_STR="alias update='curl -fsSL ${UPDATE_SCRIPT_SOURCE_URL} | zsh'"
readonly UPDATE_ALIAS_SEARCH_STR="curl -fsSL ${UPDATE_SCRIPT_SOURCE_URL} | ${SHELL}"

UPDATE_ALIAS_SOURCE_STR=$(
cat <<EOF
# Alias for Update
${UPDATE_ALIAS_SEARCH_STR}
# System Update
update() {
# Check if curl is available
if ! command -v curl >/dev/null 2>&1; then
echo "Error: curl is required but not installed. Please install curl."
exit 1
fi
readonly TEST_URL="https://www.google.com"
readonly TIMEOUT=1
# Check if the internet is reachable
if ! curl -s --max-time \${TIMEOUT} --head --request GET \${TEST_URL} | grep "200 OK" >/dev/null; then
echo "Internet Disabled!!!"
exit 1
fi
${UPDATE_ALIAS_SEARCH_STR}
}
EOF
)

Expand All @@ -33,7 +50,13 @@ EOF
# Function: println
# Description: Prints each argument on a new line, suppressing any error messages.
println() {
command printf %s\\n "$*" 2>/dev/null
printf "%s\n" "$*" 2>/dev/null
}

# Function: print_err
# Description: Prints each argument as error messages.
print_err() {
printf "%s\n" "$*" >&2
}

# Function: update_rc
Expand All @@ -45,7 +68,7 @@ update_rc() {
_rc="${HOME}/.zshrc"
;;
*)
println >&2 "Error: Unsupported or unrecognized distribution ${ADJUSTED_ID}"
print_err "Error: Unsupported or unrecognized distribution ${ADJUSTED_ID}"
exit 1
;;
esac
Expand Down Expand Up @@ -84,14 +107,14 @@ Darwin)
ADJUSTED_ID="darwin"
;;
*)
println >&2 "Error: Unsupported or unrecognized OS distribution: ${OS}"
print_err "Error: Unsupported or unrecognized OS distribution: ${OS}"
exit 1
;;
esac

# Check if curl is available
if ! command -v curl >/dev/null 2>&1; then
println >&2 "Error: curl is required but not installed. Please install curl."
print_err "Error: curl is required but not installed. Please install curl."
exit 1
fi

Expand Down
37 changes: 21 additions & 16 deletions update-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ update_cargo() {
cargo install "$(cargo install --list | grep -E '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')"
}


update_app_store() {
println "Updating App Store Applications"

Expand All @@ -142,22 +141,28 @@ update_macos() {
}

update_all() {
readonly PING_IP=8.8.8.8
if ping -q -W 1 -c 1 $PING_IP >/dev/null 2>&1; then
update_brew
update_office
update_vscode
update_gem
update_npm
update_yarn
update_pip3
update_cargo
update_app_store
update_macos
else
print_err "Internet Disabled!!!"
exit 1
readonly TEST_URL="https://www.google.com"
readonly TIMEOUT=2

# Check if curl is available
if command -v curl >/dev/null 2>&1; then
# Check if the internet is reachable
if ! curl -s --max-time ${TIMEOUT} --head --request GET ${TEST_URL} | grep "200 OK" >/dev/null; then
print_err "Internet Disabled!!!"
exit 1
fi
fi

update_brew
update_office
update_vscode
update_gem
update_npm
update_yarn
update_pip3
update_cargo
update_app_store
update_macos
}

# COMMENT OUT IF SOURCING
Expand Down

0 comments on commit 09ea57e

Please sign in to comment.