Welcome
Welcome to refracta

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

help with a bash script

If it's not on-topic, it's in here.

help with a bash script

Postby nadir » Tue Nov 08, 2016 9:44 pm

I could need a little help with a raw, short shell script (just some commands in a script.
1) First question
Before running the script, i would need to enter the content of two variables:
# insert PKG and VERSION
PKG="name_of_module"
VERSION="version_of_module"

how can i check if i missed to insert them and stop the script?

2) Are there any very obvious errors or problems

Code: Select all
#!/usr/bin/bash

# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   printf "This script must be run as root"
   exit 1
fi


# insert PKG and VERSION
PKG="name_of_module"
VERSION="version_of_module"

PKG_DESTDIR=/tmp/sources
PKG_BUILDIR=$PKG_DESTDIR/$PKG
SOURCE_DIR=$(pwd)

# 1)  change ownership and permissions
chown -R 0:0 .
chmod -R u+w,go-w,a+rX-s .

# 2) compile 
perl Makefile.PL || exit 1
INSTALLDIRS=vendor
make || exit 1
mkdir  $PKG_BUILDDIR || exit 1
make DESTDIR=$PKG_BUILDIR install || exit 1

# 3) clean up  and prepare
cd $PKG_BUILDIR
strip --strip-unneeded usr/bin/* usr/lib/*.so*
rm -f usr/info/dir
gzip -9N usr/info/*
gzip -9N usr/man/*/*.?
mkdir -p $PKG_DESTDIR/$PKG/usr/doc/$PKG-$VERSION
cd $SOURCE_DIR
cp -a AUTHORS COPYING README TODO FAQ /tmp/sources/$PGK_BUILDIR/usr/doc/$PKG-$VERSION

mkdir $PKG_BUILDIR/usr/description
vi $PKG_BUILDIR/usr/description/en

# 4) build the package
makepkg -l /tmp/$PKG-$VERSION-i486-1.tlz

exit 0



To give the idea:
I download a perl module from github.
I unpack it
i put make_perl_module.sh in the same directory like the *zip and the unzipped folder
i cd to the unzipped folder and do
../make_perl_module.sh

Here are the manual steps i would do, without script, after unzipping and cd to the unzipped folder:
Code: Select all
chown -R 0:0 .
chmod -R u+w,go-w,a+rX-s .

Makefile.PL
INSTALLDIRS=vendor
make
mkdir /tmp/sources/package-foo
make DESTDIR=$PKG install

strip --strip-unneeded usr/bin/* usr/lib/*.so*
rm -f usr/info/dir
gzip -9N usr/info/*
gzip -9N usr/man/*/*.?
mkdir -p usr/doc/foo-1.2.3
cd /directory-where-source-was-decompressed/foo-1.2.3
cp -a AUTHORS COPYING README TODO FAQ /tmp/sources/package-foo/usr/doc/foo-1.2.3

mkdir description
vi description/en

makepkg -l /tmp/foo-1.2.3-i486-1.tlz


tia.
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1160
Joined: Wed Mar 09, 2011 4:18 am
Location: here

Re: help with a bash script

Postby fsmithred » Tue Nov 08, 2016 10:06 pm

Not certain I understand the question. Maybe...

Test to see if the vars are empty -
Code: Select all
if [ -z "$PKG" ] ; then exit


If you need to keep changing what those vars are set to, you could clear them with unset at the end of the script. That way, you'll get warned if you didn't set them.

An alternative would be put the values as arguments in the command line.
Code: Select all
PKG="$1"
VERSION="$2"
User avatar
fsmithred
 
Posts: 2093
Joined: Wed Mar 09, 2011 9:13 pm

Re: help with a bash script

Postby nadir » Tue Nov 08, 2016 11:08 pm

Thanks a lot.

I changed as adviced.
Here is the new version:

Code: Select all
#!/usr/bin/bash 

# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   printf "This script must be run as root"
   exit 1
fi
----------------------------------------------

# insert PKG and VERSION
PKG=
VERSION=
if [ -z "$PKG" ] ; then printf  "PKG not declared"  && exit; fi
if [ -z "$VERSION" ] ; then  printf "VERSION not declared" && exit; fi

PKG_BUILDIR="/tmp/sources/$PKG"
SOURCE_DIR="$(pwd)"
----------------------------------------------

# 1)  change ownership and permissions
chown -R 0:0 .
chmod -R u+w,go-w,a+rX-s .
----------------------------------------------

# 2) compile 
perl Makefile.PL || { echo "perl Makefile faile" && exit 1 }
INSTALLDIRS=vendor
make || {echo "make failed" &&  exit 1 }
mkdir  "$PKG_BUILDIR" || { echo "mkdir $PKG_BUILDIR failed " && exit 1 }
make DESTDIR="$PKG_BUILDIR"  install || { echo "make install failed " && exit 1 }
----------------------------------------------


# 3) clean up  and prepare
cd $PKG_BUILDIR
strip --strip-unneeded usr/bin/* usr/lib/*.so*
rm -f usr/info/dir
gzip -9N usr/info/*
gzip -9N usr/man/*/*.?
mkdir -p "$PKG_BUILDIR"/usr/doc/"$PKG-$VERSION"
cd "$SOURCE_DIR"
cp -a AUTHORS COPYING README TODO FAQ /tmp/sources/"$PGK_BUILDIR"/usr/doc/"$PKG-$VERSION"

mkdir "$PKG_BUILDIR"/description
vi "$PKG_BUILDIR"/description/en
----------------------------------------------


# 4) build the package
makepkg -l /tmp/"$PKG"-"$VERSION"-i486-1.tlz
----------------------------------------------

exit 0


http://sprunge.us/dDTQ
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1160
Joined: Wed Mar 09, 2011 4:18 am
Location: here

Re: help with a bash script

Postby fsmithred » Wed Nov 09, 2016 1:25 am

Cleaned up some syntax errors and got it to run. Here's the last part of the output.
Code: Select all
Installing /tmp/sources/libwww-perl/usr/local/bin/lwp-request
Installing /tmp/sources/libwww-perl/usr/local/bin/lwp-dump
Appending installation info to /tmp/sources/libwww-perl/usr/local/lib/x86_64-linux-gnu/perl/5.20.2/perllocal.pod
strip: 'usr/bin/*': No such file
strip: 'usr/lib/*.so*': No such file
gzip: usr/info/*: No such file or directory
gzip: usr/man/*/*.?: No such file or directory
cp: target ‘/tmp/sources//usr/doc/libwww-perl-6.15’ is not a directory
../make_perl_modules.sh: line 50: makepkg: command not found


Here's the script:
http://sprunge.us/VXJV
User avatar
fsmithred
 
Posts: 2093
Joined: Wed Mar 09, 2011 9:13 pm

Re: help with a bash script

Postby nadir » Wed Nov 09, 2016 2:58 am

Hey thanks.
I was just in the middle of an syntax error and despite all exit's one line after the other not able to figure it out,
then found your version here.
Yes, it runs through

But two bad news:
a) it kinda installs to /lib/ not to whatever-the-path-to-perl-pm-might-be
and
b) i ran into a second, unrlated problem. versions of perl store their pm's at different locations, urgh
and to make it worse: "jul install perl" of a higher version installed it to /usr/local/bin/perl or such

Oh my, what a ****. This perl thing.
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1160
Joined: Wed Mar 09, 2011 4:18 am
Location: here

Re: help with a bash script

Postby fsmithred » Wed Nov 09, 2016 1:52 pm

I would think you could change /usr/local to just /usr in the Makefile. Normally, you'd run a configure script with a PREFIX= option, but it's also possible to edit the Makefile directly. I don't know about the other problems.

Here's a suggestion. It does make the substitutions, but I don't know if it fixes the problem.
Code: Select all
# 2) compile 
perl Makefile.PL || { echo "perl Makefile faile" ; exit 1 ; }
INSTALLDIRS=vendor
sed -i 's:/usr/local:/usr:g' Makefile
sed -i '/SITEPREFIX/s/\/local//' Makefile
make || { echo "make failed" ;  exit 1 ; }
mkdir -p "$PKG_BUILDIR" || { echo "mkdir $PKG_BUILDIR failed " ; exit 1 ; }
make DESTDIR="$PKG_BUILDIR"  install || { echo "make install failed " ; exit 1 ; }
#----------------------------------------------
User avatar
fsmithred
 
Posts: 2093
Joined: Wed Mar 09, 2011 9:13 pm

Re: help with a bash script

Postby nadir » Thu Nov 10, 2016 3:49 am

Let me look into that.
And i did ran into configure PREFIX. Which is rather stragghtforward. Perl-Modules (and youtube-viewer) use Build.PL, which created a Build script, which you run for make and make install.
Which is pretty confusing.
What makes is worth is that perl get's installed to /usr/bin or to /usr/local/bin or toperl5/perlbrew/bin/ ; and the according lib files for the modules.
I always got that wrong (and youtube-viewer needs a Version higher than the system one).

Not sure if i will get my head deeper into Build.PL and Build or give up for now. Yesterday i used Cpan to install all modules, and it were round the lines of 50 ...
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1160
Joined: Wed Mar 09, 2011 4:18 am
Location: here


Return to General Nonsense

Who is online

Users browsing this forum: No registered users and 1 guest

cron
suspicion-preferred