This is a part two (link to part one) for my home assignment for Tero Karvinen’s course on linux servers. On this part I will build and install a package that will add an executable shell script and an alias for it for all users.
Now to create a new package with a shell script file.
mkdir mmm-command cd mmm-command equivs-control mmm-command
The ‘equivs-control’ command creates a file called ‘mmm-command’, which contains the basic structure for a ‘.deb’ package.
The content I replaced in ‘mmm-command’ (I removed the other ones, which are not so relevant):
Section: misc Priority: optional Homepage: https://miro.metsanheimo.fi Standards-Version: 3.9.2 Package: mmm-command Version: 0.0.1 Maintainer: Miro Metsänheimo <email@example.com> Files: mmm-command.sh /bin # Copy the command file to the bin folder for use of all users Postinst: mmm-command-install.sh # Run the install script to make the alias after installation Architecture: all Description: My new command My new command
Here we have two lines that do something crucial:
- Files: list of files to be installed and compiled in to the ‘.deb’ package.
- Postinst: a script to run after the installation
Then we create the ‘mmm-command.sh’ file mentioned above with the content:
#!/bin/bash echo "An example scipt that installs with my .deb package to all users."
This file is just a simple echo line just to make sure the script works.
And then the ‘mmm-command-install.sh’ file with the content:
#!/bin/bash # If the file doesn't exist, create it if [ ! -f /etc/profile.d/00-aliases.sh ] then touch /etc/profile.d/00-aliases.sh fi # Append the alias to the created file echo "alias mmm-command='/bin/mmm-command.sh'" >> /etc/profile.d/00-aliases.sh source /etc/profile # Reload the commands
Here we create a new file in the ‘profile.d’, because this will last longer and works after updates. The ’00-‘ is to make sure the script is ran first.
And then we build the package creating a file called ‘mmm-command_0.0.1_all.deb’ and install the package with ‘gdebi’:
equivs-build mmm-command sudo gdebi mmm-command_0.0.1_all.deb
And then a tryout:
xubuntu@xubuntu:/$ mmm-command An example scipt that installs with my .deb package to all users.
Class by Tero Karvinen
SH command in a package
Alias for all users