Skip to content

Step 3: download the program

iVAN edited this page Mar 16, 2022 · 1 revision

For any operation, for example building a file or replacing an existing one during an update, it is a good practice to create a temporary folder "/tmp" where you can perform all operations, then:

mkdir tmp
cd tmp

Finally we can dedicate ourself to the real program. We can download it from an URL or compile it using "whatever" we have installed on our host (wget and curl to download it from an URL, but also tar or ar to uncompress .tar and .deb packages, or make or any other compiler if you want to compile it from scratch). This part is at your complete discretion.

I can only suggest my most used procedures.

Example1: download the lates version, always

This is the easier way because we are downloading a ready to use program from somewhere, for example, if we have an AppImage on a GitHub repository, this command will download a file ending with the .AppImage extension:

wget https://github.com/$(wget https://github.com/$USER/$REPOSITORY/releases/latest -O - | egrep '/.*/.*/.*AppImage' -o)

If there is also an external .zsync file needed to update the program, add this command:

wget https://github.com/$(wget https://github.com/$USER/$REPOSITORY/releases/latest -O - | egrep '/.*/.*/.*AppImage.zsync' -o)

In case we have an updatable AppImage that uses "appimageupdatetool", we can download one from the main repository and rename it as updater in /opt/$APP, this way:

wget https://github.com/AppImage/AppImageUpdate/releases/download/continuous/appimageupdatetool-x86_64.AppImage -O updater

If the AppImage have not an official way to be updated, we have to create a text file where the name of the downloaded file is stored. Being this the only file stored in ./tmp, we can proceed this way using the ls command:

version=$(ls /opt/$APP/tmp)
echo "$version" >> /opt/$APP/version

Now we have a point of reference to check the availability of a file with the same name in the same link from which we downloaded the current one (see STEP 6).

Example2: download and uncompress a .deb file

To download a .deb package we can use the same procedure we have just seen in the Example1, but we also have an useful tool named pkg2appimage that can help us in finding some packages we cannot download normally, for example, this is the command we use to download the official "Brave Browser":

wget https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/tools/pkg2appimage
chmod a+x ./pkg2appimage
echo 'app: brave
ingredients:
  package: brave-browser
  dist: stable
  sources: 
    - deb https://brave-browser-apt-release.s3.brave.com stable main' >> recipe.yml
./pkg2appimage ./recipe.yml

The first command downloads a customized version of the pkg2appimage original script I have edited to download these packages, once it has made executable (line 2) I have created a recipe.yml file (from line 3 to 8) containing the instructions that pkg2appimage must read (line 9) to create the AppDir.

More details on how to use "pkg2appimage" at https://github.com/AppImage/pkg2appimage

In any case we can use the trick we have seen before to get the name of the latest version of the .deb package, like this:

underscore=_
mkdir version
mv ./$APP/$APP$underscore*.deb ./version/
version=$(ls /opt/$APP/tmp/version)
echo "$version" >> /opt/$APP/version

The line 1 is used to prevent some errors while reading the name of the file in the line 3, the line two will create a subdirectory named "version" where the main .deb package of $your-app will be stored (just in case there are several packages downloaded by pkg2appimage), that package's complete name will be the version (lines 4 and 5).

However, not always we have the needings of download several packages. If the .deb package is easier to download, we can use wget and ar instead, this way (here OcenAudio):

wget https://www.ocenaudio.com/downloads/ocenaudio_mint64.deb
ar x ./*.deb
tar -xf ./*tar.xz

In any case, the next step is to move all the main files to /opt/$APP. From an AppDir (if you want not to convert it to an AppImage, here "Brave Browser"):

cd ..
mv ./tmp/brave/brave.AppDir/opt/brave.com/brave/* ./

From an extracted .deb package (here OcenAudio):

mv ./tmp/opt/ocenaudio/* ./
cp ./tmp/usr/share/icons/hicolor/128x128/apps/ocenaudio.png ./

The line two can also take the icon from the extrated package.

Example3: download and uncompress a .tar archive

This step is easier:

tar xf ./*.tar.zst;
rm ./*.tar.zst;
cd ..
mv ./tmp/opt/$APP/* ./

The line 2 will remove the archive, because when we go back from /opt/$APP/tmp to /opt/$APP (line 3) we can move all the content from the exact path to /opt/$APP (line 4).

Example4: compile a program from scratch

Compiling is not so easy because more often you need several programs installed on your system before proceeding, here is the example on how I wrote the (experimental) script for GLIBC (any version available on this repository):

wget http://ftp.gnu.org/gnu/glibc/$APP.tar.gz
tar zxvf $APP.tar.gz
cd $APP
mkdir build
cd build
../configure --prefix=/opt/$APP
make -j4
sudo make install

Download (line 1) and uncompress (line 2) the archive and enter the extracted folder (line 3), following the inbuilt instructions, I have to create and enter a "build" directory (lines 4 and 5) and execute the configure script with an option (in this case to set a prefix, line 6), I had make (line 7) on my host, but during my tests I had to install other compilers and dependences like bison, so read the instructions while you tri to compile a software, you can get errors. Root privileges are required too in this case (line 7).

End of the examples, and now?

Obviousily there are several other examples I can do and you can do too, all depend on your knowledges.

Now all you need to do is to remove the temporary folder:

rm -R -f ./tmp

SPOILER ALERT: this is the end of the more complicated part of this script. From now all is easier.