-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomebrew
More file actions
executable file
·120 lines (103 loc) · 2.7 KB
/
homebrew
File metadata and controls
executable file
·120 lines (103 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash -e
DUMP_FILE="${HOME}/.brewfile"
function abort {
echo "$1"
exit 1
}
function show_help {
echo "Usage: $(basename $0) -[bhilrud]" >&2
echo -e "\t-b: Backup current homebrew environment" >&2
echo -e "\t-r: Restore homebrew environment from backup" >&2
echo -e "\t-l: List the currently installed brews/casks" >&2
echo -e "\t-i: Install homebrew" >&2
echo -e "\t-u: Update homebrew and upgrade packages" >&2
echo -e "\t-d: Uninstall homebrew" >&2
echo -e "\t-h: Print this help message" >&2
}
function backup {
brew bundle dump --force --file=$DUMP_FILE
echo "Homebrew backup file created at $DUMP_FILE"
}
function restore {
brew bundle --file=$DUMP_FILE
echo "Homebrew restored from file $DUMP_FILE"
}
function list {
cat $DUMP_FILE
}
function perform_uninstall {
/usr/bin/which -s git || abort "brew install git first!"
test -d /usr/local/.git || abort "brew update first!"
cd `brew --prefix`
git checkout master
git ls-files -z | pbcopy
rm -rf Cellar
bin/brew prune
pbpaste | xargs -0 rm
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
test -d Library/LinkedKegs && rm -r Library/LinkedKegs
rmdir -p bin Library share/man/man1 2> /dev/null
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
rm -rf ~/Library/Logs/Homebrew
rm -rf /Library/Caches/Homebrew
}
function check_uninstall {
read -p "Are you sure you want to uninstall homebrew ("yes")? " REPLY
echo
if [[ $REPLY =~ ^yes$ ]]
then
perform_uninstall
else
echo "Aborting"
fi
}
function install {
# see https://brew.sh/
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
}
function update_upgrade {
# do not abort script if palantir casks are installed and not on VPN
set +e
brew update
set -e
brew upgrade `brew outdated`
}
# show help if no args specified
if [ $# -lt 1 ]
then
show_help && exit
fi
# process args
while [[ "$1" =~ ^- && ! "$1" == "--" ]];
do
case $1 in
-b | --backup )
backup && exit
;;
-r | --restore )
shift
restore $1 && exit
;;
-i | --install )
install && exit
;;
-l | --list )
list && exit
;;
-h | --help )
show_help && exit
;;
-u | --upgrade )
update_upgrade && exit
;;
-d | --delete )
check_uninstall && exit
;;
*)
show_help && abort "Unrecognized option: $1"
;;
esac
shift
done
if [[ "$1" == '--' ]]; then shift; fi