-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake.sh
executable file
·99 lines (86 loc) · 2.38 KB
/
make.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
#!/usr/bin/env bash
# install packages and deploy dotfiles
# backup conflicting dotfiles
PACMAN=/usr/bin/yay
PACKAGES_FILE=packages.pacman
CARGO=~/.cargo/bin/cargo
CARGO_FILE=packages.cargo
BACKUP_DIR=~/.dotfiles.backup
SUDO=/usr/bin/sudo
GIT=/usr/bin/git
MAKEPKG=/usr/bin/makepkg
install_packages() {
# install packages
# get sudo
$SUDO -v
# sudo keep alive
while true; do $SUDO -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# install yay
if ! pacman -Q yay-bin &> /dev/null ; then
echo -e "\n# Installing AUR helper 'yay'..."
dir=$(pwd)
cd "$(mktemp -d)" || exit 1;
$GIT clone https://aur.archlinux.org/yay-bin.git
cd yay-bin || exit 1;
$MAKEPKG -si --noconfirm
cd ..
rm -rf yay-bin
cd "$dir" || exit 1;
echo -e "AUR Helper 'yay' successfully installed\n"
fi
[ ! -f "${PACKAGES_FILE}" ] || echo "# Install packages from ${PACKAGES_FILE}"
for package in $( ! test -f "${PACKAGES_FILE}" || cat "${PACKAGES_FILE}"); do
if [[ "$package" != \#* ]]; then
${PACMAN} -S "${package}" --needed --noconfirm
fi
done
}
install_cargo_packages() {
[ ! -f "${CARGO_FILE}" ] || echo "# Install cargo from ${CARGO_FILE}"
for package in $( ! test -f "${CARGO_FILE}" || cat "${CARGO_FILE}"); do
if [[ "$package" != \#* ]]; then
${CARGO} install "${package}"
fi
done
}
link_files() {
# backup dotfiles
IFS=$'\n'
for file in $(stow -n */ 2>&1 | grep -v 'WARNING' | grep -oE ":.+" | cut -c3-); do
echo "# Backing up conflicts to ${BACKUP_DIR}"
mkdir -p ${BACKUP_DIR}/"$(dirname "${file}")"
mv ~/"${file}" ${BACKUP_DIR}/"${file}"
echo " ✔ ${file}"
done
# create symlinks
echo "# Linking dotfiles..."
stow */
echo " ✔ done"
}
print_help() {
usage="$(basename "$0") [-h] [packages] [dotfiles]
help:
packages install packages
dotfiles link dotfiles
help print this help"
echo "${usage}"
}
# check arguments
while test $# -gt 0
do
case "$1" in
packages) install_packages
;;
cargo) install_cargo_packages
;;
dotfiles) link_files
;;
help|-h) print_help
;;
*) echo "invalid argument: $1"
print_help
;;
esac
shift
done
exit 0