@@ -8,80 +8,108 @@ set -e
8
8
OK=" $( tput setaf 2) [OK]$( tput sgr0) "
9
9
ERROR=" $( tput setaf 1) [ERROR]$( tput sgr0) "
10
10
NOTE=" $( tput setaf 3) [NOTE]$( tput sgr0) "
11
+ INFO=" $( tput setaf 4) [INFO]$( tput sgr0) "
11
12
WARN=" $( tput setaf 1) [WARN]$( tput sgr0) "
12
13
CAT=" $( tput setaf 6) [ACTION]$( tput sgr0) "
13
- MAGENTA=$( tput setaf 5)
14
- WARNING=$( tput setaf 1)
15
- YELLOW=$( tput setaf 3)
16
- RESET=$( tput sgr0)
17
-
14
+ MAGENTA=" $( tput setaf 5) "
15
+ ORANGE=" $( tput setaf 214) "
16
+ WARNING=" $( tput setaf 1) "
17
+ YELLOW=" $( tput setaf 3) "
18
+ GREEN=" $( tput setaf 2) "
19
+ BLUE=" $( tput setaf 4) "
20
+ SKY_BLUE=" $( tput setaf 6) "
21
+ RESET=" $( tput sgr0) "
18
22
19
23
# Create Directory for Install Logs
20
24
if [ ! -d Install-Logs ]; then
21
25
mkdir Install-Logs
22
26
fi
23
27
24
- # Function for installing packages
28
+ # Show progress function
29
+ show_progress () {
30
+ local pid=$1
31
+ local package_name=$2
32
+ local spin_chars=(" ●○○○○○○○○○" " ○●○○○○○○○○" " ○○●○○○○○○○" " ○○○●○○○○○○" " ○○○○●○○○○" \
33
+ " ○○○○○●○○○○" " ○○○○○○●○○○" " ○○○○○○○●○○" " ○○○○○○○○●○" " ○○○○○○○○○●" )
34
+ local i=0
35
+
36
+ tput civis
37
+ printf " \r${NOTE} Installing ${YELLOW} %s${RESET} ..." " $package_name "
38
+
39
+ while ps -p $pid & > /dev/null; do
40
+ printf " \r${NOTE} Installing ${YELLOW} %s${RESET} %s" " $package_name " " ${spin_chars[i]} "
41
+ i=$(( (i + 1 ) % 10 ))
42
+ sleep 0.3
43
+ done
44
+
45
+ printf " \r${NOTE} Installing ${YELLOW} %s${RESET} ... Done!%-20s \n" " $package_name " " "
46
+ tput cnorm
47
+ }
48
+
49
+
50
+
51
+ # Function to install packages with pacman
25
52
install_package_pacman () {
26
- # Checking if package is already installed
53
+ # Check if package is already installed
27
54
if pacman -Q " $1 " & > /dev/null ; then
28
- echo -e " ${OK } $1 is already installed. Skipping..."
55
+ echo -e " ${INFO } ${MAGENTA} $1 ${RESET} is already installed. Skipping..."
29
56
else
30
- # Package not installed
31
- echo -e " ${NOTE} Installing $1 ..."
32
- sudo pacman -S --noconfirm --needed " $1 " 2>&1 | tee -a " $LOG "
33
- # Making sure package is installed
57
+ # Run pacman and redirect all output to a log file
58
+ (
59
+ stdbuf -oL sudo pacman -S --noconfirm " $1 " 2>&1
60
+ ) >> " $LOG " 2>&1 &
61
+ PID=$!
62
+ show_progress $PID " $1 "
63
+
64
+ # Double check if package is installed
34
65
if pacman -Q " $1 " & > /dev/null ; then
35
- echo -e " \e[1A\e[K ${OK} Package ${YELLOW} $1 ${RESET} has been successfully installed!"
66
+ echo -e " ${OK} Package ${YELLOW} $1 ${RESET} has been successfully installed!"
36
67
else
37
- # Something is missing, exiting to review log
38
- echo -e " ${ERROR} $1 failed to install. Please check the $LOG . You may need to install manually."
39
- exit 1
68
+ echo -e " \n${ERROR} ${YELLOW} $1 ${RESET} failed to install. Please check the $LOG . You may need to install manually."
40
69
fi
41
70
fi
42
71
}
43
72
44
-
45
73
ISAUR=$( command -v yay || command -v paru)
46
74
47
- # Function for installing packages
75
+ # Function to install packages with either yay or paru
48
76
install_package () {
49
- # Checking if package is already installed
50
77
if $ISAUR -Q " $1 " & >> /dev/null ; then
51
- echo -e " ${OK } $1 is already installed. Skipping..."
78
+ echo -e " ${INFO } ${MAGENTA} $1 ${RESET} is already installed. Skipping..."
52
79
else
53
- # Package not installed
54
- echo -e " ${NOTE} Installing $1 ..."
55
- $ISAUR -S --noconfirm --needed " $1 " 2>&1 | tee -a " $LOG "
56
- # Making sure package is installed
80
+ (
81
+ stdbuf -oL $ISAUR -S --noconfirm " $1 " 2>&1
82
+ ) >> " $LOG " 2>&1 &
83
+ PID=$!
84
+ show_progress $PID " $1 "
85
+
86
+ # Double check if package is installed
57
87
if $ISAUR -Q " $1 " & >> /dev/null ; then
58
- echo -e " \e[1A\e[K ${OK} Package ${YELLOW} $1 ${RESET} has been successfully installed!"
88
+ echo -e " ${OK} Package ${YELLOW} $1 ${RESET} has been successfully installed!"
59
89
else
60
90
# Something is missing, exiting to review log
61
- echo -e " \e[1A\e[K${ERROR} $1 failed to install :( , please check the install.log. You may need to install manually! Sorry I have tried :("
62
- exit 1
91
+ echo -e " \n${ERROR} ${YELLOW} $1 ${RESET} failed to install :( , please check the install.log. You may need to install manually! Sorry I have tried :("
63
92
fi
64
93
fi
65
94
}
66
95
67
- # Function for uninstalling packages
96
+ # Function for removing packages
68
97
uninstall_package () {
69
98
local pkg=" $1 "
70
99
71
100
# Checking if package is installed
72
- if pacman -Qi " $pkg " & >> /dev/null ; then
73
- # Package is installed
74
- echo -e " ${NOTE} Uninstalling $pkg ..."
101
+ if pacman -Qi " $pkg " & > /dev/null; then
102
+ echo -e " ${NOTE} removing $pkg ..."
75
103
sudo pacman -R --noconfirm " $pkg " 2>&1 | tee -a " $LOG " | grep -v " error: target not found"
76
- # Check if the package was uninstalled
77
- if ! pacman -Qi " $pkg " & >> /dev/null ; then
78
- echo -e " \e[1A\e[K${OK} $pkg was uninstalled ."
104
+
105
+ if ! pacman -Qi " $pkg " & > /dev/null; then
106
+ echo -e " \e[1A\e[K${OK} $pkg removed ."
79
107
else
80
- echo -e " \e[1A\e[K${ERROR} $pkg failed to uninstall. Please check the log ."
81
- return 1
108
+ echo -e " \e[1A\e[K${ERROR} $pkg Removal failed. No actions required ."
109
+ return 1
82
110
fi
83
111
else
84
- echo -e " ${NOTE} $pkg is not installed, skipping uninstallation ."
112
+ echo -e " ${INFO} Package $pkg not installed, skipping."
85
113
fi
86
- return 0
87
- }
114
+ return 0
115
+ }
0 commit comments