-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbpm
executable file
·184 lines (159 loc) · 4.6 KB
/
sbpm
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
#!/bin/sh
#SlackBuild Package Manager (SBPM) is a non-official
#script that's allow users to search, download and install
#packages from http://slackbuilds.org.
#@author krynyx
#@url http://github.com/krynyx/slackbuild-package-manager
#@date 2021-09-04
SBPM_VERSION="1.0.1"
SBPM_DESC="SlackBuild Package Manager (SBPM)"
SBPM_PATH="$HOME/.sbpm"
SBPM_CACHE="$SBPM_PATH/cache"
SBPM_PACKAGES="$SBPM_PATH/packages"
SB_URL="http://slackbuilds.org/slackbuilds"
SB_TAGS="TAGS.txt"
SB_PKGINFO="SLACKBUILDS.TXT"
SYSTEM_VERSION=$(cut -d" " -f2 /etc/slackware-version)
OPT=$1 #is the function to call
ARG=$2 #is the package name
#=================HELPERS=======================
sbpm_config()
{
if [ ! -d "$SBPM_PATH" ]; then
mkdir $SBPM_PATH
mkdir $SBPM_CACHE
mkdir $SBPM_PACKAGES
fi
}
#Search for the package name to verify if it exists before
#install/info operations.
PKGEXIST=0
package_exist()
{
pkgname=$1
result=$(cat "$SBPM_PATH/$SB_TAGS"|cut -d':' -f1 | grep -s -i -x "$pkgname")
if [ "$result" == "$pkgname" ]; then
PKGEXIST=1
else
PKGEXIST=0
fi
}
#If the package exists then get its information
PKGINFO="undefined"
get_package_info()
{
pkgname=$1
package_exist $pkgname
if [ "$PKGEXIST" -eq 1 ]; then
query="SLACKBUILD NAME: $pkgname"
first_line=$(grep -n -wx "$query" "$SBPM_PATH/$SB_PKGINFO"|cut -d':' -f1)
last_line=$(($first_line+10))
PKGINFO=$(sed -n "$first_line,$last_line p" "$SBPM_PATH/$SB_PKGINFO")
fi
}
#=================MAIN FUNCTIONS=======================
sbpm_help()
{
echo -e "==================================================="
echo -e "\t $SBPM_DESC"
echo -e "===================================================\n"
echo -e "\t sbpm help \t\t\t show this content"
echo -e "\t sbpm sync \t\t\t sync package data from slackbuilds.org"
echo -e "\t sbpm info <package_name> \t show package information"
echo -e "\t sbpm search <package_name> \t search for a specific package"
echo -e "\t sbpm install <package_name> \t install a package"
echo -e "\n"
exit
}
sbpm_sync()
{
sbpm_config
echo "Syncing..."
wget -c "$SB_URL/$SYSTEM_VERSION/$SB_TAGS" -P "$SBPM_PATH" &&
wget -c "$SB_URL/$SYSTEM_VERSION/$SB_PKGINFO" -P "$SBPM_PATH" &&
echo "Done!"
exit
}
#Function to search packages by tags and package names
sbpm_search()
{
pkgname=$1
echo "Searching package \"$pkgname\"..."
echo -e "==============================================="
echo -e "\t\tPACKAGES FOUND:"
echo -e "===============================================\n"
packages=$(cat "$SBPM_PATH/$SB_TAGS"|grep -i $pkgname|awk -F ":" '{print $1}')
echo -e "$packages\n"
exit
}
#Function to show package information
sbpm_info()
{
pkgname=$1
get_package_info $pkgname
if [ "$PKGEXIST" -eq 1 ]; then
echo -e "$PKGINFO"
else
echo -e "========| PACKAGE NOT FOUND! |========"
fi
exit
}
sbpm_install()
{
pkgname=$1
#Continue only if the package exists
get_package_info $pkgname
if [ "$PKGEXIST" == 0 ]; then
echo -e "========| PACKAGE NOT FOUND! |========"
echo "Run 'sbpm sync' and try again"
exit
fi
echo "Preparing to install..."
pkg_location=$(echo "$PKGINFO" | sed -n "2,2p" | cut -d "." -f2)
pkg_download=$(echo "$PKGINFO" | sed -n "5,5p" | awk -F "DOWNLOAD: " '{print $2}')
#get the x86_64 download link if x32 does not exits
if [ "$pkg_download" == "UNSUPPORTED" ]; then
pkg_download=$(echo "$PKGINFO" | sed -n "6,6p" | awk -F "DOWNLOAD_x86_64: " '{print $2}')
fi
#get the package version to the package name
pkg_version=$(echo "$PKGINFO" | sed -n "4,4p" | awk -F ": " '{print $2}')
pkg_compiled="/tmp/$pkgname-$pkg_version-*.tgz"
echo "Downloading..."
#download the slackbuild file
sb_package="$pkg_location.tar.gz"
wget -c "$SB_URL/$SYSTEM_VERSION/$sb_package" -P "$SBPM_CACHE" --no-check-certificate &&
tar -zxvf "$SBPM_PATH/cache/$pkgname.tar.gz" -C "$SBPM_CACHE"
#download package binary file
IFS=' '
read -ra package_url <<< "$pkg_download"
for url in "${package_url[@]}";
do
pkg_downloaded=0
wget -c "$url" -P "$SBPM_CACHE/$pkgname/" --no-check-certificate &&
pkg_downloaded=1
done
if [ $pkg_downloaded -eq 0 ]; then
echo "Download Error!"
exit
fi
echo "Done!"
echo "Installing..."
chmod +x "$SBPM_CACHE/$pkgname/$pkgname.SlackBuild" &&
cd "$SBPM_CACHE/$pkgname/" &&
sh "$SBPM_CACHE/$pkgname/$pkgname.SlackBuild" &&
/sbin/installpkg $pkg_compiled &&
mv $pkg_compiled $SBPM_PACKAGES
echo "Done!"
}
#=================END MAIN FUNCTIONS===================
if [ "$OPT" == "help" ]; then
sbpm_help
elif [ "$OPT" == "sync" ]; then
sbpm_sync
elif [ "$OPT" == "search" ]; then
sbpm_search $ARG
elif [ "$OPT" == "info" ]; then
sbpm_info $ARG
elif [ "$OPT" == "install" ]; then
sbpm_install $ARG
fi