excalibur1234 / pacui

Bash script providing advanced Pacman and Yay/Pikaur/Aurman/Pakku/Trizen/Pacaur/Pamac-cli functionality in a simple UI
GNU General Public License v3.0
169 stars 13 forks source link

added reflector commands. edited keyring related commands and help output #9

Closed thefallenrat closed 7 years ago

thefallenrat commented 7 years ago

Hey @excalibur1234 I just created a pull request that based on my suggestion from #5

But I still need some help on the keyring commands :

                # Manually download and install all keyring..
                  echo "Installing all keyring ..."
                  cache=$(awk -F '=' '/^CacheDir/ {gsub(" ","",$2); print $2}' '/etc/pacman.conf')
                  keyring=$(pacman -Ssq '(-keyring)' | grep -v -i -E '(gnome|python|debian)')
                  # Download all the keyring 
                  sudo pacman -Syw $(keyring)
                  # Then install them manually
                  sudo pacman -U "${cache}${keyring}-${version}-any.pkg.tar.xz"
                  echo ""

I'm trying to figure out how to make a pacman manual install for each keyring. But I'm having a dead-end on the version part. Do you know what should I do on this? Thanks!

excalibur1234 commented 7 years ago

thanks so far!

  1. i noticed: if the default package cache gets used, pacman.conf contains a line beginning with #CacheDir. therefore, you should use cache=$(awk -F '=' '/CacheDir/ {gsub(" ","",$2); print $2}' '/etc/pacman.conf')

  2. your mistake is pacman -Ssq '(-keyring)' | grep -v -i -E '(gnome|python|debian)'. it outputs the name of all keyring packages to the "keyring" variable separated by a ? symbol. in order to solve this issue, i typically did:

    echo $keyring > /tmp/temporary_file
    sudo pacman -Syw $(/tmp/temporary_file)
  3. your solution to simply download the keyring packages from the repository is more elegant than mine. but it does not work, when you have the wrong/old keys installed in your keyring. then (at least as far as i remember), you are not able to download any package from the repository, because of a "keys do not match/are missing" error. please keep this edge case in mind. after all, this is the "fix errors" option. it should fix your keyring problem. i recommend to create a VM, break the archlinux/manjaro developer keys in that VM and try to install (with pacman -S archlinux-keyring) and download (pacman -Syw archlinux-keyring) packages. then, you will see what i am talking about. this way, you can try to find a method to do download packages despite a broken keyring (maybe something like pacman --force -Sw archlinux-keyring works? if that does not work, you have to use the same method as i did: choose the most reliable arch mirror/repo server and download the $keyring packages from there.

thefallenrat commented 7 years ago

Thanks for the reply!

  1. Thanks for noticed the mistake! I have fixed it!

  2. Ahh you're right... But what if I changed it into this ?

pacman -Qsq '(-keyring)' | grep -v -i -E '(gnome|python|debian)' | sed s/-keyring// | paste -sd " " - )

This will order them properly... (I think) ( Does bash allow paste command?)

~ >>> pacman -Qsq '(-keyring)' | grep -v -i -E '(gnome|python|debian)' | sed s/-keyring// | paste -sd " " -                                                           
archlinux artix manjaro
  1. I found another alternative for this...

What if I used sed command to edit /etc/pacman.conf and change these first lines :

SigLevel          = Required DatabaseOptional
LocalFileSigLevel = Optional

Into :

SigLevel          = Never #Required DatabaseOptional
LocalFileSigLevel = Never #Optional

Then install them :

sudo pacman -Sy $(pacman -Qsq '(-keyring)' | grep -v -i -E '(gnome|python|debian)' | sed s/-keyring// | paste -sd " " - )

After install those keyrings... Switch back the lines in /etc/pacman.conf... This seems easier than my former proposed fix, that is if I knew how to use sed....

excalibur1234 commented 7 years ago

one more thing: please remove the ! symbols from the following code (the ! negates the result - which is exactly the opposite you want to do) (line 591):

+       if [[ ! -e /usr/bin/pacman-mirrors ]]
+       then 
+           sudo pacman-mirrors -g -y
+       fi
+       
+       if [[ ! -e /usr/bin/reflector ]]
+       then
+           sudo reflector -f 5 --sort --save /etc/pacman.d/mirrorlist && sleep 20 $$ sudo pacman -Syy
+       fi

otherwise, it will not work!

thefallenrat commented 7 years ago

please remove the ! symbols from the following code (the ! negates the result - which is exactly the opposite you want to do) (line 591)

Thanks @excalibur1234 , just fixed it !

excalibur1234 commented 7 years ago
  1. your solution seems to work, so it is fine. "paste" is part of coreutils and should be installed on all systems by default. i do not know, whether it works with bash, because i use zsh. but i can test it after your work is finished.

  2. you can use sed or awk to do the job. i recommend to look up the syntax online. then, grep for "SigLevel" in pacman.conf file and replace (using sed or awk) the = symbol with " = Never #". after you downloaded the keyring packages, replace "= Never #" with "= " again. i am not sure, whether it is a good idea to mess with repository permissions in a bash script, but if it works, it is fine. i have never used the "trap" command and i do not have time to research right now. but maybe, it could be used to make sure that "Never" is always removed from the SigLevel (if it was not put there by the user)?

thefallenrat commented 7 years ago

Just did it.... What you think?

    # Manually download and install all keyring..

    echo "Lowering pacman securities (Allowing keyring to be installed) ..."

    sudo sh -c " sed -i -e '1 s/SigLevel/SigLevel          = Never #Required DatabaseOptional/; t' \ 
    -e '1,// s/SigLevel.*/SigLevel          = Never #Required DatabaseOptional/' \ 
    /etc/pacman.conf ; \ 
    sed -i -e '1 s/LocalFileSigLevel/LocalFileSigLevel = Never #Optional/; t' \
    -e '1,// s/LocalFileSigLevel.*/LocalFileSigLevel = Never #Optional/' \
    /etc/pacman.conf "

    echo "Installing all keyring ..."

    sudo pacman -Sy $(pacman -Qsq '(-keyring)' | grep -v -i -E '(gnome|python|debian)' | sed s/-keyring// | paste -sd " " - )

    echo "Raising pacman securities back ..."

    sudo sh -c " sed -i -e '1 s/SigLevel/SigLevel          = Required DatabaseOptional/; t' \ 
    -e '1,// s/SigLevel.*/SigLevel          = Required DatabaseOptional/' \ 
    /etc/pacman.conf ; \ 
    sed -i -e '1 s/LocalFileSigLevel/LocalFileSigLevel = Optional/; t' \
    -e '1,// s/LocalFileSigLevel.*/LocalFileSigLevel = Optional/' \
    /etc/pacman.conf "

    echo ""

I will update it with a comment tomorrow.... I got headache from doing this... needs some rest...

excalibur1234 commented 7 years ago
    sudo sh -c " sed -i -e '1 s/SigLevel/SigLevel          = Never #Required DatabaseOptional/; t' \ 
    -e '1,// s/SigLevel.*/SigLevel          = Never #Required DatabaseOptional/' \ 
    /etc/pacman.conf ; \ 
    sed -i -e '1 s/LocalFileSigLevel/LocalFileSigLevel = Never #Optional/; t' \
    -e '1,// s/LocalFileSigLevel.*/LocalFileSigLevel = Never #Optional/' \
    /etc/pacman.conf "

multiple thoughts:

here is a short piece of code that works and does the same as you tried to achieve: sudo awk -i inplace '{ /SigLevel/ gsub("=","= Never #") }; { print }' '/etc/pacman.conf' explanation:

  1. awk opens file '/etc/pacman.conf' and does inplace editing of that file (in RAM)
  2. it searches all lines containing 'SigLevel'
  3. in those lines, it substitutes '=' with '= Never #'
  4. it prints the result from RAM to the file (root permissions needed)

take a short break. it helps especially when you are new to something.

thefallenrat commented 7 years ago

Thank you @excalibur1234 for your inputs!

Sadly using your code suddenly made it somehow bad.... :

~ >>> grep -i SigLevel ~/Documents/testpacman/test.conf                                                                                                               
SigLevel    = Required DatabaseOptional
LocalFileSigLevel = Optional
#RemoteFileSigLevel = Required
SigLevel  = Optional
SigLevel  = Never

~ >>> awk -i inplace '{ /SigLevel/ gsub("=","= Never #") }; { print }' '/home/thefallenrat/Documents/testpacman/test.conf'                                         [2]

~ >>> grep -i Never ~/Documents/testpacman/test.conf                                                                                                                  
#RootDir     = Never # /
#DBPath      = Never # /var/lib/pacman/
CacheDir     = Never # /home/thefallenrat/.pacmancache/
#LogFile     = Never # /var/log/pacman.log
#GPGDir      = Never # /etc/pacman.d/gnupg/
#HookDir     = Never # /etc/pacman.d/hooks/
HoldPkg     = Never # pacman glibc
#XferCommand = Never # /usr/bin/curl -C - -f %u > %o
#XferCommand = Never # /usr/bin/wget --passive-ftp -c -O %o %u
#XferCommand = Never # /usr/bin/aria2c --allow-overwrite= Never #true --continue= Never #true --file-allocation= Never #none --log-level= Never #error --max-tries= Never #2 --max-connection-per-server= Never #2 --max-file-not-found= Never #5 --min-split-size= Never #5M --no-conf --remote-time= Never #true --summary-interval= Never #60 --timeout= Never #5 --dir= Never #/ --out %o %u
#CleanMethod = Never # KeepInstalled
#UseDelta    = Never # 0.7
Architecture = Never # auto
#IgnorePkg   = Never #
#IgnoreGroup = Never #
#NoUpgrade   = Never #
#NoExtract   = Never #
SigLevel    = Never # Required DatabaseOptional
LocalFileSigLevel = Never # Optional
#RemoteFileSigLevel = Never # Required
#       Server = Never # ServerName
#       Include = Never # IncludePath
Include   = Never # /etc/pacman.d/mirrorlist
Include   = Never # /etc/pacman.d/mirrorlist
Include   = Never # /etc/pacman.d/mirrorlist
#Include = Never # /etc/pacman.d/mirrorlist-arch
#Include = Never # /etc/pacman.d/mirrorlist-arch
Include = Never # /etc/pacman.d/mirrorlist-manjaro
Include   = Never # /etc/pacman.d/mirrorlist-manjaro
Include   = Never # /etc/pacman.d/mirrorlist-manjaro
Include   = Never # /etc/pacman.d/mirrorlist-manjaro
SigLevel  = Never # Optional
Server    = Never # https://www.strits.dk/files/manjaro-strit/manjaro-strit-repo/$arch
SigLevel  = Never # Never
Server    = Never # http://nulogicsystems.com/public_files/nulogic/$arch

And so I decide to re-edit my initial commands to become like this :

sudo -c " sed -i -e '1 s/SigLevel.*/SigLevel          = Never #Required DatabaseOptional/; t' -e '1,// s/SigLevel.*/SigLevel          = Never #Required DatabaseOptional/' /etc/pacman.conf ; sed -i -e '1 s/LocalFileSigLevel.*/LocalFileSigLevel = Never #Optional/; t' -e '1,// s/LocalFileSigLevel.*/LocalFileSigLevel = Never #Optional/' /etc/pacman.conf "

This command seems works fine on my end .... :

~ >>> grep -i SigLevel ~/Documents/testpacman/test.conf                                                                                                               
SigLevel    = Required DatabaseOptional
LocalFileSigLevel = Optional
#RemoteFileSigLevel = Required
SigLevel  = Optional
SigLevel  = Never

~ >>> sh -c " sed -i -e '1 s/SigLevel/SigLevel          = Never #Required DatabaseOptional/; t' -e '1,// s/SigLevel.*/SigLevel          = Never #Required DatabaseOptional/' ~/Documents/testpacman/test.conf ; sed -i -e '1 s/LocalFileSigLevel/LocalFileSigLevel = Never #Optional/; t' -e '1,// s/LocalFileSigLevel.*/LocalFileSigLevel = Never #Optional/' ~/Documents/testpacman/test.conf "

~ >>> grep -i Never ~/Documents/testpacman/test.conf                                                                                                                  
SigLevel          = Never #Required DatabaseOptional
LocalFileSigLevel = Never #Optional
SigLevel  = Never

...What do you think?

excalibur1234 commented 7 years ago

ah you are right. i did not test my commands properly. these should work though (it is already late here, so forgive me, if i make another mistake):

sudo awk -i inplace ' { gsub( /SigLevel[ ]*=/ , "SigLevel = Never #" ) } ; {print} ' '/etc/pacman.conf'

sudo awk -i inplace ' { gsub( /SigLevel[ ]*= Never #/ , "SigLevel =" ) } ; {print} ' '/etc/pacman.conf'

please notice that your sed command is much less flexible (and longer) than my awk command (with a strange syntax).

thefallenrat commented 7 years ago

Your command works now. Though I must say that, running the command replaces all the string SigLevel (Unlike mine that only replaces the first SigLevel and LocalSigLevel)

~ >>> awk -i inplace ' { gsub( /SigLevel[ ]*=/ , "SigLevel = Never #" ) } ; {print} ' '/home/thefallenrat/Documents/testpacman/test.conf'

~ >>> grep -i Never ~/Documents/testpacman/test.conf                                                                                                                  
SigLevel = Never # Required DatabaseOptional
LocalFileSigLevel = Never # Optional
#RemoteFileSigLevel = Never # Required
SigLevel = Never # Optional
SigLevel = Never # Never

But then again, the next command reverted those changes so all seems fine now!

~ >>> awk -i inplace ' { gsub( /SigLevel[ ]*= Never #/ , "SigLevel =" ) } ; {print} ' '/home/thefallenrat/Documents/testpacman/test.conf'                          [2]
~ >>> grep -i Never ~/Documents/testpacman/test.conf                                                                                                                  
SigLevel = Never

And so, I will use your commands instead of mine. And I will also edit the echo to explicitly warns the user to never leave pacui before finishing keyring install...

excalibur1234 commented 7 years ago

are you planning to do more work in this pull request?

if not, i can start to look over the changes and accept it. i might do some small changes to your code (the help page and some comments) after accepting it.

thefallenrat commented 7 years ago

are you planning to do more work in this pull request?

Sadly, no as I don't know what to write in the help pages anymore... You can now merge it and do small changes to your codes....

Anyway... Thanks for letting me to do this pull request, I really appreciated it! It really helps me understanding github and its features...

excalibur1234 commented 7 years ago

sure, no problem.

if you ever want to contribute to this or another github (in fact, most git-based online repositories work very very similar) project, you know how it is done.

one more thing you should take a look at: commit conflicts. this is really useful to know when working with git/github. you can test this the following way:

excalibur1234 commented 7 years ago

i have just played around with sed and found a much simpler solution than my awk command mentioned above (and your sed command). i did the changes in this commit: 196570b34355d2455280df6e967024eeb70767a9