-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·157 lines (134 loc) · 5.18 KB
/
install.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
#!/bin/zsh
set -e
THIS_DIR="${0:A:h}"
function init-system-debian()
{
DEBIAN_PACKAGES=(build-essential xclip)
DEBIAN_PACKAGES+=(clang llvm lld lldb ccache cmake)
DEBIAN_PACKAGES+=(tmux git emacs)
DEBIAN_PACKAGES+=(moreutils) # Install sponge
DEBIAN_PACKAGES+=(htop nvtop)
sudo apt-get update
sudo apt-get install ${DEBIAN_PACKAGES}
}
function init-system-macos()
{
## Unautomated packages. These need to be installed manually, may need
## settings adjusted, and needed to be added to "Login Items" in system
## preferences to run on boot.
##
## - MonitorControl: https://github.com/MonitorControl/MonitorControl
## - ScrollReverser: https://github.com/pilotmoon/Scroll-Reverser
##
## TODO: Add MonitorControl to HOMEBREW_PACKAGES since its available via brew.
HOMEBREW_PACKAGES=(coreutils) # Install GNU utils like `ls` as `gls`
HOMEBREW_PACKAGES+=(util-linux) # Install GNU column & more
HOMEBREW_PACKAGES+=(sponge emacs tmux htop)
HOMEBREW_PACKAGES+=(bitwarden)
brew install ${HOMEBREW_PACKAGES}
## Register caffeine-manager to start on boot via cronjob.
##
## We use crontab's @reboot syntax to register the command on boot. According to
## the internet, cron has been deprecated in favor of launchd / launchctl but, in
## my experience launchd is tremendously complicated and cron is easy so we're
## going with that. Despite the deprecation, it seems unlikely that apple will
## actually remove support for cron (this would break posix compliance?) and even
## if this were to occur homebrew or some other community would presumably provide
## an alternative distribution.
##
## Although, imo, launchd is worse there are still some gotcha's with this cron
## solution:
##
## - There is no builtin way to append a job from the command line; only over-
## write. This means we have to build our own pipeline for appending.
##
## - On some systems, @reboot may only work in the root's crontab. You can
## write an @reboot line as any user of course, but user-level @reboot
## directives may be ignored. For now, user-cron seems to work on my macbook
## so we're going with that.
##
## References:
## - https://unix.stackexchange.com/questions/109804/crontabs-reboot-only-works-for-root
## - https://apple.stackexchange.com/questions/12819/why-is-cron-being-deprecated
CRON="/usr/bin/crontab"
CM="$(realpath ${THIS_DIR}/macos/caffeine-manager.sh)"
( ${CRON} -l | grep -v ${CM}; echo "@reboot ${CM}" )| ${CRON} -
}
function init-system()
{
echo "Initializing system..."
if [[ "$OSTYPE" == "darwin"* ]]; then
init-system-macos
else
init-system-debian
fi
}
function mk-user-dirs() {
echo "Initializing user directories..."
mkdir -p ${HOME}/apps ${HOME}/backups ${HOME}/venvs ${HOME}/workspace
}
function uninstall-top() {
grep -v 'source .*/tk.bashrc' ${HOME}/.bashrc | sponge ${HOME}/.bashrc
grep -v 'source .*/tk.zshrc' ${HOME}/.zshrc | sponge ${HOME}/.zshrc
}
function install-top()
{
# Uninstall first, to make sure we don't create duplicate entries.
uninstall-top
# For top-level startup files, we install by editing home directory rather than
# symlinking it. This leaves a place for one-off configuration in the home dir.
echo "source ${THIS_DIR}/tk.bashrc" >> ${HOME}/.bashrc
echo "source ${THIS_DIR}/tk.zshrc" >> ${HOME}/.zshrc
}
function install-dotfiles()
{
echo "Initializing user configuration..."
HTOP_RC_PATH="${HOME}/.config/htop/htoprc"
NUM_HTOP_COLS=$(source ${THIS_DIR}/term/tmux.sh && htop-num-cpu-cols)
HTOP_CONFIG=htop-cpu${NUM_HTOP_COLS}.cfg
# Setup subdirs
mkdir -p $(dirname ${HTOP_RC_PATH})
# Link secondary dotfiles
if [[ "$OSTYPE" == "darwin"* ]]; then
alias ln='gln'
fi
ln -rfs ${THIS_DIR}/core/tk.inputrc ${HOME}/.inputrc # Core
ln -rfs ${THIS_DIR}/editor/tk.emacs ${HOME}/.emacs # Editor
ln -rfs ${THIS_DIR}/editor/tk.emacs.d ${HOME}/.emacs.d
ln -rfs ${THIS_DIR}/editor/tk.editorconfig ${HOME}/.editorconfig
ln -rfs ${THIS_DIR}/stat/${HTOP_CONFIG} ${HTOP_RC_PATH} # Stat
ln -rfs ${THIS_DIR}/term/tk.tmux.conf ${HOME}/.tmux.conf # Term
ln -rfs ${THIS_DIR}/toolchain/tk.gdbinit ${HOME}/.gdbinit # Toolchain
ln -rfs ${THIS_DIR}/vcs/tk.gitignore ${HOME}/.gitignore # VCS
ln -rfs ${THIS_DIR}/vcs/tk.gitconfig ${HOME}/.gitconfig
ln -rfs ${THIS_DIR}/vcs/modular.gitconfig ${HOME}/.modular.gitconfig # Note dot
# Source top-level dotfiles
install-top
}
function uninstall-dotfiles()
{
rm -f ${HOME}/.inputrc
rm -f ${HOME}/.emacs
rm -f ${HOME}/.emacs.d
rm -f ${HOME}/.editorconfig
rm -f ${HOME}/.tmux.conf
rm -f ${HOME}/.gdbinit
rm -f ${HOME}/.gitignore
rm -f ${HOME}/.gitconfig
rm -f ${HOME}/.modular.gitconfig # Note dot
}
function print-success()
{
echo "Install complete."
echo ""
echo "System Status"
echo "============="
source ${THIS_DIR}/stat/stat.sh && system-stat
}
##
## Main
##
init-system
mk-user-dirs
install-dotfiles
print-success