-
Notifications
You must be signed in to change notification settings - Fork 0
/
do.sh
executable file
·125 lines (109 loc) · 2.69 KB
/
do.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
#!/usr/bin/env bash
##
## This script was created with purpose on testing, so it will not have any
## high rated features and speed improvements in it
## Feel free to edit this script and do whatever you want to do with it, except
## giving it out as YOUR content
##
## ~ avolgha (Marius), 10 Nov 2021
##
# **Syntax**:
# <do>
# - info
# - update
# - upgrade (+ update)
# - generate
# - cpp, c
# - js
# - ts
color_reset="$(tput sgr0)"
color_info="$(tput setaf 2)"
color_error="$(tput setaf 1)"
color_prompt="$(tput setaf 6)"
color_white="$(tput setaf 7)"
info() { echo "${color_info}info:${color_white} ${1}${color_reset}"
}
error() { echo "${color_error}error:${color_white} ${1}${color_reset}"
}
fatal() { echo "${color_error}fatal:${color_white} ${1} ${color_reset}" && exit 1
}
acceptFunction() {
while true; do
read -p "${color_prompt}prompt:${color_white} $* ${color_white}[${color_info}y${color_white}/${color_error}n${color_white}]: " yn
case "$yn" in
[YyJj]*) return 0 ;;
[Nn]*) return 1 ;;
esac
done
}
update() {
msg="$(sudo pacman -Syy)"
ret="$?"
if [ ! $ret -eq 0 ]; then
echo "${color_error}fatal: exited program with status code '$(ret)'. This might helps you to find the error:"
echo "$msg"
exit 1
fi
}
upgrade() {
update
msg="$(sudo pacman -Syyu)"
ret="$?"
if [ ! $ret -eq 0 ]; then
echo "${color_error}fatal: exited program with status code '$(ret)'. This might helps you to find the error:"
echo "$msg"
exit 1
fi
}
parse_arguments() {
update=0
upgrade=0
generate=0
for arg in "$@"; do
case "$arg" in
"--update")
if [ $update -eq 1 ]; then
error "cannot set argument '$arg' twice"
else
update=1
fi ;;
"--upgrade" | "-u")
if [ $upgrade -eq 1 ]; then
error "cannot set argument '$arg' twice"
else
upgrade=1
fi ;;
"--info" | "-i")
neofetch
exit 0 ;;
"--generate" | "-g")
if [ $generate -eq 1 ]; then
error "cannot set argument '$arg' twice"
else
generate=1
fi ;;
*)
error "unknown argument: '$arg'" ;;
esac
done
if [ $update -eq 1 ]; then
update
info "successfull system repository update"
elif [ $upgrade -eq 1 ]; then
upgrade
info "successfull system upgrade"
if $(acceptFunction "do you want to do a system reboot?"); then
reboot
fi
elif [ $generate -eq 1 ]; then
echo "still in progress lol..."
else
echo "${color_error}fatal:${color_white} please provide any of these arguments:"
echo "${color_error}fatal:${color_white} '--update'"
echo "${color_error}fatal:${color_white} '-u' | '--upgrade'"
echo "${color_error}fatal:${color_white} '-i' | '--info'"
echo "${color_error}fatal:${color_white} '-g' | '--generate'"
exit 1
fi
}
parse_arguments $@ && exit 0