LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-11-2015, 08:12 AM   #1
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
Simple universal package installer (SUPI !) script


Following script extracts files from packages (rpm, txz, tgz, deb or arch) and creates 2 scripts: copier.sh and remover.sh, which can then be run as root to copy all the files into the system, or remove them from the system. One can keep a set of packages (may be of different types) in a folder, cd to that folder, give command 'supi *' to create copier.sh and remover.sh. They only copy and remove the files and do not run any pre or post-install commands.

Code:
#! /bin/bash
# USAGE MESSAGE IF NO PACKAGE NAME: 
if [ -z $1 ]
then
  echo "USAGE: supi <packagename>"
  exit
fi
mkdir supitemp 

# EXTRACT EACH FILE: 
for FILE1 in "$@"
do
echo $FILE1 | awk ' /.rpm$/{ system("cp " $FILE1 " supitemp; cd supitemp; rpm2cpio " $FILE1 " | cpio -idvm; rm " $FILE1 "; cd ..")}'
echo $FILE1 | awk ' /.txz$/{ system("tar -Jxvf " $FILE1 " -C supitemp")}' 
echo $FILE1 | awk ' /.tgz$/{ system("tar -xvzf " $FILE1 " -C supitemp")}' 
echo $FILE1 | awk ' /.pkg.tar.xz$/{ system("tar -Jxvf " $FILE1 " -C supitemp")}'
echo $FILE1 | awk ' /.deb$/{ system("ar x " $FILE1 "; tar -Jxvf data.tar.xz -C supitemp; tar -zxvf data.tar.gz -C supitemp; rm data.tar.xz data.tar.gz control.tar.gz debian-binary")}'
done

# FIND FILES, LINKS AND NEW DIRECTORIES TO BE CREATED: 
find ./supitemp -type f > /tmp/filelist
find ./supitemp -type l >> /tmp/filelist
find ./supitemp -type d | awk ' { if ( system(" [ -d " substr($1,11) " ] ")  ) print $1 } ' > /tmp/newdirlist

# CREATE COPIER.SH
echo "#! /bin/bash" > copier.sh
cat /tmp/newdirlist | awk ' {print "mkdir -v ",substr($1,11)} ' >> copier.sh 
cat /tmp/filelist | awk ' {print "cp -vip ",$1," ",substr($1,11)} ' >> copier.sh

# CREATE REMOVER.SH
echo "#! /bin/bash" > remover.sh
cat /tmp/filelist | awk ' {print "rm -v ",substr($1,11)} ' >> remover.sh
tac /tmp/newdirlist | awk ' {print "rmdir -v ",substr($1, 11)} ' >> remover.sh 

# MAKE THEM EXECUTABLE: 
chmod +x copier.sh
chmod +x remover.sh
This is obviously not a desirable way to install packages (which is to install from one's own repository, using native package manager) but it can be used to test foreign packages that are not available for one's own distribution. Are there any code errors in this script?

Last edited by rng; 12-12-2015 at 09:36 PM.
 
Old 12-12-2015, 01:40 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
A nice little project of more than trivial complexity. Well done!

I am sure there are errors, since there is no software without errors. I suggest to test it, and if it doesn't behave as expected, ask specific questions.

For now, let me point out a few areas that can be improved:

The four awk statements under EXTRACT FILES are inefficient and awkward (pun intended). This is handled much better with a shell case statement.
Or at least call awk once instead of four times. Awk has been designed to handle more than one case.

cat somefile | awk '...' is known as cat abuse (check it out on wikipedia). Just run awk '...' somefile.

Rather than using awk to remove the string "./supitemp" from file and directory names, don't generate that string in the first place. I.e., instead of find ./supitemp, run cd supitemp; find .; cd -.

Also check out the links in my signature. I am sure others will chime in with more suggestions.

Last edited by berndbausch; 12-12-2015 at 01:42 AM.
 
Old 12-12-2015, 05:52 AM   #3
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
I will try to implement your suggestions.

Last edited by rng; 12-12-2015 at 09:13 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] UNetBootIn vs. Universal-USB-Installer? littlebigman Linux - Newbie 4 03-23-2012 07:35 PM
[SOLVED] Can not boot after using universal us linux installer ajithkanu Linux - Newbie 5 10-28-2011 01:47 AM
Universal USB Installer Makes OS or Preparation to Install? Novatian Linux - Software 1 03-18-2011 10:34 AM
Modifying MBR in universal installer twelvenine Puppy 4 03-30-2010 02:03 AM
hpux, putty, x display, oracle universal installer? boyd98 Other *NIX 1 02-05-2009 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:09 PM.

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