Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-27-2014, 12:40 AM
|
#1
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Rep:
|
Slackware Configuration Script - my first script
Hi guys, as I said on this thread I am trying to write a script to help me out on fresh slackware installations. Currently it only has two functions:
1 - enabling multilib support
2 - switching from huge to generic kernel
The code can be viewed here. I know, it is silly but it is my first script (don't be too harsh please). This is its initial state, I pretend to add more functions. Any suggestion, help and *GOOD* criticism is appreciated, thanks.
EDIT: version 0.0.2 uploaded
Last edited by moisespedro; 01-27-2014 at 12:25 PM.
|
|
|
01-27-2014, 01:27 AM
|
#2
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep:
|
It's not silly at all. I say any operation that will be done enough times to justify making a script (or something similar), should be automated. Even if it takes you just as long to create the script as it would take to do everything manually, or perhaps even longer, you will have learned something along the way.
I've had a quick look, and here are my comments: - You're greeting the user, then telling him/her the script must be run as root. Why not just check for root instead?
- You could try auto-detecting the Slackware version using the /etc/slackware-version file, and present the user with an option to override.
- The script makes a "multilib" subdirectory in the current directory. Why not use mktemp -d instead?
- Several of the operations in the script could fail under various circumstances, such as the lftp download. How about adding some error checking/handling? Even "|| exit" beats having nothing at all.
|
|
1 members found this post helpful.
|
01-27-2014, 01:31 AM
|
#3
|
Senior Member
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,860
|
- You might want to use grep, awk, or even cut to get an initial SLACKVER value from /etc/slackware-version. Or cat it to the screen.
- You can simply use
Code:
$(/usr/share/mkinitrd/mkinitrd_command_generator.sh -r)
to generate the initrd
- /boot/vmlinuz-generic-* will match more than one kernel on a 32 bit system:
Code:
# ls /boot/vmlinuz-generic-*
/boot/vmlinuz-generic-3.2.29 /boot/vmlinuz-generic-smp-3.2.29-smp
|
|
|
01-27-2014, 02:39 AM
|
#4
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
Quote:
Originally Posted by Ser Olmy
I've had a quick look, and here are my comments: - You could try auto-detecting the Slackware version using the /etc/slackware-version file, and present the user with an option to override.
|
Quote:
Originally Posted by Richard Cranium
You might want to use grep, awk, or even cut to get an initial SLACKVER value from /etc/slackware-version. Or cat it to the screen.
|
Might be easier to just source /etc/os-release, that way you will have the version number in the variable VERSION. Of course this would limit the script to be used on Slackware version that have that file, IIRC 14.0 and later.
|
|
1 members found this post helpful.
|
01-27-2014, 02:51 AM
|
#5
|
Senior Member
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,860
|
Quote:
Originally Posted by TobiSGD
Might be easier to just source /etc/os-release, that way you will have the version number in the variable VERSION. Of course this would limit the script to be used on Slackware version that have that file, IIRC 14.0 and later.
|
I did not know of that file. Cool!
|
|
|
01-27-2014, 08:32 AM
|
#6
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Quote:
Originally Posted by Ser Olmy
It's not silly at all. I say any operation that will be done enough times to justify making a script (or something similar), should be automated. Even if it takes you just as long to create the script as it would take to do everything manually, or perhaps even longer, you will have learned something along the way.
I've had a quick look, and here are my comments: - You're greeting the user, then telling him/her the script must be run as root. Why not just check for root instead?
|
- Ok, done that
Quote:
- You could try auto-detecting the Slackware version using the /etc/slackware-version file, and present the user with an option to override.
|
I am still not really sure about how to do that, I am learning and coding. Basically I am googling the option I want, seeing examples and putting into my script.
Quote:
- The script makes a "multilib" subdirectory in the current directory. Why not use mktemp -d instead?
|
What would "mktemp -d" do? Create a temporary directory that would be removed in the end?
I was thinking about creating a "/tmp/scs/" directory and work there, I am just thinking if it would be the better option and, if so, what would be the best way to implement it.
Quote:
- Several of the operations in the script could fail under various circumstances, such as the lftp download. How about adding some error checking/handling? Even "|| exit" beats having nothing at all.
|
I am pretty sure all Slackware installations have lftp
Quote:
Originally Posted by Richard Cranium
- You might want to use grep, awk, or even cut to get an initial SLACKVER value from /etc/slackware-version. Or cat it to the screen.
- You can simply use
Code:
$(/usr/share/mkinitrd/mkinitrd_command_generator.sh -r)
to generate the initrd
- /boot/vmlinuz-generic-* will match more than one kernel on a 32 bit system:
Code:
# ls /boot/vmlinuz-generic-*
/boot/vmlinuz-generic-3.2.29 /boot/vmlinuz-generic-smp-3.2.29-smp
|
Oh, thanks. Didn't know about "$(/usr/share/mkinitrd/mkinitrd_command_generator.sh -r)" and I didn't know about 32 bits slackware either, thanks for the heads up.
Quote:
Originally Posted by TobiSGD
Might be easier to just source /etc/os-release, that way you will have the version number in the variable VERSION. Of course this would limit the script to be used on Slackware version that have that file, IIRC 14.0 and later.
|
I want to make it compatible with as many slackware versions as posible
|
|
|
01-27-2014, 08:48 AM
|
#7
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
Quote:
Originally Posted by moisespedro
I am pretty sure all Slackware installations have lftp
|
What about servers being temporary unavailable or an unreliable network connection (for example with a bad WLAN signal)?
|
|
|
01-27-2014, 08:50 AM
|
#8
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep:
|
Quote:
Originally Posted by moisespedro
What would "mktemp -d" do? Create a temporary directory that would be removed in the end?
|
Type man mktemp and all will be revealed.
OK, it creates a unique temporary directory in /tmp, and echos the directory name to stdout. Thus,
Code:
TMP_DIR=$(mktemp -d)
would create the directory and store the name in the TMP_DIR variable. You could then end your script with rm -r $TMP_DIR.
Quote:
Originally Posted by moisespedro
I am pretty sure all Slackware installations have lftp
|
Are you also sure all Slackware systems have Internet connectivity that won't be interrupted, and have ample free diskspace for the downloaded files? If they don't, your script will just go ahead and install whatever has been downloaded. That could have quite unfortunate consequences.
|
|
|
01-27-2014, 08:53 AM
|
#9
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Oh, now I get what you are saying. Will look into that, thanks.
|
|
|
01-27-2014, 09:25 AM
|
#10
|
Member
Registered: Nov 2013
Posts: 744
Rep:
|
i dont know about lftp, but wget is persistent by default
so if the connection goes down it will continue when its back
guess it still can fail if there is no space on the disk
|
|
|
01-27-2014, 09:36 AM
|
#11
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
multilib directory is only 248Mb, what about a message "Please make sure you have at least 1Gb free" or something like that and a md5sum check before installing the packages? If it is correct, it installs them. If not, it tries to run lftp again. It seems reasonable to me.
|
|
|
01-27-2014, 10:16 AM
|
#12
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep:
|
The md5 check is a great idea.
When it comes to software design (and make no mistake, you're creating software here), it's usually best to make as few assumptions as possible. In this case, it is quite reasonable to assume that the script is being run on a Slackware system, since that's the whole point of the script, but beyond that you should check all prerequisites, or handle error conditions, or both.
The more you play with the core components of the system, the more careful you'll need to be. And you certainly do some potentially dangerous stuff; among other things, your script replaces glibc. That's an operation you want to make sure is atomic; either glibc gets upgraded or it's left completely untouched. Not "glibc was upgraded, but the other components weren't" or "the upgrade process for glibc started but was interrupted by [whatever], so who knows what the state of glibc is now".
Same goes for direct user input (which should be avoided if at all possible; selection menus are better): Expect characters instead of numbers, the Slackware version spelled out completely as "Slackware 14.1", the wrong version number being entered (you script should double-check and produce an "are you sure" warning), nonsense being entered because something was accidentally pasted or stuck in the keyboard buffer etc. etc.
Of course, some or all of this may be omitted if the script is for personal use only, and you're sure you'll never make any mistakes (yeah, right), but if others may use this particular script, you need to be prepared for anything.
|
|
|
01-27-2014, 10:26 AM
|
#13
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Quote:
Originally Posted by Ser Olmy
The md5 check is a great idea.
When it comes to software design (and make no mistake, you're creating software here), it's usually best to make as few assumptions as possible. In this case, it is quite reasonable to assume that the script is being run on a Slackware system, since that's the whole point of the script, but beyond that you should check all prerequisites, or handle error conditions, or both.
The more you play with the core components of the system, the more careful you'll need to be. And you certainly do some potentially dangerous stuff; among other things, your script replaces glibc. That's an operation you want to make sure is atomic; either glibc gets upgraded or it's left completely untouched. Not "glibc was upgraded, but the other components weren't" or "the upgrade process for glibc started but was interrupted by [whatever], so who knows what the state of glibc is now".
Same goes for direct user input (which should be avoided if at all possible; selection menus are better): Expect characters instead of numbers, the Slackware version spelled out completely as "Slackware 14.1", the wrong version number being entered (you script should double-check and produce an "are you sure" warning), nonsense being entered because something was accidentally pasted or stuck in the keyboard buffer etc. etc.
Of course, some or all of this may be omitted if the script is for personal use only, and you're sure you'll never make any mistakes (yeah, right), but if others may use this particular script, you need to be prepared for anything.
|
It was going to be for personal use but I am trying to make it as good as posible (with what I know/can find on Google). I am tyring to make it as user-friendly as posible. And by user-friendly I mean a script that tells you exactly what it is going to do and it easily tells you how to use it. I finally figured out how to detect Slackware version (although I know it won't work on all cases but it is the best that I can do, the way I am doing it, it assumes the user never edited '/etc/slackware-version/' file. And about direct user input I can't think about a better way of getting the slackware version (if it is not correct) other than asking the user.
|
|
|
01-27-2014, 11:10 AM
|
#14
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Having trouble with the md5. I am following http://www.slackware.com/~alien/mult.../CHECKSUMS.md5 but the file alienbob provides check for files that doesn't exist. And besides that I don't know how would I implement it
EDIT: Actually it only fails while checking
e2ffbeed099cd689a86626eaf050e95d ./slackware64-compat32/HEADER.txt
EDIT2: Already figured out how to workaround it, it has the same md5 as README so the script will duplicate README as Header.txt. Now I just need to know how to implement it.
Last edited by moisespedro; 01-27-2014 at 11:20 AM.
|
|
|
01-27-2014, 11:46 AM
|
#15
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Ok, you can check out the new code here. I've change a few things and there is a few commentaries on it, thanks.
|
|
|
All times are GMT -5. The time now is 04:08 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|