-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.zsh
156 lines (124 loc) · 3.82 KB
/
os.zsh
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
#####################################################################
SETUP__OS() {
OS__MAKE_REQUIRED_RESOURCES || return 1
[ ${CI} ] && { STATUS 'detected CI; skipping os setup'; return 0; }
GETSUDO
local OS_NAME=$(OS__GET_OS)
[ ! ${OS_NAME} ] && ABORT
OS__INSTALL_SOURCE_DEPENDENCIES || return 2
OS__INSTALL_MANAGED_DEPENDENCIES || return 3
}
OS__GET_OS() {
local OS_NAME=$(lsb_release -is 2>/dev/null | tr '[:upper:]' '[:lower:]')
[ ! ${OS_NAME} ] \
&& OS_NAME=$(cat /etc/os-release 2>/dev/null | grep '^ID=' | sed 's/^ID=//')
[ ! ${OS_NAME} ] \
&& WARNING 'failed to detect operating system' \
&& OS_NAME=$(echo -e "arch\ndebian\nother" | FZF 'select an operating system') \
;
[[ ${OS_NAME} =~ ^ubuntu$ ]] && OS_NAME=debian
[[ ${OS_NAME} =~ ^[Ee]ndeavour[Oo][Ss]$ ]] && OS_NAME=arch
echo ${OS_NAME}
}
#####################################################################
OS__INSTALL_SOURCE_DEPENDENCIES() {
case ${OS_NAME} in
arch )
command -v yay >/dev/null 2>&1 \
|| SCWRYPTS packages/install -- 'https://aur.archlinux.org/yay.git' --local-name 'yay' \
;
;;
debian ) ;;
* ) ;;
esac
[ ${COMPILE_DMENU} ] && [[ ${COMPILE_DMENU} -eq 1 ]] \
&& SCWRYPTS packages/install -- 'https://github.com/tiyn/dmenu' --local-name 'patched-dmenu'
return 0
}
#####################################################################
OS__INSTALL_MANAGED_DEPENDENCIES() {
local ERRORS=0
STATUS 'checking os dependencies'
case ${OS_NAME} in
arch )
;;
debian ) ;;
* )
OS_NAME='generic'
WARNING "no automated installer available for '${OS_NAME}'"
;;
esac
[ ${MIN} ] && [[ ${MIN} -eq 1 ]] && [ -f "${DOTWRYN_PATH}/setup/os-dependencies/${OS_NAME}.min.txt" ] \
&& DEPENDENCIES="${DOTWRYN_PATH}/setup/os-dependencies/${OS_NAME}.min.txt" \
|| DEPENDENCIES="${DOTWRYN_PATH}/setup/os-dependencies/${OS_NAME}.txt" \
;
[ ! ${CI} ] && {
STATUS 'updating system, repositories, and mirrors'
UPDATE_REPOSITORIES__${OS_NAME}
}
for DEPENDENCY in $(cat "${DEPENDENCIES}")
do
INSTALL_MANAGED__${OS_NAME} ${DEPENDENCY}
done
[[ ${ERRORS} -ne 0 ]] && {
WARNING "detected ${ERRORS} errors; double check warnings before proceeding!"
yN 'continue with install?' && return 0 || ABORT
}
SUCCESS 'all dependencies satisfied'
return 0
}
UPDATE_REPOSITORIES__arch() { yay -Syu; }
INSTALL_MANAGED__arch() {
local TARGET="$1"
[[ ${TARGET} =~ aws-cli-v2 ]] && {
STATUS "skipping aws-cli-v2 checks since they are bad right now"
return 0
}
yay -Qq 2>/dev/null | grep -q "^${TARGET}$\|^${TARGET}-git$" && {
SUCCESS "found '${TARGET}'"
} || {
STATUS "installing '${TARGET}'"
yay -Syu --noconfirm ${TARGET} \
&& SUCCESS "successfully installed '${TARGET}'" \
|| ERROR "failed to install '${TARGET}'" \
;
}
}
UPDATE_REPOSITORIES__debian() { sudo apt-get update && sudo apt-get upgrade; }
INSTALL_MANAGED__debian() {
STATUS "checking / installing '$1'"
sudo apt-get install --yes $1 \
&& SUCCESS "'$1' installed" \
|| ERROR "failed to install ${TARGET}" \
;
}
UPDATE_REPOSITORIES__generic() { return 0; }
INSTALL_MANAGED__generic() {
command -v $1 >/dev/null 2>&1 \
|| ERROR "could not find '$1'; it's up to you to install this one!"
}
#####################################################################
OS__MAKE_REQUIRED_RESOURCES() {
local ERRORS=0
local DIRECTORIES=(
"${XDG_CONFIG_HOME:-${HOME}.config}/wryn"
"${HOME}/.local/bin"
)
local FILES=(
"${HOME}/.zshrc"
)
STATUS 'making required system resources'
for D in ${DIRECTORIES}
do
[ ! -d ${D} ] && { mkdir -p ${D} || ERROR "failed to create directory '${D}'"; }
done
for F in ${FILES}
do
[ ! -f ${F} ] && { touch ${F} || ERROR "failed to create file '${F}'"; }
done
[[ ${ERRORS} -eq 0 ]] \
&& SUCCESS 'finished creating system resources' \
|| ERROR 'failed to create system resources' \
;
return ${ERRORS}
}