97 lines
2.3 KiB
Bash
Executable file
97 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
BREW_PREFIX="/usr/local/bin/"
|
|
BREW_LIST_DIR="$HOME/.local/bin/.brew_lists"
|
|
CASK_LIST_DIR="$HOME/.local/bin/.brew_lists"
|
|
BREW_LIST="$BREW_LIST_DIR/brew_list.txt"
|
|
CASK_LIST="$CASK_LIST_DIR/cask_list.txt"
|
|
|
|
# Function to check if the lists are different
|
|
are_lists_different() {
|
|
diff -q "$1" "$2" &> /dev/null
|
|
}
|
|
|
|
# Function to update the brew and cask lists
|
|
update_lists() {
|
|
echo "Updating brew list..."
|
|
"$BREW_PREFIX"brew list > "$BREW_LIST.new"
|
|
chmod 664 "$BREW_LIST.new"
|
|
|
|
echo "Updating cask list..."
|
|
"$BREW_PREFIX"brew list --cask > "$CASK_LIST.new"
|
|
chmod 664 "$CASK_LIST.new"
|
|
}
|
|
|
|
# Function to install Homebrew and packages
|
|
install_packages() {
|
|
# ... (unchanged)
|
|
}
|
|
|
|
# Function to save lists to specified directories
|
|
save_lists() {
|
|
echo "Saving updated lists to specified directories..."
|
|
|
|
mv "$BREW_LIST.new" "$BREW_LIST"
|
|
mv "$CASK_LIST.new" "$CASK_LIST"
|
|
|
|
echo "Lists saved successfully."
|
|
}
|
|
|
|
# Function to commit changes to Git
|
|
commit_to_git() {
|
|
current_dir=$PWD
|
|
cd $HOME/.local/bin || exit
|
|
git pull
|
|
git add "$BREW_LIST" "$CASK_LIST"
|
|
git commit -m "Update brew lists"
|
|
git push origin main
|
|
cd "$current_dir" || exit
|
|
}
|
|
|
|
# Check command-line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--install)
|
|
install_packages
|
|
exit 0
|
|
;;
|
|
--save-brew-dir)
|
|
shift
|
|
"$BREW_PREFIX"brew autoupdate start
|
|
;;
|
|
--save-cask-dir)
|
|
shift
|
|
CASK_LIST_DIR="$1"
|
|
;;
|
|
*)
|
|
echo "Invalid argument: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# Check if the lists directories exist, if not, create them
|
|
if [ ! -d "$BREW_LIST_DIR" ]; then
|
|
mkdir "$BREW_LIST_DIR"
|
|
fi
|
|
|
|
if [ ! -d "$CASK_LIST_DIR" ]; then
|
|
mkdir "$CASK_LIST_DIR"
|
|
fi
|
|
|
|
# Update the lists
|
|
update_lists
|
|
|
|
# Check if the lists have changed
|
|
if are_lists_different "$BREW_LIST.new" "$BREW_LIST" || are_lists_different "$CASK_LIST.new" "$CASK_LIST"; then
|
|
# Lists have changed, save the updated lists
|
|
save_lists
|
|
|
|
# Commit changes to Git
|
|
commit_to_git
|
|
else
|
|
# Lists are the same, perform a soft shutdown or any other desired action
|
|
echo "Brew lists are the same. Soft shutdown..."
|
|
# Add your soft shutdown logic here
|
|
fi
|