-
Notifications
You must be signed in to change notification settings - Fork 0
/
yuse.sh
executable file
·243 lines (204 loc) · 5.55 KB
/
yuse.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env bash
# Yuse - Crossdistro Package Wrapper.
# 1: command; 2: arguments; 3: arguments (...)
param1=$1
param2=$2
# ------ Meta ------
# Version
yuse_version="0.2"
yuse_version_channel="alpha"
yuse_location=$0
callName="yuse"
packageManager="pacman"
nativePKGUpdate="enabled"
flatpakUpdate="disabled" # [enabled/disabled]
snapUpdate="disabled" # [enabled/disabled]
distroID="DetectDistro"
afterUpdateDo=""
# Yuse config Path
# Here is the user configurations.
yuse_config_path="/opt/yuse-crosspkg/config/yuse.config"
# Configuration file
# Please change your settings in the "./yuse.config" file.
# (this changes the default settings).
function loadConfig() {
if [[ -e $yuse_config_path ]]; then
source "${yuse_config_path}"
fi
}
# . yuse.config
loadConfig
function detectDistro() {
local distID=$(cat /etc/os-release | grep -w "NAME=")
local distID=${distID:6:-1}
if ! [[ -z distID ]]; then distroID=$distID; fi
}
function setNativePKGManager() {
IFS=$'\n\t'
local distroPacman=("Arch Linux" "Manjaro")
for distro in ${distroPacman[@]}; do
if [[ $distro == $distroID ]]; then packageManager="pacman"; fi
done
local distroAPT=("Debian" "Debian GNU/Linux" "Ubuntu" "Mint")
for distro in ${distroAPT[@]}; do
if [[ $distro == $distroID ]]; then packageManager="apt"; fi
done
local distroDNF=("Fedora Linux" "Red Hat")
for distro in ${distroDNF[@]}; do
if [[ $distro == $distroID ]]; then packageManager="dnf"; fi
done
}
function commandHelp() {
echo -e "
\e[34mHelp about the Yuse Package Wrapper.\e[0m
Version: $yuse_version ($yuse_version_channel)
Distro: $distroID
Shell: $SHELL
Yuse is a simple, bash centric, cross distro, wrapper for manager packages with the same commands. Its syntax is simple and focusing on being more human. Check out some of the commands below:
\e[1;4mInstall a package\e[0m
$callName install [package]
\e[1;4mRemove a package\e[0m
$callName install [package]
\e[1;4mUpdate your packages\e[0m
$callName update
\e[1;4mClear cache from package manager\e[0m
$callName clear
\e[1;4mConfigure yuse\e[0m
$callName config
"
}
function commandCredits() {
echo -e "
\e[34mCREDITS\e[0m
Yuse is a simple, bash centric, cross distro, wrapper for manager packages with the same commands.
Created by: mblithium.
Download or contribute here: https://github.com/mblithium/yuse-crossdistro-pkg
"
}
function clearPKGCache() {
if [[ $packageManager == pacman ]]; then
sudo pacman -Sc
fi
}
function commandUpdate() {
case $packageManager in
"pacman")
echo -e "Updating pacman packages...\n"
sudo pacman -Syu
;;
"apt")
echo -e "Updating apt packages...\n"
sudo apt update
sudo apt upgrade
;;
"dnf")
echo -e "Updating apt packages...\n"
sudo dnf upgrade
;;
"yum")
echo -e "Updating YUM packages...\n"
yum update
esac
if [[ $flatpakUpdate == "enabled" ]]; then
echo -e "Updating flatpak packages...\n"
flatpak update
fi
if [[ $snapUpdate == "enabled" ]]; then
echo -e "Updating snap packages...\n"
snap update
fi
}
function commandInstall() {
if ! [[ -z $param2 ]]; then
echo "Installing package with the your package manager..."
case $packageManager in
"pacman")
sudo pacman -S $param2
;;
"apt")
sudo apt install $param2
;;
"dnf")
sudo dnf install $param2
;;
*)
echo "The script couldn't identify your package manager."
;;
esac
fi
}
function commandRemove() {
if ! [[ -z $param2 ]]; then
echo "Removing package with the your package manager..."
case $packageManager in
"pacman")
sudo pacman -R $param2
;;
"apt")
sudo apt remove $param2
;;
"dnf")
sudo dnf remove $param2
;;
"flatpak")
flatpak remove $param2
::
esac
fi
}
function configCommand() {
echo "Configurations..."
# local yuse_config_path="${yuse_location:0:-7}yuse.config"
echo "Yuse config path: $yuse_config_path"
sudo vim $yuse_config_path
loadConfig
}
function chooseCommand() {
if [[ -z $param1 ]]; then
echo -e "\e[1;31mYuse doesn't work without some argument,\nyou can try \"$callName help\" for help.\nI will do it for you...\e[0m"
commandHelp
fi
case $param1 in
"install")
commandInstall
;;
"update")
commandUpdate
;;
"remove")
commandRemove
;;
"clear")
clearPKGCache
;;
"config")
configCommand
;;
"help")
commandHelp
;;
"credits")
commandCredits
;;
*)
printf "Invalid argument, try using \"yuse help\" to find out what options are available.\n"
;;
esac
}
function afterUpdate() {
# Scripts that run after update
if [[ $param2 == "--flatpak" ]]; then
$flatpakUpdate = "enabled"
flatpak update
fi
return 0
}
function init() {
if [[ $distroID == "DetectDistro" ]]; then detectDistro; fi
if [[ $nativePKGUpdate == "enabled" ]]; then setNativePKGManager; fi
chooseCommand
afterUpdate
}
init
# By: mblithium
# https://github.com/mblithium