-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
116 lines (98 loc) · 2.26 KB
/
utils.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
#!/bin/bash
if [ "$DOTFILES_UTILS_SOURCED" == true ]; then
return
fi
source "$SHLIB_ROOT/lib.sh"
SHLIB_FMT_TIME=true
function uninst ()
{
if ! sudo $PM_UNINSTALL_CMD $@; then
log::wrn "An error occurred while uninstalling: $@"
return 1
fi
}
function inst ()
{
if ! inst_silent $@; then
log::err "An error occurred while installing: $@"
return 1
fi
}
function inst_silent ()
{
sudo $PM_INSTALL_CMD $@
}
function inst_aur ()
{
if ! yay -S --sudoloop --needed --noconfirm --provides=false --answerdiff None --answerclean None --mflags "--noconfirm --needed" $@; then
log::err "An error occurred while installing from AUR: $@"
return 1
fi
}
function inst_pip ()
{
if [ -f /etc/arch-release ]; then
local args=("$@")
inst "${args[@]/#/python-}"
unset args
else
pip install "$@"
fi
}
function rm_comments ()
{
sed -e 's/[[:space:]]*#.*// ; /^[[:space:]]*$/d' $@
}
function read_list ()
{
echo $(rm_comments $1)
}
function is_android ()
{
if [ "$OSTYPE" == "linux-android" ]; then
return 0
else
return 1
fi
}
function pm_cmd ()
{
if is_android ; then
echo "pkg install"
return
fi
declare -A osinfo;
osinfo[/etc/redhat-release]="yum -y install"
osinfo[/etc/arch-release]="pacman --noconfirm --needed -S"
osinfo[/etc/gentoo-release]='emerge'
osinfo[/etc/SuSE-release]='zypper install'
osinfo[/etc/debian_version]="apt-get install -qq"
for f in "${!osinfo[@]}"; do
if [[ -f $f ]]; then
echo "${osinfo["$f"]}"
return
fi
done
}
function pm_uninst_cmd ()
{
if is_android ; then
echo "pkg uninstall"
return
fi
declare -A osinfo;
osinfo[/etc/redhat-release]="yum -y remove"
osinfo[/etc/arch-release]="pacman --noconfirm -R"
osinfo[/etc/gentoo-release]='emerge --deselect'
osinfo[/etc/SuSE-release]='zypper remove'
osinfo[/etc/debian_version]="apt-get remove -qq"
for f in "${!osinfo[@]}"; do
if [[ -f $f ]]; then
echo "${osinfo["$f"]}"
return
fi
done
}
export PM_INSTALL_CMD=$(pm_cmd)
export PM_UNINSTALL_CMD=$(pm_uninst_cmd)
export DOTFILES_UTILS_SOURCED=true