|
1 | 1 | #!/bin/bash
|
2 | 2 | # Solus User Repo Tool by Justin Zobel (justin@solus-project.com)
|
3 | 3 | # License GPL-2.0
|
4 |
| -# Version 0.3 |
| 4 | +# Version 0.4 |
5 | 5 |
|
6 | 6 | # Colours
|
7 | 7 | red="\e[31m"
|
@@ -49,6 +49,7 @@ function createpackagerfile {
|
49 | 49 | }
|
50 | 50 |
|
51 | 51 | function install {
|
| 52 | + cd /tmp/ur |
52 | 53 | # Check if pkgname blank
|
53 | 54 | if [[ $package == "" ]]
|
54 | 55 | then
|
@@ -113,14 +114,28 @@ function listinstalled {
|
113 | 114 | then
|
114 | 115 | echo -e "${yellow}Notice: ${white}Database shows no packages installed."
|
115 | 116 | else
|
116 |
| - cat /tmp/ur/installed |
| 117 | + echo -e "There are ${yellow}$(cat /tmp/ur/installed | wc -l) ${white}package(s) installed." |
| 118 | + while read p;do |
| 119 | + pkg=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 1) |
| 120 | + ver=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 2) |
| 121 | + rel=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 3) |
| 122 | + echo -e ${yellow}Package: ${white}$pkg ${yellow}Version: ${white}${ver} ${yellow}Release: ${white}$rel |
| 123 | + done </tmp/ur/installed |
117 | 124 | fi
|
118 | 125 | }
|
119 | 126 |
|
120 | 127 | function listpackages {
|
121 | 128 | # List packages that are available from the User Repo
|
122 | 129 | echo -e "${yellow}Notice: ${white}Listing available packages."
|
123 |
| - cat /usr/share/solus-user-repo/repo-index | more |
| 130 | + echo "" |
| 131 | + echo -e "There are ${yellow}$(cat /usr/share/solus-user-repo/repo-index | wc -l) ${white}packages available:" |
| 132 | + # Get name and version out |
| 133 | + while read p;do |
| 134 | + pkg=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 1) |
| 135 | + ver=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 2) |
| 136 | + rel=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 3) |
| 137 | + echo -e ${yellow}Package: ${white}$pkg ${yellow}Version: ${white}${ver} ${yellow}Release: ${white}$rel |
| 138 | + done </usr/share/solus-user-repo/repo-index |
124 | 139 | }
|
125 | 140 |
|
126 | 141 | function printhelp {
|
@@ -182,103 +197,86 @@ function search {
|
182 | 197 | then
|
183 | 198 | # Advise multiple items found
|
184 | 199 | echo -e "${yellow}Notice: ${white}Found $(grep -i $package /usr/share/solus-user-repo/repo-index | wc -l) items:"
|
185 |
| - grep -i $package /usr/share/solus-user-repo/repo-index |
| 200 | + grep -i $package /usr/share/solus-user-repo/repo-index > /tmp/ur/searchfound |
| 201 | + while read p;do |
| 202 | + pkg=$(echo $p | cut -d, -f 1) |
| 203 | + ver=$(echo $p | cut -d, -f 2) |
| 204 | + rel=$(echo $p | cut -d, -f 3) |
| 205 | + echo -e ${yellow}Package: ${white}$pkg ${yellow}Version: ${white}${ver} ${yellow}Release: ${white}$rel |
| 206 | + done </tmp/ur/searchfound |
186 | 207 | else
|
187 | 208 | # Advise singular item found
|
188 | 209 | echo -e "${yellow}Notice: ${white}Found 1 item:"
|
189 |
| - grep -i $package /usr/share/solus-user-repo/repo-index |
| 210 | + grep -i $package /usr/share/solus-user-repo/repo-index > /tmp/ur/searchfound |
| 211 | + while read p;do |
| 212 | + pkg=$(echo $p | cut -d, -f 1) |
| 213 | + ver=$(echo $p | cut -d, -f 2) |
| 214 | + rel=$(echo $p | cut -d, -f 3) |
| 215 | + echo -e ${yellow}Package: ${white}$pkg ${yellow}Version: ${white}${ver} ${yellow}Release: ${white}$rel |
| 216 | + done </tmp/ur/searchfound |
190 | 217 | fi
|
191 | 218 | fi
|
192 | 219 | }
|
193 | 220 |
|
194 | 221 | function updaterepo {
|
195 | 222 | # Update repo database from server to local disk.
|
| 223 | + echo -e "${yellow}Notice: ${white}Updating Repository..." |
196 | 224 | wget -q http://solus-us.tk/ur/index -O /usr/share/solus-user-repo/repo-index
|
197 |
| - echo Repository Database Updated. |
| 225 | + echo -e "${yellow}Notice: ${white}Repository Updated." |
198 | 226 | }
|
199 | 227 |
|
200 | 228 | function upgrade {
|
| 229 | + # Firstly update the repo index so we have the right info |
| 230 | + updaterepo |
201 | 231 | # Check if we're upgrading all or one specific package, or all with skipyn
|
202 | 232 | if [[ $package == "-y" ]] || [[ $package == "" ]]
|
| 233 | + then upgrademultiple |
| 234 | + else upgradesingle |
| 235 | + fi |
| 236 | +} |
| 237 | + |
| 238 | +function upgrademultiple { |
| 239 | + # Get installed packages into /tmp/ur/installed |
| 240 | + grep "=1" /usr/share/solus-user-repo/database | sed 's/=1//g' > /tmp/ur/installed |
| 241 | + # Find if a new release is in repo and annoucce version diff |
| 242 | + while read $p;do |
| 243 | + newver=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 2) |
| 244 | + newrel=$(grep $p /usr/share/solus-user-repo/repo-index | cut -d, -f 3) |
| 245 | + installedrelease=$(eopkg info $p | grep Name | cut -d: -f 4 | sed 's/ //g') |
| 246 | + installedversion=$(eopkg info $p | grep Name | cut -d: -f 3 | cut -d, -f 1 | sed 's/ //g') |
| 247 | + if [[ $newrel -gt $installedrelease ]] |
| 248 | + then |
| 249 | + echo -e "${yellow}Package: ${white}$pkg ${yellow}Version: ${white}$oldver ${yellow}Release: ${white}$oldrel to be upgraded to ${yellow}Version: ${white}$ver ${yellow}Release: ${white}$rel" |
| 250 | + echo $p >> /tmp/ur/upgradethese |
| 251 | + fi |
| 252 | + done </tmp/ur/installed |
| 253 | + # Upgrade those suckers |
| 254 | + if [[ ! -f /tmp/ur/upgradethese ]] |
| 255 | + then |
| 256 | + echo -e "${yellow}Notice: ${white}No packages found that require upgrade." |
| 257 | + else |
| 258 | + while read $p;do |
| 259 | + echo -e "${yellow}Notice: ${white}Upgrading ${yellow}${p}" |
| 260 | + install $P |
| 261 | + done </tmp/ur/upgradethese |
| 262 | + fi |
| 263 | +} |
| 264 | + |
| 265 | +function upgradesingle { |
| 266 | + if [[ $(cat /usr/share/solus-user-repo/repo-index | grep $package | wc -l) -eq 0 ]] |
203 | 267 | then
|
204 |
| - echo -e "${yellow}Notice: ${white}Checking what packages need upgrading." |
205 |
| - # Check what packages are installed |
206 |
| - while read p; do |
207 |
| - if [[ $(echo $p | cut -d= -f 2) == 1 ]] |
208 |
| - then |
209 |
| - # Push package names to upgrade list |
210 |
| - echo $(echo $p | cut -d= -f 1) >> /tmp/ur/upgrades |
211 |
| - fi |
212 |
| - done </usr/share/solus-user-repo/database |
213 |
| - # Check if anything found |
214 |
| - if [ -f /tmp/ur/upgrades ]; |
| 268 | + echo -e "${red}Error: ${white} $package not found." |
| 269 | + else |
| 270 | + newver=$(cat /usr/share/solus-user-repo/repo-index | grep $package | cut -d, -f 2) |
| 271 | + newrel=$(cat /usr/share/solus-user-repo/repo-index | grep $package | cut -d, -f 3) |
| 272 | + installedrelease=$(eopkg info $package | grep Name | cut -d: -f 4 | sed 's/ //g') |
| 273 | + installedversion=$(eopkg info $package | grep Name | cut -d: -f 3 | cut -d, -f 1 | sed 's/ //g') |
| 274 | + if [[ $installedrelease -ge $newrel ]] |
215 | 275 | then
|
216 |
| - # Do release number checks against packages |
217 |
| - while read a; do |
218 |
| - cd /tmp/ur |
219 |
| - wget -q http://solus-us.tk/ur/$a.yml |
220 |
| - reporelease=$(cat $a.yml | grep release | cut -d: -f 2 | sed 's/ //g') |
221 |
| - repoversion=$(cat $a.yml | grep version | cut -d: -f 2 | sed 's/ //g') |
222 |
| - installedrelease=$(eopkg info $a | grep Name | cut -d: -f 4 | sed 's/ //g') |
223 |
| - installedversion=$(eopkg info $a | grep Name | cut -d: -f 3 | cut -d, -f 1 | sed 's/ //g') |
224 |
| - if [[ $reporelease -gt $installedrelease ]] |
225 |
| - # Push package info to addtoupgradelist function to display pretty output later |
226 |
| - then addtoupgradelist $a $reporelease $repoversion $installedrelease $installedversion |
227 |
| - fi |
228 |
| - done </tmp/ur/upgrades |
229 |
| - echo -e "${yellow}Notice: ${white}Upgrade checks done." |
230 |
| - # Check if any were found that were higher version |
231 |
| - if [ -f /tmp/ur/doup ] |
232 |
| - then |
233 |
| - echo -e "${yellow}Notice: ${white}The following package(s) will be upgraded:" |
234 |
| - # Get a list of packages to upgrade |
235 |
| - while read m; do |
236 |
| - # Get package info from $m and get old and new release number and version |
237 |
| - pkg=$(echo $m | cut -d, -f 1) |
238 |
| - ver=$(echo $m | cut -d, -f 2) |
239 |
| - rel=$(echo $m | cut -d, -f 3) |
240 |
| - oldver=$(echo $m | cut -d, -f 4) |
241 |
| - oldrel=$(echo $m | cut -d, -f 5) |
242 |
| - echo -e "${yellow}Package: ${white}$pkg ${yellow}Version: ${white}$oldver ${yellow}Release: ${white}$oldrel to be upgraded to ${yellow}Version: ${white}$ver ${yellow}Release: ${white}$rel" |
243 |
| - done </tmp/ur/urlist |
244 |
| - # Check for skipyn |
245 |
| - if [[ $package == "-y" ]] |
246 |
| - then |
247 |
| - # Do the upgrades |
248 |
| - while read b; do |
249 |
| - installpackage $b |
250 |
| - done </tmp/ur/doup |
251 |
| - else |
252 |
| - read -p "Do you wish to proceed? (y/n) " -n 1 -r |
253 |
| - if [[ $REPLY =~ ^[Yy]$ ]] |
254 |
| - then |
255 |
| - # Do the upgrades |
256 |
| - while read b; do |
257 |
| - installpackage $b |
258 |
| - done </tmp/ur/doup |
259 |
| - fi |
260 |
| - fi |
261 |
| - else |
262 |
| - echo -e "${yellow}Notice: ${white}No packages need upgrading." |
263 |
| - fi |
| 276 | + echo -e "${yellow}Notice: ${white}$package is already up to date, no upgrade needed." |
264 | 277 | else
|
265 |
| - echo -e "${yellow}Notice: ${white}No packages need upgrading." |
266 |
| - fi |
267 |
| - else |
268 |
| - # Single package upgrade, package name specified |
269 |
| - cd /tmp/ur |
270 |
| - wget -q http://solus-us.tk/ur/$package.yml |
271 |
| - newversion=$(cat $package.yml | grep version | cut -d: -f 2 | sed 's/ //g') |
272 |
| - # Confirmation |
273 |
| - if [[ $skipyn == "1" ]] |
274 |
| - then installpackage $package |
275 |
| - else |
276 |
| - echo -e "${yellow}Notice: ${white}Package built." |
277 |
| - read -p "Do you wish to proceed? (y/n) " -n 1 -r |
278 |
| - if [[ $REPLY =~ ^[Yy]$ ]] |
279 |
| - then |
280 |
| - installpackage $package |
281 |
| - fi |
| 278 | + echo "$package will be updated to version $newver, release number $newrel" |
| 279 | + install $package |
282 | 280 | fi
|
283 | 281 | fi
|
284 | 282 | }
|
|
0 commit comments