Compare commits
	
		
			16 Commits
		
	
	
		
			0.1.1
			...
			9c36cef1e1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9c36cef1e1 | |||
| 73f7e37670 | |||
| af686fe6c0 | |||
| ba07f6275d | |||
| 8e2bdd88d3 | |||
| 8b23dc96a3 | |||
| 7b3de6cef0 | |||
| 2c209fd7a0 | |||
| b1306a73b4 | |||
| e2789d200b | |||
| eddbe307c2 | |||
| 3e22f4ebbd | |||
| cdc17a329b | |||
| fd49c9e953 | |||
| eeaee974bd | |||
| 0df0a8dd6e | 
							
								
								
									
										23
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,15 +1,28 @@ | |||||||
| # pman.sh | # pman.sh | ||||||
| A `pacman` helper script, because you forget the stupid flags | A `pacman` helper script, because you forget all the stupid flags | ||||||
|  |  | ||||||
| ## Usage / Features: | ## Usage / Features: | ||||||
|  | - aur/yay | ||||||
| - search | - search | ||||||
|  | - info | ||||||
|  | - localinfo | ||||||
|  | - provides | ||||||
|  | - providefiles | ||||||
|  | - installed | ||||||
|  | - install | ||||||
| - update | - update | ||||||
| - upgradable | - upgradable | ||||||
| - upgrade | - upgrade | ||||||
| - install | - remove | ||||||
| - provides | - purge | ||||||
|  | - clean | ||||||
|  | - reflector | ||||||
| - config | - config | ||||||
|  |  | ||||||
| `config` is the only flag that is not appended to `pacman`, instead it resolves to `nano /etc/pacman.conf`. | `reflector` and `config` are the only flag that are not appended to `pacman` (or `yay`)<br> | ||||||
|  | instead `reflector` resolves to `reflector` with the previously used parameters stored in `/etc/pacman.d/mirrorlist`<br> | ||||||
|  | and `config` resolves to `nano /etc/pacman.conf`. | ||||||
|  |  | ||||||
| `sudo` gets prepended automatically if the command requires it and if installed - no, there is no check if your user is in the `sudo` group, if you download this script you should already be, or know you can only use part of this utility | `sudo` gets prepended automatically if the command requires root privileges, if the UID is not 0 (you are not `root`) and if `sudo` installed.<br> | ||||||
|  | no, there is no check if your user is in the `sudo` group, if you download this script you should already be, or know you can only use part of this utility<br> | ||||||
|  | tho such a feature is planned, to make the script truly ubiquitus. | ||||||
|   | |||||||
							
								
								
									
										139
									
								
								pman.sh
									
									
									
									
									
								
							
							
						
						
									
										139
									
								
								pman.sh
									
									
									
									
									
								
							| @@ -7,6 +7,24 @@ command="" | |||||||
| more_arguments=false | more_arguments=false | ||||||
| su_needed=false | su_needed=false | ||||||
|  |  | ||||||
|  | # If sudo is needed and necessary (and installed), prepend it, if not installed throw error | ||||||
|  | check_sudo() { | ||||||
|  |   if [ "$su_needed" = "true" ] && [ "$UID" != 0 ]; then | ||||||
|  |     if command -v "sudo" &>/dev/null; then | ||||||
|  |       command="sudo $command" | ||||||
|  |     else | ||||||
|  |       echo "sudo command needed but not found" > /dev/stderr | ||||||
|  |       exit 1 | ||||||
|  |     fi | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # Execute the command | ||||||
|  | execute_command() { | ||||||
|  |   check_sudo | ||||||
|  |   $command $command_args "${@}" | ||||||
|  | } | ||||||
|  |  | ||||||
| # Check if yay (aur) | # Check if yay (aur) | ||||||
| if [ "$command_args" = "yay" ] || [ "$command_args" = "aur" ]; then | if [ "$command_args" = "yay" ] || [ "$command_args" = "aur" ]; then | ||||||
|   command="yay" |   command="yay" | ||||||
| @@ -18,6 +36,15 @@ elif [ "$command_args" = "config" ]; then | |||||||
|   command="nano" |   command="nano" | ||||||
|   command_args="/etc/pacman.conf" |   command_args="/etc/pacman.conf" | ||||||
|   su_needed=true |   su_needed=true | ||||||
|  | elif [ "$command_args" = "reflector" ]; then | ||||||
|  |   command="reflector" | ||||||
|  |   command_args=$(cat /etc/pacman.d/mirrorlist 2>/dev/null | grep -e "With.*reflector" | sed 's/#.*reflector //') | ||||||
|  |   # Check if reflector was actually used to generate the mirrorlist | ||||||
|  |   if [ "$command_args" = "" ]; then | ||||||
|  |     echo "Error: reflector was not used to generate mirrorlist or mirrorlist location differ from standard" | ||||||
|  |     exit 1 | ||||||
|  |   fi | ||||||
|  |   su_needed=true | ||||||
| fi | fi | ||||||
|  |  | ||||||
| # If command is empty, command is pacman | # If command is empty, command is pacman | ||||||
| @@ -27,29 +54,86 @@ if [ "$command" = "" ]; then | |||||||
| fi | fi | ||||||
|  |  | ||||||
| # Evaluate the command arguments | # Evaluate the command arguments | ||||||
| if [ "$command_args" = "search" ]; then | case "$command_args" in | ||||||
|  |   "search") | ||||||
|     command_args="-Ss" |     command_args="-Ss" | ||||||
| elif [ "$command_args" = "update" ]; then |     ;; | ||||||
|   command_args="-Sy" |   "info") | ||||||
|   if [ "$command" = "pacman" ]; then |     command_args="-Si" | ||||||
|  |     ;; | ||||||
|  |   "localinfo") | ||||||
|  |     command_args="-Qi" | ||||||
|  |     ;; | ||||||
|  |   "provides") | ||||||
|  |     # Update the cache | ||||||
|     su_needed=true |     su_needed=true | ||||||
|   fi |     command_args="-Fy" | ||||||
| elif [ "$command_args" = "upgradable" ]; then |     execute_command "${@}" | ||||||
|   command_args="-Qu" |  | ||||||
| elif [ "$command_args" = "upgrade" ]; then |     su_needed=false | ||||||
|   command_args="-Syu" |     command_args="-F" | ||||||
|   if [ "$command" = "pacman" ]; then |     ;; | ||||||
|  |   "providefiles") | ||||||
|  |     # Update the cache | ||||||
|     su_needed=true |     su_needed=true | ||||||
|   fi |     command_args="-Fy" | ||||||
| elif [ "$command_args" = "install" ]; then |     execute_command "${@}" | ||||||
|  |  | ||||||
|  |     su_needed=false | ||||||
|  |     command_args="-Fl" | ||||||
|  |     ;; | ||||||
|  |   "installed") | ||||||
|  |     command_args="-Q" | ||||||
|  |     ;; | ||||||
|  |   "install") | ||||||
|     command_args="-S" |     command_args="-S" | ||||||
|     if [ "$command" = "pacman" ]; then |     if [ "$command" = "pacman" ]; then | ||||||
|       su_needed=true |       su_needed=true | ||||||
|     fi |     fi | ||||||
| elif [ "$command_args" = "provides" ]; then |     ;; | ||||||
|   command_args="-F" |   "update") | ||||||
| elif [ "$more_arguments" = "true" ]; then |     command_args="-Sy" | ||||||
|   echo "Invalid command: \"$command $command_args\"" |     if [ "$command" = "pacman" ]; then | ||||||
|  |       su_needed=true | ||||||
|  |     fi | ||||||
|  |     execute_command "${@}" | ||||||
|  |  | ||||||
|  |     su_needed=false | ||||||
|  |     command_args="-Qu" | ||||||
|  |     echo | ||||||
|  |     echo "$(execute_command "${@}" | wc -l) packages are available for update" | ||||||
|  |     exit 0 | ||||||
|  |     ;; | ||||||
|  |   "upgradable") | ||||||
|  |     command_args="-Qu" | ||||||
|  |     ;; | ||||||
|  |   "upgrade") | ||||||
|  |     command_args="-Syu" | ||||||
|  |     if [ "$command" = "pacman" ]; then | ||||||
|  |       su_needed=true | ||||||
|  |     fi | ||||||
|  |     ;; | ||||||
|  |   "remove") | ||||||
|  |     command_args="-Rs" | ||||||
|  |     if [ "$command" = "pacman" ]; then | ||||||
|  |       su_needed=true | ||||||
|  |     fi | ||||||
|  |     ;; | ||||||
|  |   "purge") | ||||||
|  |     command_args="-Rns" | ||||||
|  |     if [ "$command" = "pacman" ]; then | ||||||
|  |       su_needed=true | ||||||
|  |     fi | ||||||
|  |     ;; | ||||||
|  |   "clean") | ||||||
|  |     command_args="-Scc" | ||||||
|  |     if [ "$command" = "pacman" ]; then | ||||||
|  |       su_needed=true | ||||||
|  |     fi | ||||||
|  |     ;; | ||||||
|  |   *) | ||||||
|  |     if [ "$more_arguments" = "true" ]; then | ||||||
|  |       echo "Invalid command: \"$command_args\"" | ||||||
|       echo |       echo | ||||||
|       echo "Usage: pman <command> [args...]" |       echo "Usage: pman <command> [args...]" | ||||||
|       echo "Available commands:" |       echo "Available commands:" | ||||||
| @@ -57,17 +141,24 @@ elif [ "$more_arguments" = "true" ]; then | |||||||
|       echo "               (aur packages - all the normal operations except config are available)" |       echo "               (aur packages - all the normal operations except config are available)" | ||||||
|       echo "  aur (yay)    - yay              | same as \"yay\"" |       echo "  aur (yay)    - yay              | same as \"yay\"" | ||||||
|       echo "  search       - pacman -Ss       | search packages" |       echo "  search       - pacman -Ss       | search packages" | ||||||
|  |       echo "  info         - pacman -Si       | show package information" | ||||||
|  |       echo "  localinfo    - pacman -Qi       | show local package information" | ||||||
|  |       echo "  provides     - pacman -F        | list packages that provide file" | ||||||
|  |       echo "  providefiles - pacman -Fl       | list files provided by package" | ||||||
|  |       echo "  installed    - pacman -Q        | list installed packages" | ||||||
|  |       echo "  install      - pacman -S        | install packages" | ||||||
|       echo "  update       - pacman -Sy       | updates the repositories" |       echo "  update       - pacman -Sy       | updates the repositories" | ||||||
|       echo "  upgradable   - pacman -Qu       | list available upgrades" |       echo "  upgradable   - pacman -Qu       | list available upgrades" | ||||||
|       echo "  upgrade      - pacman -Syu      | upgrades your system" |       echo "  upgrade      - pacman -Syu      | upgrades your system" | ||||||
|   echo "  provides   - pacman -F        | list packages that provide file" |       echo "  remove       - pacman -Rs       | remove packages & dependencies" | ||||||
|  |       echo "  purge        - pacman -Rns      | remove packages, dependencies & conf" | ||||||
|  |       echo "  clean        - pacman -Scc      | remove all package files & trash" | ||||||
|  |       echo "  reflector    - mirrorlist       | refresh the mirrorlist with reflector (if used)" | ||||||
|  |       echo "               (do not use if file location differ from default /etc/pacman.d/mirrorlist)" | ||||||
|       echo "  config       - /etc/pacman.conf | edits pacman configuration" |       echo "  config       - /etc/pacman.conf | edits pacman configuration" | ||||||
|       exit 1 |       exit 1 | ||||||
| fi |     fi | ||||||
|  |     ;; | ||||||
|  | esac | ||||||
|  |  | ||||||
| # If sudo is needed and necessary (and installed), prepend it | execute_command "${@}" | ||||||
| if [ "$su_needed" = "true" ] && [ "$UID" != 0 ] && command -v "sudo" &>/dev/null; then |  | ||||||
|   sudo $command $command_args "${@}" |  | ||||||
| else |  | ||||||
|   $command $command_args "${@}" |  | ||||||
| fi |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user