Skip to content

Commit

Permalink
Merge pull request #32 from archetipico/main
Browse files Browse the repository at this point in the history
Add cache system close #31
  • Loading branch information
MasterCruelty authored Jun 23, 2021
2 parents 11d033e + 5259350 commit fcb54c0
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/utils/.cache
src/utils/.md5
11 changes: 8 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
source src/utils/global.sh
printProgress "Setup: starting"

src/utils/cachegen.sh > src/utils/.cache
md5sum src/utils/.cache | cut -d " " -f1 > src/utils/.md5
chmod 775 src/utils/.cache
chmod 775 src/utils/.md5

EXST=$(cat ~/.bashrc | grep -c "updater.sh")
if [[ $EXST -ne 0 ]]; then

printProgress "Alias 'up' already exists. Use 'up' or run './src/updater.sh'."
printProgress "Setup completed"
exit 0
printProgress "Setup completed."
exit 0
else
echo "alias up='bash $(pwd)/src/updater.sh'" >> ~/.bashrc
chmod +x src/updater.sh
printProgress "Alias 'up' added.\nUse 'up' or run './src/updater.sh'."
printProgress "Setup completed."
fi

printf "${RED}"
read -p "Press enter, the process will be killed:\nif your terminal closes, open a new one to see changes." text
printf "${NORMAL}"
Expand Down
10 changes: 6 additions & 4 deletions src/package/archlinux.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/bin/bash

source $(dirname "$(readlink -f "$0")")/utils/global.sh
SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)
PKG="pacman"

printf "${GREEN}\nPackage manager detected: ${RED}Using $PKG${NORMAL}"

printProgress "update: starting"
sudo $PKG -Syy
$PWR $PKG -Syy
printProgress "update: completed"

printProgress "upgrade: starting"
sudo $PKG -Syu
$PWR $PKG -Syu
printProgress "upgrade: completed"

printProgress "clean all: starting"
sudo $PKG -R $($PKG -Qtdq)
$PWR $PKG -R $($PKG -Qtdq)
printProgress "clean all: completed"


Expand Down
12 changes: 7 additions & 5 deletions src/package/debian.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

source $(dirname "$(readlink -f "$0")")/utils/global.sh
SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)
PKG="apt-get"

if [[ $(command -v apt) ]]; then
Expand All @@ -12,19 +14,19 @@ printf "${GREEN}\nPackage manager detected: ${RED}Using $PKG${NORMAL}"


printProgress "update: starting"
sudo $PKG update
$PWR $PKG update
printProgress "update: completed"

printProgress "upgrade: starting"
sudo $PKG upgrade
$PWR $PKG upgrade
printProgress "upgrade: completed"

printProgress "autoclean: starting"
sudo $PKG autoclean
$PWR $PKG autoclean
printProgress "autoclean: completed"

printProgress "autoremove: starting"
sudo $PKG autoremove
$PWR $PKG autoremove
printProgress "autoremove: completed"

printf "\n"
10 changes: 7 additions & 3 deletions src/package/flatpak.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#!/bin/bash

SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)
PKG="flatpak"

printf "${GREEN}\nPackage manager detected: ${RED}Using $PKG${NORMAL}"

printProgress "flatpak update: starting"
sudo $PKG update
$PWR $PKG update
printProgress "flatpak update: completed"

printProgress "flatpak repair: starting"
sudo $PKG repair
$PWR $PKG repair
printProgress "flatpak repair: completed"

printProgress "flatpak uninstall unused extensions: starting"
sudo $PKG uninstall --unused
$PWR $PKG uninstall --unused
printProgress "flatpak uninstall unused extensions: completed"

printf "\n"
10 changes: 6 additions & 4 deletions src/package/gentoo.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/bin/bash

source $(dirname "$(readlink -f "$0")")/utils/global.sh
SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)
PKG="emerge"

printf "${GREEN}\nPackage manager detected: ${RED}Using $PKG${NORMAL}"

printProgress "syncing: starting"
$PKG --sync
$PWR $PKG --sync
printProgress "syncing: completed"

printProgress "update: starting"
$PKG --update --deep --newuse --with-bdeps y @world --ask
$PWR $PKG --update --deep --newuse --with-bdeps y @world --ask
printProgress "update: completed"

printProgress "deepclean: starting"
$PKG --depclean --ask
$PWR $PKG --depclean --ask
revdep-rebuild
printProgress "deepclean: completed"

Expand Down
12 changes: 7 additions & 5 deletions src/package/rpm.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

source $(dirname "$(readlink -f "$0")")/utils/global.sh
SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)
PKG="yum"

if [[ $(command -v dnf) ]]; then
Expand All @@ -11,19 +13,19 @@ fi
printf "${GREEN}\nPackage manager detected: ${RED}Using $PKG${NORMAL}"

printProgress "update: starting"
sudo $PKG update
$PWR $PKG update
printProgress "update: completed"

printProgress "upgrade: starting"
sudo $PKG upgrade
$PWR $PKG upgrade
printProgress "upgrade: completed"

printProgress "autoremove: starting"
sudo $PKG autoremove
$PWR $PKG autoremove
printProgress "autoremove: completed"

printProgress "clean all: starting"
sudo $PKG clean all
$PWR $PKG clean all
printProgress "clean all: completed"

printf "\n"
7 changes: 6 additions & 1 deletion src/package/snap.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash

SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)

printf "${GREEN}\nPackage manager detected: ${RED}Using snap${NORMAL}"

printProgress "snap refresh: starting"
sudo snap refresh
$PWR snap refresh
printProgress "snap refresh: completed"

printf "\n"
10 changes: 6 additions & 4 deletions src/package/termux.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/bin/bash

source $(dirname "$(readlink -f "$0")")/utils/global.sh
SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

PWR=$(source $SRC/utils/checkpwr.sh)
PKG="pkg"

printf "${GREEN}\nPackage manager detected: ${RED}Using $PKG${NORMAL}"

printProgress "update: starting"
$PKG update
$PWR $PKG update
printProgress "update: completed"

printProgress "upgrade: starting"
$PKG upgrade
$PWR $PKG upgrade
printProgress "upgrade: completed"

printProgress "autoclean: starting"
$PKG autoclean
$PWR $PKG autoclean
printProgress "autoclean: completed"

printf "\n"
69 changes: 22 additions & 47 deletions src/updater.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,30 @@
#!/bin/bash

src_path=$(dirname "$(readlink -f "$0")")
source "$src_path"/utils/global.sh

printf "${LOGO}"
if [[ $(stty size | awk '{print $2}') -ge 69 ]]; then
cat "$src_path"/utils/.logo
fi
printf "Running on: $(uname -rs)\n${NORMAL}"

# termux
if [[ $(command -v pkg) ]]; then
source "$src_path"/package/termux.sh
source "$src_path"/utils/trash.sh
exit 0;
#gentoo
elif [[ $(command -v emerge) ]]; then
source "$src_path"/package/gentoo.sh
source "$src_path"/utils/trash.sh
exit 0;
fi

# check privileges
source "$src_path"/utils/privileges.sh

# snap
if [[ $(command -v snap) ]]; then
source "$src_path"/package/snap.sh
fi

# flatpak
if [[ $(command -v flatpak) ]]; then
source "$src_path"/package/flatpak.sh
SRC=$(dirname "$(readlink -f "$0")")
source $SRC/utils/global.sh

if [[ -f "$SRC/utils/.cache" ]]; then
HASH=$(md5sum "$SRC/utils/.cache" | cut -d " " -f1)
if [[ $HASH != $(cat $SRC/utils/.md5) ]]; then
md5sum $SRC/utils/.cache | cut -d " " -f1 > $SRC/utils/.md5
fi
else
$SRC/utils/cachegen.sh > $SRC/utils/.cache
md5sum $SRC/utils/.cache | cut -d " " -f1 > $SRC/utils/.md5
chmod 775 $SRC/utils/.cache
fi
chmod 775 $SRC/utils/.md5

# debian
if [[ $(command -v apt-get) ]]; then
source "$src_path"/package/debian.sh
# rpm
elif [[ $(command -v yum) ]]; then
source "$src_path"/package/rpm.sh
# arch
elif [[ $(command -v pacman) ]]; then
source "$src_path"/package/archlinux.sh
# not found
else
printf "${RED}System not supported${NORMAL}"
printf "$LOGO"
if [[ $(stty size | awk '{print $2}') -ge 69 ]]; then
cat $SRC/utils/.logo
fi
printf "Running on: $(uname -rs)\n$NORMAL"

# check trash
source "$src_path"/utils/trash.sh
while read line; do
if [[ "$line" != "" ]]; then
source $SRC/$line.sh;
fi
done < $SRC/utils/.cache

printf "\n"
exit 0
45 changes: 45 additions & 0 deletions src/utils/cachegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

### generates default caches ###
OUT=""

OUT+="utils/privileges\n"

# arch
if [[ $(command -v pacman) ]]; then
OUT+="package/archlinux\n"
fi

# debian
if [[ $(command -v apt-get) ]]; then
OUT+="package/debian\n"
fi

# flatpak
if [[ $(command -v flatpak) ]]; then
OUT+="package/flatpak\n"
fi

#gentoo
if [[ $(command -v emerge) ]]; then
OUT+="package/gentoo\n"
fi

# rpm
if [[ $(command -v yum) ]]; then
OUT+="package/rpm\n"
fi

# snap
if [[ $(command -v snap) ]]; then
OUT+="package/snap\n"
fi

# termux
if [[ $(command -v pkg) ]]; then
OUT+="package/termux\n"
fi

OUT+="utils/trash"

echo -e "$OUT"
8 changes: 8 additions & 0 deletions src/utils/checkpwr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

PWR=""
if [[ $(grep -c "utils/privileges" $(dirname "$(readlink -f "$0")")/utils/.cache) -gt 0 ]]; then
PWR="sudo"
fi

echo "$PWR"
4 changes: 2 additions & 2 deletions src/utils/global.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ RED="\e[1;91;49m"

printProgress() {
if [[ "$1" == *starting ]] || [[ "$1" == *privileges ]] || [[ "$1" == *already* ]] || [[ "$1" == *aborting* ]]; then
printf "${RED}\n$1\n${NORMAL}"
printf "$RED\n$1\n$NORMAL"
else
printf "${GREEN}$1\n${NORMAL}"
printf "$GREEN$1\n$NORMAL"
fi
}
14 changes: 4 additions & 10 deletions src/utils/trash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
source $(dirname "$(readlink -f "$0")")/utils/global.sh

if [[ -d ~/.local/share/Trash/files ]]; then
printf "${RED}\nShowing files in .local/share/Trash/files${NORMAL}\n"
ls -hl ~/.local/share/Trash/files
printf "Should I clean Trash? "
read -p "[y/n]: " ANSW
if [[ "$ANSW" == "y" ]]; then
sudo rm -rf ~/.local/share/Trash/*
printProgress "Trash: cleaned"
else
printProgress "Trash: not cleaned"
fi
printf "$RED\nShowing files in .local/share/Trash/files$NORMAL\n"
ls -Ahl ~/.local/share/Trash/files
sudo rm -rf ~/.local/share/Trash/*
printProgress "Trash: cleaned"
else
printProgress "\nTrash is empty, nothing to clean"
fi
Loading

0 comments on commit fcb54c0

Please sign in to comment.