-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup.sh
executable file
·193 lines (156 loc) · 3.75 KB
/
up.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
#!/bin/bash
declare -A args=(
[dotfiles]=0
[programs]=0
[personal]=0
[keys]=0
)
# Parse any args
fancy=0
POSITIONAL=()
while [ $# -gt 0 ]
do
case $1 in
"--dotfiles"|"-d")
# output fancy message
args[dotfiles]=1
shift
;;
"--programs"|"-p")
# output fancy message
args[programs]=1
shift
;;
"--personal"|"-e")
# output fancy message
args[personal]=1
shift
;;
"--keys"|"-k")
# output fancy message
args[keys]=1
shift
;;
*)
# save it in an array for later
POSITIONAL+=("$1")
# shift past argument
shift
;;
esac
done
# restore positional parameters
set -- "${POSITIONAL[@]}"
# https://stackoverflow.com/questions/17336915/return-value-in-a-bash-function
distro() {
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=debian
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
fi
echo $OS
}
# programs
programs() {
ROOT="sudo"
PROGRAMS="programs.txt"
OS=$(echo $(distro))
OS_LOWER=$(echo $OS | tr '[:upper:]' '[:lower:]')
OS_SHORT=$(echo $OS_LOWER | awk '{print $1;}')
declare -A pkgman=(
[arch]="pacman -Syu --needed - "
[void]="xbps-install -Su"
[debian]="apt-get update; apt-get install"
[gentoo]="emerge --ask --verbose --update --deep --newuse @world"
)
for pm in ${!pkgman[@]}
do
if [[ $OS_SHORT == $pm ]]
then
echo "$OS based operating system detected."
INSTALL="${pkgman[$pm]}"
fi
done
if [ ! -z "$INSTALL" ]
then
echo "Running '$INSTALL < $PROGRAMS'"
$ROOT $INSTALL < $PROGRAMS
fi
}
keys() {
KEY="https://git.liambeckman.com/cgit/private"
git clone $KEY
gpg --output private/.ssh.tar.gz --decrypt private/.ssh.tar.gz.gpg
tar -zxvf private/.ssh.tar.gz -C private
cp -r private/.ssh $HOME
}
# dotfiles
dotfiles() {
PATH=$HOME/Documents/code/dotfiles
REPO="[email protected]:/srv/git/dotfiles.git"
BACKUP=".backup"
declare -A configs=(
[bspwm]=$HOME/.config/bspwm
[emacs]=$HOME
[gtk]=$HOME/.config/gtk
[nvim]=$HOME
[openbox]=$HOME/.config/openbox
[polybar]=$HOME/.config/polybar
[sxhkd]=$HOME/.config/sxhkd
[tmux]=$HOME
[vim]=$HOME
[zsh]=$HOME
)
mkdir -p $PATH
git clone $REPO $PATH
for pkg in "${!configs[@]}"
do
for file in $pkg
do
file_count=$(find "${configs[$pkg]}" -name $file | wc -l)
if [[ $file_count -gt 0 ]]
then
mv "${configs[$pkg]}/$file" "${configs[$pkg]}/$file$BACKUP"
fi
done
stow -t ${configs[$pkg]} "$PATH/$pkg"
done
}
personal() {
xdg-user-dirs-update
echo "exec sxhkd &" >> $HOME/.xinitrc
echo "exec bspwm &" >> $HOME/.xinitrc
}
# ./up.sh --programs --dotfiles --personal --keys
main() {
if [ ${args[programs]} -eq 1 ]
then
programs
fi
if [ ${args[dotfiles]} -eq 1 ]
then
dotfiles
fi
if [ ${args[personal]} -eq 1 ]
then
personal
fi
if [ ${args[keys]} -eq 1 ]
then
keys
fi
}
main