Skip to content

Commit

Permalink
Update BrewautoInstaller.sh
Browse files Browse the repository at this point in the history
Imbedded new GithubDownLoader Function to replace script calls and reduce number of files required to install new Brewauto system to 1.
  • Loading branch information
iAGorynT committed Nov 2, 2024
1 parent d1455dd commit 66aab2c
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions ShellScripts/BrewautoInstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,71 @@ display_message() {
esac
}

# Make User Bin Direcory and Download Shell Scripts
# Function to download a file from GitHub
download_github_file() {
# Check if curl is installed
if ! command -v curl &>/dev/null; then
echo "Error: curl is not installed. Please install curl to use this script."
return 3
fi

# Check if all required arguments are provided
if [ "$#" -ne 4 ]; then
echo "Usage: $0 owner repo branch filepath"
echo "Example: $0 microsoft vscode main README.md"
return 1
fi

local owner=$1
local repo=$2
local branch=$3
local filepath=$4
local github_raw_url="https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${filepath}"
local filename=$(basename "$filepath")

# Check if the file already exists and prompt for overwrite
if [ -f "$filename" ]; then
read "overwrite?File $filename already exists. Overwrite? (y/N): "
if [[ ! "$overwrite" =~ ^[Yy]$ ]]; then
echo "Download canceled."
return 1
fi
fi

# Attempt to download the file
echo "Downloading ${filename} from ${github_raw_url}..."

if curl -L -o "$filename" "$github_raw_url"; then
echo "Successfully downloaded ${filename}"
echo "File saved as: $(pwd)/${filename}"
return 0
else
echo "Error: Failed to download the file from ${github_raw_url}"
return 2
fi
}

# Make User Bin Directory and Download Shell Scripts
mkdir -p "$BIN_FOLDER"
cd "$BIN_FOLDER"

# Run the GitHub download script
GithubDownloader.sh iAGorynT Brew-Autoupdate main bin/Brewautom2.sh
# Download files using the download_github_file function
download_github_file iAGorynT Brew-Autoupdate main bin/Brewautom2.sh
ret_code=$?

# Call the display_message function with the return code
display_message $ret_code
echo

# Run the GitHub download script
GithubDownloader.sh iAGorynT Brew-Autoupdate main bin/BrewitLaunchd.sh
download_github_file iAGorynT Brew-Autoupdate main bin/BrewitLaunchd.sh
ret_code=$?

# Call the display_message function with the return code
display_message $ret_code
echo

# Make User Launchd Direcory and Download Plist Files
# Make User Launchd Directory and Download Plist Files
mkdir -p "$LAUNCHD_FOLDER"
cd "$LAUNCHD_FOLDER"

# Run the GitHub download script
$HOME/bin/GithubDownloader.sh iAGorynT Brew-Autoupdate main Launchd/Launchd.plist
download_github_file iAGorynT Brew-Autoupdate main Launchd/Launchd.plist
ret_code=$?

# Call the display_message function with the return code
display_message $ret_code
echo

Expand Down

0 comments on commit 66aab2c

Please sign in to comment.