-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·208 lines (176 loc) · 4.85 KB
/
setup.sh
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env zsh
# Working environment: macOS/ArchLinux
set -x
FILES=(
.gitignore
.zshrc
.tmux.conf
.ideavimrc
)
CONFIG_FILES=(
nvim
git
tmux
raycast
wezterm
pycodestyle
starship.toml
stylua.toml
direnv
zed
)
CUSTOM_FILES=(
#"ssh/config .ssh/config"
"git/config .gitconfig"
#"logseq .logseq"
)
WORKING_DIR=$(pwd)
HOME_DIR="$HOME"
UNAME_LINUX="Linux"
UNAME_MACOS="Darwin"
RELEASE_ARCH="Arch Linux"
RELEASE_UBUNTU="Ubuntu"
# install golang rustc cargo
# cargo install lsd
RELEASE_DEBIAN="Debian"
RELEASE_MANJARO="Manjaro Linux"
RELEASE_MACOS="macOS"
release_name=$(cat /etc/*release| egrep '^NAME=' | sed -E 's/.*"(.*)"/\1/')
is_brew_installed="$+commands[brew]"
_uname=`uname`
is_linux=0
is_macos=0
if [ $_uname = $UNAME_LINUX ]
then
is_linux=1
fi
if [ $_uname = $UNAME_MACOS ]
then
is_macos=1
fi
function init() {
sudo xcode-select --install
sudo xcodebuild -license accept
k git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0
if [[ $(command -v brew) = "" ]]; then
echo "Installing brew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
brew update
brew install zsh
chsh -s /bin/zsh
ssh-keygen
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >>"$HOME/.zshrc"
source "$HOME/.zshrc"
fi
}
function purge() {
uninstall_oh_my_zsh
brew remove $(brew list --formula)
for i in ${FILE_OR_DIRS[@]}; do
rm -rf $WORKING_DIR/$i $HOME_DIR/$i
done
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
}
function manual_install() {
wget -qO- http://stevenygard.com/download/class-dump-3.5.tar.gz | tar xvz - -C /usr/local/bin && chmod u+x /usr/local/bin/class-dump
wget -O /usr/local/bin/class-dump https://github.com/AloneMonkey/MonkeyDev/raw/master/bin/class-dump && chmod u+x /usr/local/bin/class-dump
pip install --user frida-tools
# mkdir -p $ZSH/custom/plugins/poetry
# poetry completions zsh > $ZSH/custom/plugins/poetry/_poetry
}
function backup() {
if (( $is_brew_installed ))
then
# brew backup
brew tap Homebrew/bundle
brew bundle dump -f
mv Brewfile .Brewfile."$(uname)."$(echo $(hostname) | cut -d '.' -f 1)
fi
if [ $is_linux -eq 1 ] && [ $release_name = $RELEASE_ARCH ]
then
pacman -Qqe > pkglist.txt
fi
}
function recover() {
#softwareupdate --install-rosetta
OS="$(uname)"
# Homebrew
if [ ! $(which brew) ]; then
echo "Installing homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if [ "$OS" = 'Darwin' ]; then
export PATH=/usr/local/bin/:$PATH
xcode-select --install
defaults write -g ApplePressAndHoldEnabled -bool false
elif [ "$OS" = 'Linux' ]; then
export PATH=/home/linuxbrew/.linuxbrew/bin/:$PATH
fi
# antigen
if [ ! -f $HOME/.antigen/antigen.zsh ]; then
mkdir -p $HOME/.antigen/
curl -L git.io/antigen >$HOME/.antigen/antigen.zsh
fi
mkdir -p $HOME/.kube/
mkdir $HOME/.ssh
mkdir $HOME/.config/
# dotfiles
cp ssh/example .ssh/config
echo "Linking files..."
for i in ${FILES[@]}; do
ln -svfn $WORKING_DIR/$i $HOME_DIR/$i
done
echo "Linking config files..."
for i in ${CONFIG_FILES[@]}; do
ln -svfn $WORKING_DIR/$i $HOME_DIR/.config/$i
done
echo 'Linking customized files'
for row in ${CUSTOM_FILES[@]}; do
IFS=' ' read -r from to <<< "$row"
ln -svfn $WORKING_DIR/$from $HOME_DIR/$to
done
# submodules
echo 'Syncing Submodules...'
git submodule init
git submodule update --init --recursive
git submodule foreach --recursive git fetch
git submodule foreach git merge origin master
# brew bundle
if (( $is_brew_installed ))
then
echo "Installing by brew..."
suffix="$OS."$(echo $(hostname) | cut -d '.' -f 1)
mv .Brewfile.$suffix Brewfile
brew bundle -v
mv Brewfile .Brewfile.$suffix
fi
# if it is arch
if [ $is_linux -eq 1 ] && [ $release_name = $RELEASE_ARCH ]
then
sudo pacman -S - < pkglist.txt
elif [ $is_macos -eq 1 ]
then
mkdir -p ~/.1password && ln -s ~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock ~/.1password/agent.sock
fi
# others
git config --global core.excludesfile ~/.config/git/.gitignore
git config --global init.defaultBranch main
$(brew --prefix)/opt/fzf/install
}
function post_recover() {
mkdir -p ~/.1password && ln -s /Users/d0zingcat/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock /Users/d0zingcat/.1password/agent.sock
}
option=$1
case $option in
"")
recover
;;
uninstall)
uninstall
;;
*)
backup
;;
esac
exit 0