-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunprovision
executable file
·111 lines (99 loc) · 3.61 KB
/
unprovision
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
#!/bin/bash
# Environment Unprovisioner - Unprovision development environment.
# Copyright (C) 2015-2022 Richard Huang <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Source function library.
. ~/bin/functions
step "Clear caches"
try rm -rf ~/.atom/.apm/*
try find ~/Library/Caches -type f -exec rm -f '{}' \; &>/dev/null
try rm -rf ~/Library/Containers/com.apple.Preview/*
try find ~/Library/Developer/Xcode/Archives -type f -exec rm -f '{}' \; &>/dev/null
try find ~/Library/Developer/Xcode/DerivedData -type f -exec rm -f '{}' \; &>/dev/null
try command -v composer &>/dev/null && composer clearcache 2>/dev/null
if [ -n "$(command -v nuget)" ]; then
output_start
nuget locals all -clear
output_end
fi
next
step "Clear log files"
[ -f $LOCAL/var/log/php-fpm.log ] && try :>$LOCAL/var/log/php-fpm.log
[ -f $LOCAL/var/log/php_errors.log ] && try :>$LOCAL/var/log/php_errors.log
sudo -- bash -c "truncate --size 0 $LOCAL/var/log/nginx/*.log; rm -f /var/log/*.bz2 /var/log/*.gz /var/log/*.old /var/log/*/*.gz; find /Library/Logs/DiagnosticReports -type f -exec rm -f '{}' \; &>/dev/null"
try find ~/Library/Logs -type f -exec rm -f '{}' \; &>/dev/null
try rm -rf ~/.npm/_logs/*
if [ -x "$(command -v mysql)" ]; then
output_start
echo "PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY)" | mysql
output_end
fi
next
# Only when yarn executable exists.
if [ -n "$(command -v yarn)" ]; then
output_start
yarn cache clean
npm uninstall --location=global --no-audit --no-fund yarn
output_end
fi
# Only when npm executable exists.
if [ -n "$(command -v npm)" ]; then
output_start
npm cache verify
npm uninstall --location=global --no-audit --no-fund npm
output_end
fi
# Only when brew executable exists.
if [ -x "$(command -v brew)" ]; then
output_start
# Stop services.
if [ -n "$(brew list --versions mysql)" ]; then
brew services stop mysql
fi
if [ -n "$(brew list --versions php@$PHP_LTS)" ]; then
brew services stop php@$PHP_LTS
fi
if [ -n "$(brew list --versions nginx)" ]; then
sudo brew services stop nginx
fi
if [ -n "$(brew list --versions redis)" ]; then
brew services stop redis
fi
brew list --cask | xargs brew uninstall --force
brew list | xargs brew uninstall --force
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
output_end
fi
step "Clear history files"
try :>~/.lesshst
[ -f ~/.mysql_history ] && try :>~/.mysql_history
[ -f ~/.rediscli_history ] && try :>~/.rediscli_history
next
step "Clear Vim history files"
try find ~/.vim/backup -mindepth 1 ! -name '.gitignore' -exec rm -rf -- {} +
[ -d ~/.vim6 ] && try find ~/.vim6/backup -mindepth 1 ! -name '.gitignore' -exec rm -rf -- {} +
try :>~/.viminfo
next
if [ -d ~/.git ]; then
rm -rf $(git ls-files)
rm -rf ~/.git
fi
# Clear {ba|z}sh history.
step "Clear shell history"
:>~/.bash_history
:>~/.zsh_history
history -c
# history -p on zsh.
next