Last active 3 weeks ago

Revision 73489104c91b3d4a0978773d7833f1889423ac6a

backup.sh Raw
1#!/bin/bash
2
3# Color Utilities
4function green() { printf "\033[32m%s\033[0m\n\n" "$1"; }
5function orange() { printf "\033[38;5;208m%s\033[0m\n" "$1"; }
6function red() { printf "\033[91m%s\033[0m\n" "$1"; }
7function blue() { printf "\033[38;5;27m%s\033[0m\n" "$1"; }
8
9# Constants
10BACKUP_DIR="$HOME/backups"
11FILENAME="$BACKUP_DIR/$(date +%d_%m_%Y).tar"
12
13# Create backup directory if it doesn't exist
14function ensure_backup_dir() {
15 if [[ ! -e "$BACKUP_DIR" ]]; then
16 blue "Creating backup directory."
17 mkdir -p "$BACKUP_DIR"
18 fi
19}
20
21# Handle existing backup file
22function check_existing_backup() {
23 if [[ -f "$FILENAME" ]]; then
24 orange "$FILENAME already exists!"
25 read -rp "Do you want to remove the existing backup file? (y/n) : " answer
26 [[ $answer == 'y' ]] && rm "$FILENAME" || exit 1
27 fi
28}
29
30function generate_config_files() {
31 green "Preparing iterm2 & brew config ..."
32
33 local brew_file="$HOME/Brewfile"
34 local iterm2_file="$HOME/iterm.itermexport"
35
36 brew bundle dump --force --file="$brew_file"
37
38 if [[ ! -f "$brew_file" ]]; then
39 orange "$brew_file doesn't exist!"
40 read -rp "Do you want to continue? (y/n): " answer
41 [[ "$answer" == "y" ]] || exit 1
42 fi
43
44 tar -rpf "$FILENAME" "$brew_file"
45
46 if [[ ! -f "$iterm2_file" ]]; then
47 orange "$iterm2_file doesn't exist!"
48 read -rp "Do you want to continue? (y/n): " answer
49 [[ "$answer" == "y" ]] || exit 1
50 fi
51
52 tar -rpf "$FILENAME" "$iterm2_file" && rm "$iterm2_file"
53}
54
55# Backup dotfiles
56function backup_dotfiles() {
57 green "Backing up dotfiles..."
58 find "$HOME"/.* -maxdepth 0 -type f -exec tar -rpf "$FILENAME" {} +
59}
60
61# Exclude large config dirs and create gzipped archive of .config
62function backup_config_gz() {
63 tar -rpf "$FILENAME" "$HOME/.config/git"
64 tar -rpf "$FILENAME" "$HOME/.config/rclone"
65 tar -rpf "$FILENAME" "$HOME/.config/telebit"
66 tar -rpf "$FILENAME" "$HOME/.config/yarn/global/package.json"
67
68 tar -rpf "$FILENAME" "$HOME/.gnupg/*.gpg"
69 tar -rpf "$FILENAME" "$HOME/.gradle/gradle.properties"
70 tar -rpf "$FILENAME" "$HOME/.android/debug.keystore"
71}
72
73# Append selected items to tar archive
74function backup_specific_items() {
75 green "Backing up specific items..."
76 tar -rpf "$FILENAME" --exclude=".git" "$HOME/.zsh"
77 tar -rpf "$FILENAME" "$HOME/.ssh"
78 tar -rpf "$FILENAME" $HOME/Library/LaunchAgents/local.*
79 tar -rpf "$FILENAME" $HOME/Data/launchd/*/*.sh
80 tar -rpf "$FILENAME" "$HOME/Library/Developer/Xcode/UserData/KeyBindings"
81 tar -rpf "$FILENAME" --exclude="*.log" "$HOME/.aria2"
82 tar -rpf "$FILENAME" /etc/hosts /etc/paths
83 # tar -rpf "$FILENAME" /etc/postfix
84 # tar -rpf "$FILENAME" /etc/apache2/**/*.conf
85}
86
87# Backup command output (defaults, crontab, brew list)
88function backup_system_state() {
89 crontab -l >crontab.txt && tar -rpf "$FILENAME" crontab.txt && rm crontab.txt
90 defaults read >defaults.txt && tar -rpf "$FILENAME" defaults.txt && rm defaults.txt
91 brew list >homebrew.txt && tar -rpf "$FILENAME" homebrew.txt && rm homebrew.txt
92}
93
94# Append list of backed-up files
95function add_backup_log() {
96 {
97 echo "Save location: https://onedrive.live.com/?id=5FC8AF0024B02AE9%2118898&cid=5FC8AF0024B02AE9"
98 echo -e "\n\nBackup List:\n"
99 tar -tvf "$FILENAME"
100 } >backup_log.txt
101 tar -rpf "$FILENAME" backup_log.txt
102 rm backup_log.txt
103}
104
105# Validate final backup size
106function validate_backup_size() {
107 local size size_mb
108 size=$(stat -f "%z" "$FILENAME")
109 size_mb=$(echo "scale=2; $size / 1024 / 1024" | bc)
110 blue "$FILENAME has size ${size_mb} MB"
111
112 if [[ $size -gt 24000000 ]]; then
113 red "Backup > 24 MB, aborting."
114 exit 1
115 else
116 green "Done!"
117 fi
118}
119
120# === Main Execution ===
121ensure_backup_dir
122check_existing_backup
123cd "$HOME" || exit 1
124generate_config_files
125backup_dotfiles
126backup_config_gz
127backup_specific_items
128backup_system_state
129add_backup_log
130validate_backup_size
131
132exit 0
133
134# Restore with:
135# sudo tar -xvf <backup_filename>.tar -C /
136# brew bundle install --file=~/Brewfile
137
config.md Raw

macos

  • settings -> keyboard shortuts -> services -> disable searching
  • settings -> keyboard shortuts -> mission control -> mission control {swtich to desktop nth}
  • settings -> display -> {reduce motion,increase contrast}
  • settings -> desktop & dock -> Mission control -> {diable rerrangement,separate spaces}
  • settings -> desktop & dock -> Desktop & dock -> {diable animate application,recent apps}
  • sudo mdutil -i off / -> disable spotlight indexing

iterm

  • settings -> profiles -> other actions -> import json as profile
  • Settings -> Advanced -> Scroll wheel sends arrow keys when in alternate screen mode: FALSE
  • Preferences → Profiles → Keys → Keyboard Behavior-> Natural Text Editing

android studio

  • tools -> create commandline launcher
  • logcat -> ⚙️ -> modify views
  • settings -> keymaps -> version control systems -> git -> Annotate = ctl + shf + b
  • build -> build tools -> gradle -> enable parallel gradle model fetching
  • Preferences -> Appearance & Behavior -> System Settings -> max
  • commit -> ⋮ -> configure local change -> staging area
  • commit -> 👁️ -> group by directory

firefox

  • about:preferences#privacy -> Firefox Data Collection and Use -> disable
  • about:preferences#privacy -> Custom history -> Uncheck all

mate

  • view -> show file browser -> project folder -> (dropdown) use * as project folder
  • settings -> terminal -> shell support insatll

vscode

  • settings gui -> "search: exclude" -> add "**/*lock.yaml"
  • > Install 'code' command in PATH" command

zed

  • /> cli: install cli binary

dbeaver

  • window -> show view -> query manager

tailscale

https://login.tailscale.com/admin/machines -> Disable key expiry (trusted server)

install.sh Raw
1sudo echo
2
3## reboot your mac and press ⌘+R
4## csrutil disable
5## reboot
6
7## colors
8red() { printf "\033[31m${1}\033[0m\n\n"; }
9green() { printf "\033[32m${1}\033[0m\n\n"; }
10blue() { printf "\033[38;5;27m${1}\033[0m\n"; }
11purple() { printf "\033[35m${1}\033[0m\n\n"; }
12
13## show hidden files
14defaults write com.apple.Finder AppleShowAllFiles true
15
16# xcode
17blue "Installing xcode"
18xcode-select --install
19
20# brew
21blue "Installing brew"
22bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
23brew update --auto-update
24brew analytics off
25
26# git
27blue "Installing git"
28brew install gh
29gh auth login
30
31## zsh
32bash -c "$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"
33
34## brew
35blue "Installing apps"
36
37brew install git git-gui
38brew install mos ffmpeg
39brew install fastlane
40brew install stats
41brew install carthage
42brew install lima
43brew install swiftformat
44brew install robotsandpencils/made/xcodes
45brew install swiftlint
46brew install mos asciinema
47brew install imagemagick
48brew install aria2
49brew install mackup # backup
50brew install jq
51brew install swiftlint
52brew install rsync
53brew tap majd/repo
54brew install ipatool
55brew install jadx
56brew install apktool
57brew install grep ## ggrep (gnu-unix)
58brew install ccat ## cat with format.
59brew install duti ## set default app.
60brew install ripgrep ## grep like, + recursive
61brew install ngrok/ngrok/ngrok
62brew install imagemagick
63brew install rclone
64brew install fd ## find alt
65brew install bat
66brew install tree
67brew install gitui
68brew install git-delta
69brew install neofetch
70brew install lolcat
71brew install lesspipe ## advance less
72brew install yt-dlp ## as youtube-dl weirdo
73brew install imagemagick
74brew install pngpaste
75brew install micro ## editor
76brew install vhs ## terminal recorder
77brew install rustfmt
78brew install jesseduffield/lazygit/lazygit
79brew install glances ## htop
80brew install mitmproxy
81brew install php
82brew install gitleaks
83brew install source-highlight
84brew install rbenv
85brew install jq
86brew install yq
87brew install scrcpy
88# brew install dua-cli mole # clean disk
89
90brew install git-lfs
91git lfs install
92git lfs install --system
93
94brew install --cask swiftformat-for-xcode
95brew install --cask maccy
96brew install --cask flameshot
97brew install --cask vlc
98brew install --cask localsend
99brew install --cask lunar # brightness
100brew install --cask ghostty
101
102# brew install --cask jurplel/tap/instant-space-switcher # spaces
103# brew install --cask xcodes
104# brew install --cask devtoys
105# brew install --cask hiddenbar
106# brew install --cask swiftbar trex multi // create web application
107# brew install --cask alt-tab
108# brew install --cask pusher
109# brew install --cask sequel-ace
110# brew install --cask keycastr # keystroke visualizer
111# brew install --cask linearmouse
112# brew install --cask iconizer
113# brew install --cask kap
114# brew install --cask --no-quarantine middleclick
115# brew install --cask amethyst rectangle // tiling window
116# brew tap duongductrong/snapzy https://github.com/duongductrong/Snapzy && brew install --cask snapzy # screenshot
117
118# https://caddy.community/t/caddy-on-mac-os-as-homebrew-service-autostart-on-system-startup/16940/2
119brew install caddy
120
121## vim
122curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
123 https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim #plugin
124
125# rust
126curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
127
128## services
129brew services start caddy
130# /usr/local/etc/Caddyfile
131
132curl -fsSL https://raw.githubusercontent.com/onmyway133/FinderGo/master/install.sh | sh
133
134## font
135blue "Installing fonts"
136echo -e "\xee\x82\xa0"
137brew tap homebrew/cask-fonts
138brew install --cask font-fira-code
139brew install font-hack-nerd-font
140echo -e "\xee\x82\xa0"
141
142# cli
143curl -sL https://firebase.tools | bash
144curl -fsSL https://d2lang.com/install.sh | sh -s -- # d2 for diagrams, arrows....
145sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/install)"
146
147curl https://raw.githubusercontent.com/ax/apk.sh/main/apk.sh -o /usr/local/bin/apk.sh
148chmod +x /usr/local/bin/apk.sh
149
150# node
151brew install node
152brew install watchman
153brew install cocoapods
154
155npm install --global web-ext
156npm install --global git-format-staged
157npm install -g react-native-cli
158npm install -g yarn
159npm install -g eslint
160npm install -g terminalizer
161
162# disk-space-analyzer
163curl https://download.nektony.com/download/diskexpert/disk-space-analyzer.dmg -O
164open disk-space-analyzer.dmg > /dev/null 2&>1 &
165
166## sublime text
167
168ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
169
170## fzf
171brew install fzf
172
173## dotfiles
174blue "Config dotfiles https://www.atlassian.com/git/tutorials/dotfiles"
175git init --bare $HOME/.cfg
176alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
177config config --local status.showUntrackedFiles no
178
179## vim
180curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
181 https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim #plugin
182
183# sudo part
184## Enable install from anywhere
185# https://www.reddit.com/r/MacOS/comments/pquuc4/comment/hdds9g0/
186# https://maclife.io/huong-dan-tat-gatekeeper-bat-tuy-chon-anywhere-tren-macos-sierra-10-12-de-cai-ung-dung-ben-ngoai-app-store.html
187sudo spctl --master-disable
188
189sudo gem install cocoapods
190sudo gem install screengrab
191
192# exit
193green "Install successfully, enjoy this awsome machine ❤️"
194exit
195
196## addition
197[vscode xcode] https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line
198[storage] https://nektony.com/disk-expert
199[cliboard] flycut/cutbox
200[editor] textmate coteditor
201[vpn] warp 1.1.1.1
202[player] https://github.com/iina/iina/releases/tag/v1.3.0
203[extension] https://github.com/quoid/userscripts
204[wiget] https://github.com/leits/MeetingBar
205[ci] https://github.com/cirruslabs/tart
206[vm] https://github.com/utmapp/UTM
207[ipa] https://github.com/majd/ipatool
208[xcode] https://github.com/RobotsAndPencils/XcodesApp
209[emulator] https://github.com/PlayCover/PlayCover
210[annotate, cite, and share research] https://www.zotero.org/
211[terminal] https://iterm2.com/downloads.html
212[keyboard] https://github.com/pqrs-org/Karabiner-Elements
213[realm] https://studio-releases.realm.io/latest/download/mac-dmg https://github.com/dsmelov/simsim
214[sketch] https://github.com/duraki/SketchCrapp
215[record] https://github.com/onmyway133/GifCapture/releases/tag/1.1.0
216[note] https://github.com/glushchenko/fsnotes
217[convert video2gif] https://github.com/sindresorhus/Gifski
218[download manager] https://github.com/agalwood/Motrix/releases
219[wallpaper] https://github.com/rlxone/Equinox
220[php] https://github.com/nicoverbruggen/phpmon
221[firmware] https://github.com/ninxsoft/mist-cli
222[xcodeproject] https://github.com/yonaskolb/XcodeGen
223[calender] https://github.com/pakerwreah/Calendr
224[java] https://www.oracle.com/java/technologies/downloads/#jdk19-mac
225[automation] https://www.hammerspoon.org/go/
226[video] https://github.com/mltframework/shotcut/releases
227[xcode] https://github.com/Serchinastico/Kin
228[database] https://github.com/dbeaver/dbeaver/releases
229[default app] https://www.rubicode.com/Downloads/RCDefaultApp-2.1.X.dmg
230[wasm] https://github.com/WebAssembly/wabt/releases/w
231[launchctl] launchcontrol
232[file-explorer] https://github.com/sayanarijit/xplr/releases | https://github.com/ranger/ranger | https://github.com/kamiyaa/joshuto | nnn | https://github.com/sxyazi/yazi
233[file server] https://github.com/sigoden/dufs # webdav
234[localsend] https://localsend.org/#/download # file sharing, airdrop
235[teamview] https://github.com/rustdesk/rustdesk/releases # teamviewer alternative
236[sql] drawsql.app
237[disk] https://github.com/Byron/dua-cli?tab=readme-ov-file
238[monitor brightness] https://github.com/alin23/Lunar
239[export photo library ios] https://github.com/RhetTbull/osxphotos
240[music lyric] buzz
241[image compressor, blog] caesium image compressor
242[vpn] tunelblick
243[bloatware] uad-ng-macos
244[window manager] https://github.com/MrKai77/Loop/releases/
245[editor] https://zed.dev/download
246[software] https://github.com/objective-see/KnockKnock
247[server] https://github.com/lollipopkit/flutter_server_box
248[network monitor] https://github.com/GyulyVGC/sniffnet
249[slideshow] https://github.com/gobbledegook/creevey
250[editor]https://github.com/sinelaw/fresh
251[window managers] https://www.raycast.com/ | https://github.com/nikitabobko/AeroSpace
252[video] https://github.com/HandBrake/HandBrake
253[stats, monitor] https://github.com/exelban/stats
254