Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: H_TeXMeX_H on 1 March 2006, 23:14

Title: Self-extracting archive
Post by: H_TeXMeX_H on 1 March 2006, 23:14
I was trying to make my own rpms but upon encountering lots of problems and just cuz it was a pain in the ass to do I found that you can actually make your own self-extracting archives ... which is really cool

http://linux.org.mt/article/selfextract (http://linux.org.mt/article/selfextract)

An example ... after compiling and installing the game toppler (http://toppler.sourceforge.net/)

./configure
make
make prefix=/home/USERNAME/Stuff/MAKEBIN install

add all the files inside /home/USERNAME/Stuff/MAKEBIN to a tar.gz call it toppler-1.1.2-fc4-i686-bin.tar.gz

write a header script call it toppler-header

Code: [Select]
#!/bin/sh

SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`

echo ""
echo "toppler-1.1.2-fc4-i686-bin"
echo "this package is built for Fedora Core 4 on i686 architecture"
echo ""
echo "!!! You must be root to install this package !!!"
echo ""

echo -n "Options: Type i to install, r to remove, or any other key to quit? "
read switch
if  [ "$switch" == "i" ]; then
  echo "Installing ... stand by"
  tail +$SKIP $0 | tar xz -C /usr/local
  echo "Done"
elif [ "$switch" == "r" ]; then
  echo "Removing ... stand by"
  rm /usr/local/bin/toppler
  rm /usr/local/man/man6/toppler.6
  rm /usr/local/share/applications/toppler.desktop
  rm /usr/local/share/doc/toppler/AUTHORS
  rm /usr/local/share/doc/toppler/ChangeLog
  rm /usr/local/share/doc/toppler/COPYING
  rm /usr/local/share/doc/toppler/NEWS
  rm /usr/local/share/doc/toppler/README
  rmdir /usr/local/share/doc/toppler
  rm /usr/local/share/locale/de/LC_MESSAGES/toppler.mo
  rm /usr/local/share/locale/fi/LC_MESSAGES/toppler.mo
  rm /usr/local/share/locale/fr/LC_MESSAGES/toppler.mo
  rm /usr/local/share/locale/pt/LC_MESSAGES/toppler.mo
  rm /usr/local/share/locale/sv/LC_MESSAGES/toppler.mo
  rm /usr/local/share/pixmaps/toppler.xpm
  rm /usr/local/share/toppler/abc.ttm
  rm /usr/local/share/toppler/ball2.ttm
  rm /usr/local/share/toppler/m1.ttm
  rm /usr/local/share/toppler/pasi2.ttm
  rm /usr/local/share/toppler/ball1.ttm
  rm /usr/local/share/toppler/ball3.ttm
  rm /usr/local/share/toppler/m2.ttm
  rm /usr/local/share/toppler/toppler.dat
  rmdir /usr/local/share/toppler
  rm /usr/local/var/toppler/toppler.hsc
  rmdir /usr/local/var/toppler
  echo "Done"
else
  exit 1
fi

exit 0

__ARCHIVE_FOLLOWS__

(I wrote this myself :D)

and finally ...

cat toppler-header toppler-1.1.2-fc4-i686-bin.tar.gz > toppler-1.1.2-fc4-i686-bin.sh

You might want to note that you can install and remove the package without needing rpm ... that's exactly what I wanted ... anyway I thought it was a cool

And if you wanted to, you could make it input the install location ... /usr/local is the most logical place to put it though
Title: Re: Self-extracting archive
Post by: Aloone_Jonez on 1 March 2006, 23:28
This looks great, it's a classic example of how UNIX's superiour scripting capabilities totally blow$ Winblow$ out of the water.
Title: Re: Self-extracting archive
Post by: mobrien_12 on 2 March 2006, 05:54
I'm pretty good at building RPMS if I can find some SPEC file to start with and update.  Still haven't mastered writing SPEC files from scratch.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 2 March 2006, 20:43
Yeah, that's the biggest problem with rpms ... the damn spec files ... and even if you do know how to make them, they gotta be done right or there will be problems
Title: Re: Self-extracting archive
Post by: Aloone_Jonez on 2 March 2006, 21:44
Packages suck shit in general, if I made some softwere (and I do have a little project in progress) I'd release the binary in a simple archive so all you do is make a directory and extract it, if it was large and needed to alter the desktop I'd write a script like this one.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 4 March 2006, 21:50
Well I wrote a script that makes self-extracting and removing packages (I've tried to make it as safe as possible so it only deletes stuff you actually installed with the packaging system and only in /usr/local) I also added an extract feature so you can extract the archive inside to anywhere you want.

Code: [Select]
#!/bin/sh

if [ -a /tmp/Sirx ]; then
 rm -rf /tmp/Sirx
fi

mkdir /tmp/Sirx
mkdir /tmp/Sirx/local

echo "Build package from [s]ource or from [b]inary? "
read pack

if [ "$pack" == "s" ]; then
 mkdir /tmp/Sirx/source
 echo "Path to folder containing configure and/or Makefile? "
 read inputsource
 cd "$inputsource"
 cp -r * /tmp/Sirx/source
 cd /tmp/Sirx/source
 if [ -a configure ]; then
  if ./configure --prefix=/usr/local ; then
   echo "configure complete"
  else
   echo "!configure failed!"
   read dummy
   exit 1
  fi
 fi
 if make ; then
  echo "make complete"
 else
  echo "!make failed!"
  read dummy
  exit 1
 fi
 if make prefix=/tmp/Sirx/local install ; then
  echo "make install complete"
 else
  echo "!make install failed!"
  read dummy
  exit 1
 fi
elif [ "$pack" == "b" ]; then
 echo "Path to folder containing binary? "
 read inputbinary
 cd "$inputbinary"
 cp -r * /tmp/Sirx/local
else
 echo "!Incorrect input!"
 read dummy
 exit 1
fi

cd /tmp/Sirx/local

echo "Name of output package file? "
read outputfilename

tar -czf /tmp/Sirx/"$outputfilename".tar.gz *

find -type f > /tmp/Sirx/remove.txt

cd /tmp/Sirx/
sed 's/\./\/usr\/local/' remove.txt > removefixed.txt

echo "#!/bin/sh" > header.sh
echo SKIP=\`awk \'\/\^__ARCHIVE_FOLLOWS__\/ { print NR + 1\; exit 0\; }\' \$0\` >> header.sh
echo \echo \""$outputfilename"\" >> header.sh
echo \echo \"Select: \[i\]nstall, \[r\]emove, e\[x\]tract, or any other key to quit\? \" >> header.sh
echo "read switch" >> header.sh
echo \if  \[ \"\$switch\" == \"i\" \]\; \then >> header.sh
echo \echo \"Installing . . .\" >> header.sh
echo \tail +\$SKIP \$0 \| tar xz -C \/usr\/local >> header.sh
echo \echo \"Done\" >> header.sh
echo \elif \[ \"\$switch\" == \"r\" \]\; \then >> header.sh
echo \echo \"Removing . . .\" >> header.sh
while read line
do
 echo rm "$line" >> header.sh
done < removefixed.txt
echo \echo \"Done\" >> header.sh
echo \elif \[ \"\$switch\" == \"x\" \]\; \then >> header.sh
echo \echo \"Extract directory\? \" >> header.sh
echo "read extract" >> header.sh
echo \echo \"Extracting . . .\" >> header.sh
echo \tail +\$SKIP \$0 \| tar xz -C \"\$extract\" >> header.sh
echo \echo \"Done\" >> header.sh
echo "else" >> header.sh
echo "exit 1" >> header.sh
echo "fi" >> header.sh
echo "exit 0" >> header.sh
echo "__ARCHIVE_FOLLOWS__" >> header.sh

cat header.sh "$outputfilename".tar.gz > $HOME/"$outputfilename".sh

cd $HOME
echo "Finished, check your home folder . . . press [Enter] to quit"
read dummy
rm -rf /tmp/Sirx
exit 0

I also put it up on my site (http://htexmexh.tripod.com/) along with the home-made man page for it and further info on how to use it properly.
Title: Re: Self-extracting archive
Post by: ReggieMicheals on 4 March 2006, 23:00
What UNIX needs is less irritating makefiles and more windows-like installers/uninstallers with actual binaries if the home market is going to accept UNIX OSes. Its a small step, but it's a step nonetheless...
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 5 March 2006, 03:17
I like binaries ... but not Window$ installers ... after switching to Linux, I realized how retarded the Window$ installers really are. They all go something like this if I remember correctly:

Double-click the exe file ... it loads after 1-2 min
"Blah, Blah, Blah, Blah, Blah, Blah ... click next" -> you click next
"Do you accept this 200 page EULA ?" Only option: Yes -> you click yes
click next 5 times
"Install to /Program File$ ?" -> yes
click next 5 more times
"Installing" ...
30-45 minutes later ... Done
And you goto the next installer and do it over again !!!

You wonder how efficient this system really is ... not at all efficient. I was really surprised by how easily and quickly RPMS install compared to the Window$ way. With rpm it takes like 2 steps max and installs nearly instantly. I'm never going back to Window$ ... or any of their inefficient bullshit.

If you want Linux installers try Loki ... too bad they went out of business.
Title: Re: Self-extracting archive
Post by: Aloone_Jonez on 5 March 2006, 16:52
It depends alot on the installer, I haven't had any trouble with OpenOffice, Opera and Firefox but some of the shareware shitware used to give me that kind of grief.
Title: Re: Self-extracting archive
Post by: ReggieMicheals on 5 March 2006, 18:37
Quote
You wonder how efficient this system really is ... not at all efficient. I was really surprised by how easily and quickly RPMS install compared to the Window$ way. With rpm it takes like 2 steps max and installs nearly instantly. I'm never going back to Window$ ... or any of their inefficient bullshit.

Yeah, you do have to wonder what moron came up with the idea. What would be better is something along the lines of a self extracting zip file with a self deletion program in the installed directory.
Title: Re: Self-extracting archive
Post by: Orethrius on 5 March 2006, 22:10
Quote from: ReggieMicheals
What would be better is something along the lines of a self extracting zip file with a self deletion program in the installed directory.


You mean emerge -C? :p
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 5 March 2006, 22:53
Ok ... here's the last version of the script ... you now have the ability to install and remove a program anywhere not just /usr/local ... as for the suggestion to put an uninstall script in the install directory ... there would be a lot of scripts there after installing lots of stuff. Besides, I keep the installers for everything I install just in case I need to re-install it.

Code: [Select]
#!/bin/sh

if [ -a /tmp/Sirx ]; then
 rm -rf /tmp/Sirx
fi

mkdir /tmp/Sirx
mkdir /tmp/Sirx/local

echo "Build package from [s]ource or from [b]inary? "
read pack

echo "Install path? "
read installpath

if [ "$pack" == "s" ]; then
 mkdir /tmp/Sirx/source
 echo "Path to folder containing configure and/or Makefile? "
 read inputsource
 cd "$inputsource"
 cp -r * /tmp/Sirx/source
 cd /tmp/Sirx/source
 if [ -a configure ]; then
  if ./configure --prefix="$installpath" ; then
   echo "configure complete"
  else
   echo "!configure failed!"
   read dummy
   exit 1
  fi
 fi
 if make ; then
  echo "make complete"
 else
  echo "!make failed!"
  read dummy
  exit 1
 fi
 if make prefix=/tmp/Sirx/local install ; then
  echo "make install complete"
 else
  echo "!make install failed!"
  read dummy
  exit 1
 fi
elif [ "$pack" == "b" ]; then
 echo "Path to folder containing binary? "
 read inputbinary
 cd "$inputbinary"
 cp -r * /tmp/Sirx/local
else
 echo "!Incorrect input!"
 read dummy
 exit 1
fi

cd /tmp/Sirx/local

echo "Name of output package file? "
read outputfilename

tar -czf /tmp/Sirx/"$outputfilename".tar.gz *

find -type f > /tmp/Sirx/remove.txt

cd /tmp/Sirx/
sed 's/\.//' remove.txt > removefixed.txt

echo "#!/bin/sh" > header.sh
echo SKIP=\`awk \'\/\^__ARCHIVE_FOLLOWS__\/ { print NR + 1\; exit 0\; }\' \$0\` >> header.sh
echo 'echo' \""$outputfilename"\" >> header.sh
echo 'echo "Select: [i]nstall, [r]emove, e[x]tract, or any other key to quit? "' >> header.sh
echo "read switch" >> header.sh
echo 'if [ "$switch" == "i" ]; then' >> header.sh
echo 'echo "Installing . . ."' >> header.sh
echo 'tail +$SKIP $0 | tar xz -C '"$installpath" >> header.sh
echo 'echo "Done"' >> header.sh
echo 'elif [ "$switch" == "r" ]; then' >> header.sh
echo 'echo "Removing . . ."' >> header.sh
while read line
do
 echo rm "$installpath""$line" >> header.sh
done < removefixed.txt
echo 'echo "Done"' >> header.sh
echo 'elif [ "$switch" == "x" ]; then' >> header.sh
echo 'echo "Extract directory? "' >> header.sh
echo "read extract" >> header.sh
echo 'echo "Extracting . . ."' >> header.sh
echo 'tail +$SKIP $0 | tar xz -C "$extract"' >> header.sh
echo 'echo "Done"' >> header.sh
echo "else" >> header.sh
echo "exit 1" >> header.sh
echo "fi" >> header.sh
echo "exit 0" >> header.sh
echo "__ARCHIVE_FOLLOWS__" >> header.sh

cat header.sh "$outputfilename".tar.gz > $HOME/"$outputfilename".sh

cd $HOME
echo "Finished, check your home folder . . . press [Enter] to quit"
read dummy
rm -rf /tmp/Sirx
exit 0
Title: Re: Self-extracting archive
Post by: piratePenguin on 6 March 2006, 19:25
Quote from: H_TeXMeX_H
I like binaries ... but not Window$ installers ... after switching to Linux, I realized how retarded the Window$ installers really are. They all go something like this if I remember correctly:

Double-click the exe file ... it loads after 1-2 min
"Blah, Blah, Blah, Blah, Blah, Blah ... click next" -> you click next
"Do you accept this 200 page EULA ?" Only option: Yes -> you click yes
click next 5 times
"Install to /Program File$ ?" -> yes
click next 5 more times
"Installing" ...
30-45 minutes later ... Done
And you goto the next installer and do it over again !!!
Yea, heh. Doing that for like 10+ packages would be hell.
Quote

If you want Linux installers try Loki ... too bad they went out of business.
There's also autopackage (http://autopackage.org/) and probably some others.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 6 March 2006, 21:24
Of course, the other problem is getting people to use your packaging software. So far I've only come across 1 autopackage for 1 program ... in the last year. There are far more RPMS out there than any other packaging system ... as far as I've seen. Too bad it's so hard to make them correctly.
Title: Re: Self-extracting archive
Post by: mobrien_12 on 8 March 2006, 03:10
Quote from: H_TeXMeX_H

"Installing" ...
30-45 minutes later ... Done
And you goto the next installer and do it over again !!!

You forgot the fact where you have to reboot after running most windows installers.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 8 March 2006, 04:49
Yeah ... I forgot about that ... well you can imagine that it takes a shitload more time on Window$ than installing stuff on Linux.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 21 March 2006, 03:27
I just installed Fedora Core 5 and the script doesn't work anymore ... it gives me these errors in connection to the tail and tar commands:

tail: cannot open `+21' for reading: No such file or directory

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors

Are the environment variables screwed ? How do I fix it ? :(
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 21 March 2006, 21:36
I've found out a bit more ...

Quote
> tail: cannot open `+7` for reading: No such file or directory.
 > Error in check sum 1640625506 1987377779
 > Problem with either License Agreement or j2sdk bianry.

The tail problem has been located, tail will not work with +/-
if its compiled with NLS and linked to glibc 2.3.3 (it checks posix
version to invalidate old style options).

A global fix for this is in the works... no need to go sedit on makefiles.



http://foo-projects.org/pipermail/lunar/2004-August/004505.html
Title: Re: Self-extracting archive
Post by: Aloone_Jonez on 21 March 2006, 23:06
Huh?
Don't get it, I'm a nube to all this scripting stuff.

Does this mean you've fixed it then?

Quote from: mobrien_12
You forgot the fact where you have to reboot after running most windows installers.

What installers on which Windows version?

I've never had to reboot after installing software on any modern (post 2k) OS unless it requires special drivers.
Title: Re: Self-extracting archive
Post by: piratePenguin on 22 March 2006, 01:46
Quote from: Aloone_Jonez

What installers on which Windows version?

I've never had to reboot after installing software on any modern (post 2k) OS unless it requires special drivers.
Install any software, and it'll ask you to reboot. Dunno why, probably because the people who wrote the installer software were retards, and were writing for retards.

Then there's DirectX and other shit which will tell you you HAVE TO reboot and not give you a cancel/later option. What's next? A 1 second timer so you can save your work?

When something's already loaded in RAM, updating it can bring bad news. So you update it before the system starts, after a reboot... That's the only time you should need to reboot for installing software, really.
Quote
Huh?
Don't get it, I'm a nube to all this scripting stuff.
There's a bug in the setup and a fix is in the works.
Title: Re: Self-extracting archive
Post by: mobrien_12 on 22 March 2006, 02:46
Penguin in right.  I have to use XP pro at work and it's install-reboot install-reboot.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 22 March 2006, 05:14
Actually ... I'll probably have to rewrite the script ... in a more universal fashion. But I guess that's one of the problems with scripts ... it may work well today ... but not tomorrow. Maybe I'll try doing it in python ... or maybe just stay away from specialized commands like tail and sed etc.
Title: Re: Self-extracting archive
Post by: piratePenguin on 22 March 2006, 05:38
Quote from: H_TeXMeX_H
Actually ... I'll probably have to rewrite the script ... in a more universal fashion. But I guess that's one of the problems with scripts ... it may work well today ... but not tomorrow. Maybe I'll try doing it in python ... or maybe just stay away from specialized commands like tail and sed etc.

"specialized" ?
tail and sed are pretty standard on UNIXes..

That bug is pretty shit. Bugs like that don't really happen alot, though.
Title: Re: Self-extracting archive
Post by: H_TeXMeX_H on 22 March 2006, 19:40
Well ... yeah, I guess ... it certainly could be done without the use of tail and sed ... then if any bugs pop up (rare as they may be) it won't affect the script ... so I don't have to rewrite it. But, ok, maybe sed won't have any future bugs :D