Difference between revisions of "Uuencode"

From Bashlinux
Jump to: navigation, search
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
= uuencode =
+
This is technique is useful to embed a binary file on a script. First ensure to have the proper package installed
This is useful to install a binary from an script like an executable file, a zip or even an rpm. First be sure to have the needed tools installed
 
 
<pre><nowiki>
 
 
  yum -y install sharutils
 
  yum -y install sharutils
</nowiki></pre>
 
  
 +
=== How to encode binary files to text ===
 +
Execute the following command
 +
/usr/bin/uuencode /path/to/binary/file -
 +
: Note the hyphen at the end of the command
  
==== Encode - Binary to text ====
+
=== How to decode text files to binary ===
Suppose we want to encode the `~/.Xauthority` file, the execute in command line
+
To restore a binary file from text copy the result string from stdin to your script as follows
+
  /usr/bin/uudecode > /path/to/binary/file << 'EOF'
<pre><nowiki>
 
/usr/bin/uuencode ~/.Xauthority -
 
</nowiki></pre>
 
 
 
Note the dash at the end of the command
 
 
 
==== Decode - Text to binary ====
 
Then copy the result string from stdin to your script as follows
 
 
<pre><nowiki>
 
  /usr/bin/uudecode > ~/.Xauthority << 'EOF'
 
 
  begin 644 -
 
  begin 644 -
 
  M````!'\```$``3``$DU)5"U-04=)0RU#3T]+244M,0`0(581,6(<1J&_0`OE
 
  M````!'\```$``3``$DU)5"U-04=)0RU#3T]+244M,0`0(581,6(<1J&_0`OE
Line 29: Line 18:
 
  end
 
  end
 
  EOF
 
  EOF
</nowiki></pre>
+
The output of the above command always must be redirected to a file.
 
 
Since this commands yields the result to stdin you should redirect it to a file, specially with decoding process that will generate a binary file.
 

Latest revision as of 01:57, 10 June 2015

This is technique is useful to embed a binary file on a script. First ensure to have the proper package installed

yum -y install sharutils

How to encode binary files to text

Execute the following command

/usr/bin/uuencode /path/to/binary/file -
Note the hyphen at the end of the command

How to decode text files to binary

To restore a binary file from text copy the result string from stdin to your script as follows

/usr/bin/uudecode > /path/to/binary/file << 'EOF'
begin 644 -
M````!'\```$``3``$DU)5"U-04=)0RU#3T]+244M,0`0(581,6(<1J&_0`OE
M_:%-L@$``!5L;V-A;&AO<W0N;&]C86QD;VUA:6X``3``$DU)5"U-04=)0RU#
93T]+244M,0`0(581,6(<1J&_0`OE_:%-L@``
`
end
EOF

The output of the above command always must be redirected to a file.