You are not logged in.
Hello, I am having fun bash scripting because I see the potential. I am still a beginner but, I can learn and am willing.
Here is my mock-up
==========================================================================================
#!/usr/bin/env bash
name="myname"
echo "Hello, $name. Please give us a second as we populate you arch-linux post install set-up
sudo pacman-key --init
sudo pacman-key --populate archlinux
sudo pacman -S wine dolphin-emu ppsspp gparted partitionmanager lutris obs-studio git discord firefox firewalld bluez bluez-utils vlc vlc-plugins-all steam seahorse flameshot lact virtualbox virtualbox-host-modules-arch yt-dlp libimobiledevice ifuse okular python-pip tk xdotool xorg-xwininfo gtksourceview3
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo systemctl enable bluetooth.service
sudo systemctl enable --now lactd
if command -v git &> ./git; then
[Tab Insert]echo "Application git is available."
[Tab Insert]git clone ....
[Tab Insert]cd ventoy-bin
[Tab Insert]makepkg -si
fi
echo "The exit code for this process is: $?"
=====================================================================================================
Problems w/ my own script:
- Constantly prompted y/n & sudo password (therefore it is not fully automated)
- The git clone/makepkg -si process still prompts me for y/n & sudo password
- In regards to git clone/makepkg -si process, how do I do mutiple of these.....automated.....one by one down the line
Personal Request To More Knowledgeable Members:
- Please teach me and explain to me what they do, I do make my own notes and I get a satisfaction from figuring things out. I am stumped now though and I don't want to rely on AI too much. I genuinely like using my brain.
- Explain why people and how people use bash and python together, what are the pros & cons
- Any new ideas to pass onto a beginner bash scripter? & as far a python I understand it somewhat but, I don't know how to make anything.
Future Personal Project:
- How to make my own script that will update the Arch-linux system every week or so
Offline
Don't put sudo into a bash script. Run the script as root if you need it.
if [ $(whoami) != 'root' ]; then
echo "Must be root or sudo to run $0"
exit
fiOffline
Don't put sudo into a bash script. Run the script as root if you need it.
That doesn't work when running python-pip and makepkg.
Offline
- Constantly prompted y/n
Use pacman's --noconfirm option for non-interactive operations.
& sudo password (therefore it is not fully automated)
Create dedicated user with interactive login disabled. Configure sudo to run necessary pacman commands by this user without a password. Run your script as that user.
- The git clone/makepkg -si process still prompts me for y/n & sudo password
git shouldn't do that. What exactly does git prompt?
makepkg prompts for password in order to run pacman for -si.
- In regards to git clone/makepkg -si process, how do I do mutiple of these.....automated.....one by one down the line
packages=(
foo
bar
baz
)
for pkg in "${packages[@]}"; do
# Do something with "$pkg"
...
doneConsider to use
set -eat the beginning of the script to stop execution if any command failed.
- How to make my own script that will update the Arch-linux system every week or so
This doesn't look like a good idea. Update may require manual intervention.
Offline
Don't put sudo into a bash script. Run the script as root if you need it.
I'd say that very much depends on the UID requirements of the script: one should™ limit the UID0 processes as much as possible, there's no point in running an entire script as UID0 if only a single instruction actually needs those.
eg.: as Scimmia pointed out, makepkg won't allow you to run as UID0 at all.
Discussion is to be head as the whether hardcoding the lever is ok (for a local script: sure why not) and whether it makes sense to allocate (and bounce) credentials early on to allow a long running script to ask for credentials once early on and then use them much later.
I doubt the sudo prompts are /that/ constantly, the problem will be between
sudo systemctl enable --now lactd # last cred cache bump
if command -v git &> ./git; then
echo "Application git is available."
git clone ....
cd ventoy-bin
makepkg -si # makepkg is gonna ask you for the sudo password at the endhttps://man.archlinux.org/man/sudo.8#v
https://man.archlinux.org/man/sudoers.5.en / look for timestamp_timeout
A possible approach would be to run "makepkg -s" in a forked subshell, frequently bump the cred cache while waiting for that to end and then sudo makepkg -i at the end, depending on the success of the building step.
Offline
this:
Create dedicated user with interactive login disabled. Configure sudo to run necessary pacman commands by this user without a password. Run your script as that user.
and this:
https://man.archlinux.org/man/sudoers.5.en / look for timestamp_timeout
needs to edit the same file, but I highly recommend you, in case you don't know yet, that for that use sudo visudo to edit it. Visudo let you know if you are making syntax mistakes in your file, so it shows you a warning. It helps you to not brick your system accounts. So make the changes with visudo please. Probably here all we know that but since you seems to be new to Linux I just think is okey to said that.
I'm going to talk about the script, among other questions you have in another post ^^
Last edited by Succulent of your garden (2025-11-08 12:36:39)
str( @soyg ) == str( @potplant ) btw!
Offline
This entire block of code it does required root privileges as you know:
sudo pacman-key --init
sudo pacman-key --populate archlinux
sudo pacman -S wine dolphin-emu ppsspp gparted partitionmanager lutris obs-studio git discord firefox firewalld bluez bluez-utils vlc vlc-plugins-all steam seahorse flameshot lact virtualbox virtualbox-host-modules-arch yt-dlp libimobiledevice ifuse okular python-pip tk xdotool xorg-xwininfo gtksourceview3
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo systemctl enable bluetooth.service
sudo systemctl enable --now lactd
One solution as some people say here is to just run your script as root, or add your user to the wheel group, and edit the sudoers file with visudo to let your user account run sudo commands without asking for password, you can specify which commands are allowed to run with NOPASSWD: in the sudoers file, so you just simply not let that your user can run any command without asking password, unless you really want to do that.
Also this line of your code is redundant
sudo systemctl start firewalldif you make this first:
sudo systemctl enable firewalld --now The same can be applied to bluetooth and lactd ^^
This part of the script:
if command -v git &> ./git; then
[Tab Insert]echo "Application git is available."
[Tab Insert]git clone ....
[Tab Insert]cd ventoy-bin
[Tab Insert]makepkg -si
fiThe main problem is with the makepkg -si. You can fix that using the same approach and using the --no-confirm flag that was said before. But I highly recommend that you check really well what are you going to install and if you trust the code on it, and also if you think is okey to have some commands in your user account that can be executed without asking password authentication, like makepkg, so this really can work if you are okey with the trade offs, and those are okey in the context that you are working in your machine.
As for me the first part of the script I would just run it as root user, since it seems a setup part that is only going to be used once, you are installing and configuring the system so probably it's okey to run that script with root or using sudo /.Your_script.sh the second it's going to depend what are you installing, if you are installing something that you created 100% by yourself then it's okey if you trust your code. If for example is a thing that uses external packages from npm then probably I would say be careful on that.
Please teach me and explain to me what they do, I do make my own notes and I get a satisfaction from figuring things out. I am stumped now though and I don't want to rely on AI too much. I genuinely like using my brain.
Nice, many around here appreciate that kind of mentality ^^ , so keep on that and nice attitude and we are going to help you
- Explain why people and how people use bash and python together, what are the pros & cons
That's going to depend of the context on what are your working, probably in some cases you really don't need python at all. The magic of python is that is just a glue language for really good c++ code. Most of the more used libraries in pytorch are made in c++, so python is just more like wrapper for that, so you can just write fast things in a very high level language approach. Maybe if you need to work with data files like .csv and need to do some processioning then you could use python for just doing that and then came back to your shell script which is bash in your case. I guess in the context that you are saying is more like using numpy, seaborn or matplotlib and pandas. Maybe you need to create some histograms and for that you could use seaborn for example. But it's really going to depend in the context of what are you doing.
For running python in bash you just need to run your python script file in your bash script, but probably it's going to create a sub process for that only for python, so keep that in mind. I think that the cons are that python is slow by default if you are not using gpu accelerated libraries, it runs by default in just one cpu thread. The pro is that maybe you can write things fast and easily to understand for everyone in long story short.
- Any new ideas to pass onto a beginner bash scripter? & as far a python I understand it somewhat but, I don't know how to make anything.
It's going to depend what are you going to do. Assuming you want to create GUI non webapp programs or if you want to create webapps. In practice you can using flask or django and other stuff. In practice you just need to read the documentation of libraries and frameworks that you are going to use. But if you are really newbie then focus on learning OOP first and what are APIs and maybe ABIs, then if you are interested in web development learn about it, learn how to do frontend, backends and all that stuff.
Future Personal Project:
- How to make my own script that will update the Arch-linux system every week or so
That's very simple. But try to do it yourself first. For that you should need to use anacron, not cron, anacron ^^, then just put the script path in your anacron config file ![]()
Last edited by Succulent of your garden (2025-11-08 13:15:08)
str( @soyg ) == str( @potplant ) btw!
Offline
The timestamp_timeout defaults to 5 minutes, that should be plenty and reasonable enough to keep it there (you don't want to set it to 7 days or stuff like that and if you need to carry the creds over long running jobs, you're looking for a dynamic solution - 10 minutes can be 9 minutes too long or one minute too little)
That being said: ALWAYS use visudo to edit sudoers - whether you're using vi or vim as sudo/editor or nano or … doesn't matter.
Offline
#!/usr/bin/env bash
name="Mr. name"
echo "Hello, $name. Please give us a second as we populate your arch-linux setup"
if [ $(whoami) != 'root' ]; then
echo "Must be root or sudo to run $0"
sudo pacman-key --init
sudo pacman-key --populate archlinux
yes | pacman -S wine dolphin-emu ppsspp gparted partitionmanager lutris obs-studio git discord firefox firewalld bluez bluez-utils vlc vlc-plugins-all steam seahorse flameshot lact virtualbox virtualbox-host-modules-arch yt-dlp libimobiledevice ifuse okular python-pip tk xdotool xorg-xwininfo gtksourceview3
sudo systemctl enable firewalld --now
sudo systemctl enable bluetooth.service -now
sudo systemctl enable lactd --now
if command -v git &> /usr/bin/git; then
echo "Application git is available."
fi
fi
echo "The exit code for this process is: $?"
=======================================================================
Output:
Hello, Mr. name. Please give us a second as we populate your arch-linux setup
Must be root or sudo to run /usr/local/bin/script.sh
==> Appending keys from archlinux.gpg...
==> Updating trust database...
gpg: next trustdb check due at 2025-12-31
error: you cannot perform this operation unless you are root.
/usr/local/bin/script.sh: line 14: /usr/bin/git: Permission denied
The exit code for this process is: 0
===================================================================
My Personal Notes:
Bash Scripting Notes
=====================
- 1st line is called the shebang, it determines the interpreter. A great shebang to almost always use is.....#!/usr/bin/env bash..... The reason we use this shebang is because it is 'portable' across multiple systems.
- nano 'scriptname'.sh..... This will create the script template
> We need to give it permission to be executable
>> sudo chmod +x 'scriptname'.sh
> To execute the script, its usually /home/'nameofUSR'/'scriptname'.sh
- pacman's --noconfirm option bypasses all confirmation prompts, making it great for automation
> it defualts to "no" to force a "yes", you can pipe the yes command into pacman like: yes | pacman -Syu
.
Bash Scripting Advice From Others
=================================
- AVOID using sudo, its a security risk.
- Create a dedicated user to run scripts with no password and disabled interactive login.
> useradd -m -s /user/bin/nologin username
>> -m creates the user's home directory
>> -s login shell for the new account
>>> To make certain the user doesn't have a password, you can remove it by passwd -d username *only works as root user*
- They will also need sudo prefix to avoid usage of the command as a security protocol.
> sudo usermod -aG wheel username
> sudo EDITOR=nano visudo
> Scroll all the way down, look for # %wheel ALL=(ALL) ALL. Uncomment the one without password option by deleting the #
Bash Script Testing-it-out Components
===============================
1. Run your scripts as a dedicated usr while avoiding the usage of sudo
runuser -l username -c '/home/q/script.sh
> -l logins in as username
> -c passes a single command to shell
=====================================================================
Questions & statements I for the community...
- if [ $(whoami) != 'root' ]; then
echo "Must be root or sudo to run $0" <----- this is awesome it worked credit: teckk
- I removed more redundancy as mentioned <----- great!
- I tried creating a user with passwordless and no interactive login with sudo (i did use visudo i promise, but im new so it is a little overwhelming) and it made the process kind of complicated to clarify, I went into a rabbit hole of trying to get it to work. Above us are the notes I took. In the end, it didn't work because for the systemctl & pacman-key it required root, so on arch-linux kde it kept prompting an authentication required with the option of switching from the root to the created user and it repeated that 5x.
- How do I use pacman's --noconfirm in the context of this script? Can I just get 1 example or hint, and I swear I'll put in the work.
- I learned so much that I have a headache, but you guys are awesome and I appreciate you
- Also how are you guys quoting each other like that, ??
==================================================================
Community Mentioned Advice I Haven't Tried Yet Or Dont Understand
- Dimich suggested:
packages=(
foo
bar
baz
)
for pkg in "${packages[@]}"; do
# Do something with "$pkg"
...
done
Consider to use
set -e
UndiePatrol: I haven't tried this yet, I also don't understand but its because I haven't tried yet.
- Succulent of your garden suggested:
That's very simple. But try to do it yourself first. For that you should need to use anacron, not cron, anacron ^^, then just put the script path in your anacron config file
UndiePatrol: I don't know this yet, I will look it up
- Seth suggested:
A possible approach would be to run "makepkg -s" in a forked subshell, frequently bump the cred cache while waiting for that to end and then sudo makepkg -i at the end, depending on the success of the building step.
UndiePatrol: I understand what you're saying, I don't know how to do it (yet) the arch-linux skill ceiling is friggin steep omg.
Extra thanks to Succulent of your garden my brain actually hurts theres so much to learn and im grateful & appreciative. You mentioned: C++, python, Django, Flask, I was looking into those. I want to make a nonprofit mmo like Ragnarok online and just make it "word of mouth" and make one heavenly happiness in this world (just a silly dream, but i wonder if i throw spare time at it maybe something will be produced). It's just a lot of self learning for me, and even though its difficult I'm enjoying it.
Last edited by UndiePatrol (2025-11-08 16:01:41)
Offline
Please use [code][/code] tags. Edit your post in this regard.
"yes | pacman -S " isn't going to work, you'll probably have to update the database, thus the system and also this requires root permissions.
Offline
- AVOID using sudo, its a security risk.
It's only a security risk if you are using it to run scripts/programs that you don't know what are doing 100%. It's totally fine to do some stuffs with sudo if they really need it and you know what are they doing. It's common sense in some way, but yep, if you can avoid using privilege escalation then do it. That doesn't mean that running sudo without password is that, it's not. Sudo is for asking the privilege escalation, some times you need it.
Extra thanks to Succulent of your garden my brain actually hurts theres so much to learn and im grateful & appreciative. You mentioned: C++, python, Django, Flask, I was looking into those. I want to make a nonprofit mmo like Ragnarok online and just make it "word of mouth" and make one heavenly happiness in this world (just a silly dream, but i wonder if i throw spare time at it maybe something will be produced). It's just a lot of self learning for me, and even though its difficult I'm enjoying it.
^^ doing a quick search it seems that cocos2d is still a thing for making games in python, but not sure if the python version it does provide cross compatibility support for different operative systems. If you are into the open source things maybe godot is what are you looking for. But be in mind that using those kind of tools usually need a licence when you publish games and sometimes a fee. So try first to see what engine would be better for your money needs. All engines have their pros and cons, so maybe if you are going full 3d game then unreal is better than godot [but maybe you are going to pay more for licensing and fee for the games], but if you wanna make some kind of 2d game then maybe unreal is an overkill and you can do it in godot, it really depends also in your ambitions, some kind of physics stuff in the engines exists and in other don't or it's not that good, so make your research. The only way to not pay any single penny to anybody is to make the engine by yourself, which could be nice and a hard task to do, but in that case you will avoid the paying fees for using third party engines
, some folks do that, big brain C or C++ by the way. I'm not a game developer by the way
- Also how are you guys quoting each other like that, ??
Read this ^^ https://bbs.archlinux.org/help.php#url
Last edited by Succulent of your garden (2025-11-08 21:57:25)
str( @soyg ) == str( @potplant ) btw!
Offline
Wouldn't it be great or .... if sudo could accept non-interactive password?
sudo -p <password> systemctl ....I know MySQL does this which allows use from scripts but why won't sudo do it?
Edit:- interactive ----> non-interactive
Last edited by ReDress (2025-12-02 05:59:05)
Offline
but why won't sudo do it?
You mean luring you into storing your password cleartext in some script?
Offline
#!/usr/bin/env bash
echo "Hello, $(whoami). Please give us a second as we populate you arch-linux post install set-up
sudo pacman -S - < packages.txt --noconfirm
sudo systemctl enable firewalld bluetooth.service lactd
#note you can include git in your packages.txt
if git --version &>/dev/null; then
git clone https://aur.archlinux.org/ventoy-bin.git
makepkg -siD ventoy-bin --noconfirm
else
sudo pacman -S git --noconfirm
git clone https://aur.archlinux.org/ventoy-bin.git
makepkg -siD ventoy-bin --noconfirm
fi
echo "The exit code for this process is: $?"Offline
but why won't sudo do it?
You mean luring you into storing your password cleartext in some script?
It's predominantly used for testing purposes
Offline
https://man.archlinux.org/man/sudo.8#S
I seem to remember that there used to be a warning about using this being probably a not so great idea in the manpage
Offline
seth wrote:but why won't sudo do it?
You mean luring you into storing your password cleartext in some script?
It's predominantly used for testing purposes
I remember but only very vaguely.
Offline
Hello, I am having fun bash scripting because I see the potential. I am still a beginner but, I can learn and am willing.
You might find the following helpful in your quest to learn bash:
Offline
Hello, I am having fun bash scripting because I see the potential. I am still a beginner but, I can learn and am willing.
You might find the following helpful in your quest to learn bash:
Seems to me like some languages are best learnt on the go :-]
Particularly scripting languages.
Last edited by ReDress (2025-12-04 07:11:28)
Offline
Seems to me like some languages are best learnt on the go :-]
On the go is a very nice way ^^, even with C if you have some experience in programming before ![]()
But now days Java Script is probably the only one that makes me feel like I need to check and be an Elite senior JS/TS dev because npm is getting hacked like every week now days xD
Install pnpm, use bun, use deno said some folks, that fix everything. Well that can be a partial truth, but is like I'm always scared of using the packages of others in JS anyways LoL.
That's not the case for python, or even Rust by the way[I know that in Rust sometimes things get's pwned btw, but not like the rate of JS/TS]. JS/TS is driving me more like the approach of: Okey we need to go and tell everyone to fuck themselves and build everything from scratch
It's a particular experience.
Imagine that you are working with a Junior dev and you need to teach JS as senior. And the first lesson is not how to do programming, instead is how to do package lock well to not get pwned LoL.
So yeah, learn on the go, but not with JS ? Maybe in that field people should be more careful ![]()
EDIT: And now with the release of webgpu API we are going to see JS + LLMs hacks. We opened the door to hell oh no boys.
Last edited by Succulent of your garden (2025-12-04 13:46:32)
str( @soyg ) == str( @potplant ) btw!
Offline
ReDress wrote:Seems to me like some languages are best learnt on the go :-]
On the go is a very nice way ^^, even with C if you have some experience in programming before
.
It's generally hard to impossible to.trip on scripting language. Honestly, trying to master it before using it might not be worth the effort.
Offline
On the go is a very nice way ^^, even with C if you have some experience in programming before
C is not a "try it and see" language (in fact, the bot for the #c channel on Libera.chat has a pre-written message about this point). Obviously the only way to get good at any programming language is to actually use it and experiment with it, but using C properly requires knowledge of the standard which you simply can't acquire from any amount of trial and error.
If you don't have that understanding, you'll end up writing code that works on your system but fails on others, or breaks when the compiler updates, or has an exploitable buffer overflow, or any other problem.
"Don't comment bad code - rewrite it." - The Elements of Programming Style (1978), Brian W. Kernighan & P. J. Plauger, p. 144.
Offline
Honestly, trying to master it before using it might not be worth the effort.
I agree with that. But my point is like you can do programming and C and be comfy that nothing bad is going to happen. You will just get segmentation faults that probably are hard to understand, you really need to fucked up so hard to destroy your workstation in the process. In the case of JS/TS one package can create Hell without noticing it ![]()
EDIT:
but using C properly requires knowledge of the standard which you simply can't acquire from any amount of trial and error.
Yes you are right. You will need to read a lot of have some book. I can't deny that. I was joking in some sentences and light talking about it.
If you don't have that understanding, you'll end up writing code that works on your system but fails on others, or breaks when the compiler updates, or has an exploitable buffer overflow, or any other problem.
That's also true. But my point is that to create things and making serious oops while learning the language in C is more robust and hard to make it happen in comparison to JS. Since C does have a learning step and lacks the "package manager" thing, it's far more hard to get pwned. Sure you can create a program with a lot of exploitable buffer overflows, but if that thing never is going into production and you don't want to share it with anyone then is very hard that your bad code in C is going to be exploited, which is not the case in the JS experience, in which you can get pwned while learning it. I'm talking just in the context of learning the language.
That's not the case in shell scripting, or even python that does have his "package manager" thing. As far as I know python packages are well audited or you can check it with snyk for example. Python had created his own eco system where you know that "some libraries" you can trust them almost 100%. If you just go into normie python world, the chances to get pwned are very low to be honest, in comparison to JS now days. Or that's my humble opinion to be honest.
My comment is about how more easily is to get pwned in one language while learning it, and not how much exploitable is the code that you had created. And seems that JS is king in that
, again my humble opinion.
Last edited by Succulent of your garden (2025-12-04 16:02:56)
str( @soyg ) == str( @potplant ) btw!
Offline
Okay, okay, okay, that's enough, we shall stop derailing the thread now.
Offline
use code tags https://bbs.archlinux.org/help.php#bbcode
Offline