LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-27-2014, 12:40 AM   #1
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Rep: Reputation: 195Reputation: 195
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.
 
Old 01-27-2014, 01:27 AM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
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.
Old 01-27-2014, 01:31 AM   #3
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
  • 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
 
Old 01-27-2014, 02:39 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by Ser Olmy View Post
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.
Old 01-27-2014, 02:51 AM   #5
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by TobiSGD View Post
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!
 
Old 01-27-2014, 08:32 AM   #6
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Original Poster
Rep: Reputation: 195Reputation: 195
Quote:
Originally Posted by Ser Olmy View Post
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 View Post
  • 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 View Post
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
 
Old 01-27-2014, 08:48 AM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by moisespedro View Post
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)?
 
Old 01-27-2014, 08:50 AM   #8
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Quote:
Originally Posted by moisespedro View Post
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 View Post
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.
 
Old 01-27-2014, 08:53 AM   #9
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Original Poster
Rep: Reputation: 195Reputation: 195
Oh, now I get what you are saying. Will look into that, thanks.
 
Old 01-27-2014, 09:25 AM   #10
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
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
 
Old 01-27-2014, 09:36 AM   #11
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Original Poster
Rep: Reputation: 195Reputation: 195
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.
 
Old 01-27-2014, 10:16 AM   #12
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
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.
 
Old 01-27-2014, 10:26 AM   #13
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Original Poster
Rep: Reputation: 195Reputation: 195
Quote:
Originally Posted by Ser Olmy View Post
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.
 
Old 01-27-2014, 11:10 AM   #14
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Original Poster
Rep: Reputation: 195Reputation: 195
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.
 
Old 01-27-2014, 11:46 AM   #15
moisespedro
Senior Member
 
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223

Original Poster
Rep: Reputation: 195Reputation: 195
Ok, you can check out the new code here. I've change a few things and there is a few commentaries on it, thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
slackware wireless configuration script omissions Rod3775 Slackware 1 10-03-2012 07:24 AM
Old Slackware from 1994/95, LaTeX-package KOMA-Script in Slackware (t-series) markush Slackware 9 05-28-2012 07:22 AM
Script configuration command dbabalola2 Linux - Newbie 4 12-19-2007 02:50 AM
Here's my post-installation slackware configuration script (great for newbies) WindowBreaker Slackware 25 10-05-2006 01:43 AM
how to use automatic configuration script???? TAAN Linux - Networking 1 06-23-2004 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration