You are not logged in.

#1 2023-01-17 09:47:00

pikomarco
Member
Registered: 2023-01-17
Posts: 3

[Risolved] My Pacman script work for new installations?

Hi all,

i'm newbie in a Forum and have a question for more experts.
I created a script for automate pacman.
The script contains the main commands but not those for installing and removing because i don't know the way to bring it up "sudo pacman -S" or "sudo pacman -Rs" and add the name of package.
Thank you for support.

Last edited by pikomarco (2023-01-20 08:44:16)

Offline

#2 2023-01-17 11:56:05

seth
Member
Registered: 2012-09-03
Posts: 51,175

Re: [Risolved] My Pacman script work for new installations?

because i don't know the way to bring it up "sudo pacman -S" or "sudo pacman -Rs" and add the name of package

Bring what up?
I guess you're looking for an interactive GUI way to issue a password to sudo?
You can use https://man.archlinux.org/man/core/sudo/sudo.8.en#S or alternatively pkexec, but it's really not clear to me what you want to achieve.

Offline

#3 2023-01-17 13:06:47

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 1,985
Website

Re: [Risolved] My Pacman script work for new installations?

I rather think OP does not know how to format / concatenate string literals in $SCRIPT_LANGUAGE they are using.
Which would be reasons enough for me to not engage any further in here.

Last edited by schard (2023-01-17 13:07:10)


macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }

Offline

#4 2023-01-17 13:36:13

Awebb
Member
Registered: 2010-05-06
Posts: 6,286

Re: [Risolved] My Pacman script work for new installations?

schard wrote:

I rather think OP does not know how to format / concatenate string literals in $SCRIPT_LANGUAGE they are using.
Which would be reasons enough for me to not engage any further in here.

But you posted here and the thread will now foerever turn up under "Posted".

Dang.

Offline

#5 2023-01-17 13:44:00

seth
Member
Registered: 2012-09-03
Posts: 51,175

Re: [Risolved] My Pacman script work for new installations?

He could report is post for deletion, but we can also just wait and see what the OP actually meant.
Unless somebdy can parse their statement, 'cause I've really no exact idea about the issue.

Offline

#6 2023-01-17 17:17:34

Roken
Member
From: South Wales, UK
Registered: 2012-01-16
Posts: 1,253

Re: [Risolved] My Pacman script work for new installations?

A very insecure way is:

echo password | sudo -S pacman -S pkg

Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus Prime B450 Plus, 32Gb Corsair DDR4, Cooler Master N300 chassis, 5 HD (1 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703

Offline

#7 2023-01-17 19:02:53

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [Risolved] My Pacman script work for new installations?

Given that it has "main commands" but just not installing/removing, I'm inclined to agree with Schard's interpretation as surely updating would be one of the main commands (and this requires sudo / root).

But in any case, pikomarco, please post the actual code.  Even without any language barrier, describing what a script does is error prone - show us the script, and we'll see exactly what it does.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2023-01-18 07:44:01

pikomarco
Member
Registered: 2023-01-17
Posts: 3

Re: [Risolved] My Pacman script work for new installations?

But in any case, pikomarco, please post the actual code.  Even without any language barrier, describing what a script does is error prone - show us the script, and we'll see exactly what it does.

Right!
The script is this:

 #! /bin/bash
2 while true
3 do
4 echo "=========="
5 echo "Pac-Man"
6 echo "=========="
echo "1) update "
8echo "2) pacchetti installati "
9 echo "3) pulisci l'intera cache "
19 echo e "\n"
11 echo "Premi u per uscire "
12 echo -e "\n"
13 echo -e "Scegli: \c"
14 read answer
15 case "$answer" in
16 1) sudo pacman -Syu ;;
2) pacman -Q ;;
20 3) sudo pacman -Scc ;;
22 u)exit ;;
23 esac
24 echo -e "Premi INVIO per tornare al menù \c"
25 read input
26 done 

The options is an italian.

Last edited by pikomarco (2023-01-18 07:48:31)

Offline

#9 2023-01-18 10:31:54

seth
Member
Registered: 2012-09-03
Posts: 51,175

Re: [Risolved] My Pacman script work for new installations?

Ok, but that doesn't explain what your problem is - it's an interactive script, there's no input redirection… so where's the problem?

Offline

#10 2023-01-18 10:35:54

Awebb
Member
Registered: 2010-05-06
Posts: 6,286

Re: [Risolved] My Pacman script work for new installations?

Okay, here is the deal: pikomarco wants to add names of packages to commands like "pacman -S" and doesn't know enough bash. Now he's come here for input, but we don't get it, because the question is so basic, that we should be discussing basic bash guides.

https://tldp.org/LDP/Bash-Beginners-Guide/html/

Offline

#11 2023-01-18 20:26:04

teckk
Member
Registered: 2013-02-21
Posts: 519

Re: [Risolved] My Pacman script work for new installations?

Formatted so one can read it.

#! /bin/bash

while true; do
    echo "=========="
    echo "Pac-Man"
    echo "=========="
    echo "1) update "
    echo "2) pacchetti installati "
    echo "3) pulisci l'intera cache "
    echo e "\n"
    echo "Premi u per uscire "
    echo -e "\n"
    echo -e "Scegli: \c"
    read answer
    case "$answer" in
        sudo pacman -Syu ;;
        pacman -Q ;;
        sudo pacman -Scc ;;
        u)exit ;;
    esac
    echo -e "Premi INVIO per tornare al menù \c"
    read input
done

And that has multiple problems.

How about something like this framework:

#!/usr/bin/bash

PS3="
Select an option.:  "

while :; do
    clear
    options=("Quit" "update" "pacchetti installati" "pulisci l'intera cache")
    select opt in "${options[@]}"; do
        case "$opt" in
            Quit) clear; exit
            ;;
            
            update) echo "pacman -Syu"
                    break
            ;;
            
            "pacchetti installati") echo "pacman -Q" 
                                    break
            ;;
            
            "pulisci l'intera cache") echo "pacman -Scc"
                                        break
            ;;
            
            *) echo "Not a valid option"
                break
            ;;
        esac
    done
    sleep 2
done

Last edited by teckk (2023-01-18 20:27:24)

Offline

#12 2023-01-18 20:33:21

seth
Member
Registered: 2012-09-03
Posts: 51,175

Re: [Risolved] My Pacman script work for new installations?

He has proper case handling (gets lost in the broken and somewhat inconsistent line handling)
The script is certainly improvable on multiple layers and in multiple regards, but I'm afraid that schard and Awebb are correct (at least their parsing doesn't contradict the statement - absurd as it seems since the existing script reads and references variables …)

Offline

#13 2023-01-18 21:14:52

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Risolved] My Pacman script work for new installations?

/me turns to ChatGPT to write a pacman wrapper...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#14 2023-01-20 08:26:53

pikomarco
Member
Registered: 2023-01-17
Posts: 3

Re: [Risolved] My Pacman script work for new installations?

Hi all,

i risolved with

#! /bin/bash
while true
do
echo "==============="
echo "   Pac-Man     "
echo "==============="
echo "1) Installa"
echo "2) Rimuovi"
echo "3) Pacchetti installati"
echo "4) Pulisce l'intera cache"
echo -e "\n"
echo "Premi u per uscire "
echo -e "\n"
read -p "Scegli: " answer
case "$answer" in
1)  clear
    read -p "Nome del pacchetto da installare: " pkg
    sudo pacman -S $pkg
    clear
    continue
    ;;
2)  clear
    read -p "Nome del pacchetto da rimuovere: " pkg
    sudo pacman -Rs $pkg
    clear
    continue
    ;;
3)  pacman -Q ;;
4)  sudo pacman -Scc ;;
u)  exit ;;
*)  clear
    continue
esac
done

It's not a greatest script but is pratical for me.
Thanks all!

Last edited by pikomarco (2023-01-20 08:29:29)

Offline

Board footer

Powered by FluxBB