Skip to content

Commit 7cacb86

Browse files
author
Zadjad Rezai
committed
chore(LinuxUpdate): Implements automation-ability
1 parent c72ceb9 commit 7cacb86

2 files changed

Lines changed: 53 additions & 52 deletions

File tree

LinuxUpdate.sh

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -o pipefail
4+
35
RESET='\033[00m'
46
RED='\033[01;31m'
57
GREEN='\033[01;32m'
@@ -13,30 +15,21 @@ UNDERLINE='\033[4m'
1315
BASE_DISTRO=$(cat /etc/*release | grep -oP 'ID_LIKE=\K\w+')
1416
REAL_DISTRO=$(cat /etc/*release | grep -oP '^ID=\K\w+')
1517

16-
if [ "$BASE_DISTRO" = "" ]; then
18+
if [[ -z "$BASE_DISTRO" ]]; then
1719
BASE_DISTRO=$REAL_DISTRO
1820
fi
1921

2022
function update_arch_based_mirror_lists() {
21-
if [ "$REAL_DISTRO" != "arch" ]; then
22-
sudo pacman-mirrors --interactive --default
23-
else
24-
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
25-
echo "/etc/pacman.d/mirrorlist -> /etc/pacman.d/mirrorlist.backup"
26-
sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist.backup
27-
rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist
28-
fi
23+
reflector --verbose -l 5 --sort rate --save /etc/pacman.d/mirrorlist
2924
}
3025

3126
function install_yay() {
3227
yay -Syu;
3328
if [ "$?" != 0 ]; then
34-
read -p $'\033[1m\033[01;32m::\033[00m\033[1m Install yay? (y/n) \033[00m' -n 1 -r
35-
case $REPLY in
36-
y|Y)
37-
echo -e "\n Installing yay - version 10.1.0"
38-
mkdir /tmp/yay && cd /tmp/yay
39-
URL=$(curl -s https://api.github.com/repos/Jguer/yay/releases/latest | grep "browser_download_url.*${$(uname -m)}.*\.tar\.gz" | cut -d '"' -f 4 )
29+
echo -e "\033[1m\033[01;32m::\033[00m\033[1m Installing latest version of yay \033[00m"
30+
mkdir /tmp/yay && cd /tmp/yay
31+
ARCH=$(uname -m)
32+
URL=$(curl -s https://api.github.com/repos/Jguer/yay/releases/latest | grep "browser_download_url.*${ARCH}.*tar.gz" | cut -d '"' -f 4 )
4033
curl -LJ $URL -o yay.tar.gz
4134
tar xfz yay.tar.gz
4235
sudo mv yay*/yay /usr/local/bin/yay
@@ -46,7 +39,7 @@ function install_yay() {
4639
}
4740

4841
clear
49-
echo -e "${BOLD}Hi, $(whoami), I'm updating ${CYAN}${REAL_DISTRO} ${RESET}${BOLD}for you."
42+
echo -e "${BOLD}Hi, $(whoami), I'm updating ${CYAN}${REAL_DISTRO}${BOLD} ${RESET}for you."
5043
echo -e "${RESET}Please give me sudo-rights."
5144
echo
5245

@@ -57,50 +50,38 @@ if [ "$BASE_DISTRO" = "arch" ]; then
5750

5851
echo -e "${BOLD}Populating the keyring and refreshing it.. ${RESET}"
5952
echo
60-
sudo pacman-key --populate archlinux "$REAL_DISTRO"
53+
54+
populate_keys="sudo pacman-key --populate archlinux"
55+
56+
echo $BASE_DISTRO
57+
echo $REAL_DISTRO
58+
59+
if [[ $REAL_DISTRO != "arch" ]]; then
60+
eval "$populate_keys $REAL_DISTRO"
61+
else
62+
eval $populate_keys
63+
fi
64+
6165
sudo pacman-key --refresh-keys
6266

6367
echo
64-
read -p $'\033[1m\033[01;32m::\033[00m\033[1m Do you want to update the mirrorlist? (y/n) \033[00m' -n 1 -r
68+
echo "Updating the mirrorlist (uses 'reflector').."
6569
echo
66-
case $REPLY in
67-
y|Y)
68-
echo "Updating the mirrorlist.."
69-
echo
70-
update_arch_based_mirror_lists;;
71-
n|N)
72-
echo "Okay, not updating mirrorlist.";;
73-
* ) echo "Invalid";;
74-
esac
75-
76-
sudo pacman -Syu
77-
read -p $'\033[1m\033[01;32m::\033[00m\033[1m Do you want to update AUR packages (yay needed)? (y/n) \033[00m' -n 1 -r
78-
echo
79-
case $REPLY in
80-
y|Y)
81-
install_yay;;
82-
n|N)
83-
echo "Okay, not updating via AUR packages (via yay).";;
84-
* ) echo "Invalid";;
85-
esac
70+
update_arch_based_mirror_lists;
8671
echo
8772

88-
read -p $'\033[1m\033[01;32m::\033[00m\033[1m Do you want to clear pacmans cache? (y/n) \033[00m' -n 1 -r
73+
sudo pacman -Syu --noconfirm
74+
75+
echo -e "\033[1m\033[01;32m::\033[00m\033[1m Updating AUR packages (yay will be installed, if not already there) \033[00m"
76+
install_yay;
77+
8978
echo
90-
case $REPLY in
91-
y|Y)
92-
echo -e "${RED}Removing ${NONE}old stuff from your cache.."
93-
echo
94-
sudo pacman -Sc;;
95-
n|N)
96-
echo "Okay, not clearing pacmans cache.";;
97-
* ) echo "Invalid";;
98-
esac
79+
echo -e "${RED}Removing ${NONE}old stuff from your cache.."
9980
echo
10081

10182
elif [ "$BASE_DISTRO" = "debian" ]; then
102-
sudo apt-get update
103-
sudo apt-get full-upgrade
83+
sudo apt update
84+
sudo apt -y full-upgrade
10485
else
10586
echo -e "Sorry, I don't know how to update ${BASE_DISTRO}, yet."
10687
exit 1

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# LinuxUpdate
22

3+
[![LinuxUpdate on Ubuntu & Arch](https://github.com/Xcalizorz/LinuxUpdate/actions/workflows/test-update.yml/badge.svg)](https://github.com/Xcalizorz/LinuxUpdate/actions/workflows/test-update.yml)
4+
35
This is a small bash script that can update all Arch and Debian Distros, create a new mirrorlist and delete old stuff (only arch).
4-
I didn't like typing all the code in everytime, so I created a small bash script -
6+
I didn't like typing all the code in everytime, so I created a small bash script -
57
maybe you're like me and I can help you with this :)
68
\
79
The plan is to create an easy command-line tool for (almost) all Linux Distros.
@@ -22,6 +24,24 @@ Since I just started looking at bash, it might take a little bit to upload scrip
2224

2325
## Usage
2426

27+
### Prerequisites
28+
29+
#### Arch based
30+
31+
Install the following packages, to make this script work:
32+
33+
```bash
34+
pacman -S sudo reflector
35+
```
36+
37+
#### Debian based
38+
39+
Install the following packages, to make this script work:
40+
41+
```bash
42+
apt install bash sudo
43+
```
44+
2545
### Use the cli
2646

2747
```bash
@@ -50,4 +70,4 @@ Now you have a shortcut and can start the update via double-click.
5070

5171
### Removing old stuff
5272

53-
![Removing old stuff](img/removingStuff.png)
73+
![Removing old stuff](img/removingStuff.png)

0 commit comments

Comments
 (0)