forked from nullxception/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·108 lines (90 loc) · 2.24 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
#!/bin/bash
#
# simple deploy script for dotfiles
#
# usage :
# ./install.sh <module-name>
#
dotfiles=$(realpath "$(dirname "$0")")
log() {
printf "$(basename "$0"): %s\n" "$1"
}
fun_exists() {
declare -f -F $1 >/dev/null
return $?
}
usage() {
cat <<EOF
Dotfiles install script
Usage :
$(basename "$0") [module-name]
EOF
}
comm_prefix_gen() {
if [ ! -d "$1" ]; then
mkdir -p "$1" >/dev/null 2>&1
if [ $? != 0 ]; then
sudo mkdir -p "$1" >/dev/null 2>&1
printf sudo
fi
else
local curr=$(id -gn)
local dest=$(stat -c %G "$1")
if [ "$dest" != "$curr" ]; then
printf sudo
fi
fi
}
deploy_topic() {
local target=$1
local comm_prefix=$(comm_prefix_gen "$target")
local moddir="$dotfiles/$mod"
if [ "$comm_prefix" = "sudo" ]; then
log "using sudo to install module..."
fi
find "$moddir" -type f | while read src; do
[ "${src#*.module-data.bash}" != "$src" ] && continue
[ "${src#*.module-data.ps1}" != "$src" ] && continue
dest="$(printf ${src%/*} | sed "s|$moddir|$target|")/"
log "copying $src to $dest"
[ -d "$dest" ] || $comm_prefix mkdir -p "$dest"
$comm_prefix cp "$src" "$dest"
done
}
install_mod() {
local comm_prefix=""
local mod=$(basename "$(realpath "$1")")
if [[ ! -f "$dotfiles/$1/.module-data.bash" ]]; then
log ".module-data.bash for \"$1\" doesn't exists. aborting"
exit 1
fi
source "$dotfiles/$mod/.module-data.bash"
if fun_exists module_preinstall; then
module_preinstall
fi
if fun_exists module_install; then
log "using custom install method for topic '$mod'"
module_install
else
local target=$(realpath -mq "$module_target")
if [ -z "$target" ]; then
log "Invalid module_target entry. aborting"
exit 1
fi
# Execute install procedure
log "installing topic '$mod' to $target"
deploy_topic "$target"
fi
# Execute module's post-install
if fun_exists module_postinstall; then
module_postinstall
fi
}
if [[ -z "$@" ]]; then
usage
exit 1
fi
for mod in $@
do
install_mod "$mod"
done