-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply.sh
80 lines (72 loc) · 2.78 KB
/
apply.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
#!/bin/bash
set -ex
function usage() {
echo "$0 [-x | --install-extra-packages]"
}
install_extra_packages=false
while [ "$1" != "" ]; do
case $1 in
-x | --install-extra-packages )
install_extra_packages=true
;;
-h | --help )
usage
exit
;;
-* )
usage
exit 1
;;
* )
usage
exit 1
esac
shift
done
# source location
source=$(readlink -f -- $(dirname $0)/data)
target=~/bin
# copy configs
mkdir -p "${target:?}" ~/.vim ~/.config
cp "${source:?}"/etc/vim/vimrc ~/.vim/vimrc
cp -R "${source:?}"/etc/micro ~/.config/
cp -R "${source:?}"/etc/hl ~/.config/
cp -R "${source:?}"/etc/atuin ~/.config/
tar -C ~ -x -f "${source:?}"/share/tmuxcfg.tar.gz
# install needed and useful packages from official repositories
if [ ${install_extra_packages:?} == true ] && [ "$(id -u)" == 0 ]; then
if [ -f /etc/redhat-release ]; then
yum -y install epel-release
yum -y install -q vim htop git
elif [ -f /etc/lsb-release ]; then
apt -y install htop git
fi
fi
# unpack binaries from tarballs
tar -C ~ -x --strip-components 1 -f "${source:?}"/dist/tmux.tar.gz
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/bat.tar.gz --wildcards '*/bat'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/fd.tar.gz --wildcards '*/fd'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/lsd.tar.gz --wildcards '*/lsd'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/delta.tar.gz --wildcards '*/delta'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/micro.tar.gz --wildcards '*/micro'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/procs.tar.gz --wildcards '*/procs'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/gojq.tar.gz --wildcards '*/gojq'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/rg.tar.gz --wildcards '*/rg'
tar -C "${target:?}" -x --strip-components 1 -f "${source:?}"/dist/atuin.tar.gz --wildcards '*/atuin'
tar -C "${target:?}" -x -f "${source:?}"/dist/hl.tar.gz --wildcards 'hl'
# configure bash profile
if [ -f ~/.bash_profile ]; then
profile=~/.bash_profile
elif [ -f ~/.profile ]; then
profile=~/.profile
fi
echo "source ${source:?}/scripts/profile.sh" | "${source:?}/scripts/append.sh" "${profile:?}"
echo "export PATH=${target:?}:\${PATH}" | "${source:?}/scripts/append.sh" "${profile:?}"
echo "[[ -f ${source:?}/etc/.bash-preexec.sh ]] && source ${source:?}/etc/.bash-preexec.sh" | "${source:?}/scripts/append.sh" "${profile:?}"
echo 'eval "$(atuin init bash --disable-up-arrow)"' | "${source:?}/scripts/append.sh" "${profile:?}"
# configure ssh
mkdir -p ~/.ssh && chmod 0700 ~/.ssh
for key in $(find "${source:?}"/keys -name '*.key'); do
cat ${key:?} | "${source:?}"/scripts/append.sh ~/.ssh/authorized_keys
done
chmod 0600 ~/.ssh/authorized_keys