Showing posts with label packages. Show all posts
Showing posts with label packages. Show all posts

Automating Installation of Debian Packages

When installing packages, you may notice that you often get prompts similar to the one shown below:

These are useful for grabbing details from the user where necessary, but are annoying when trying to automate the installation of many packages, or when one needs to ensure the same details are used across multiple systems and the user does not make a mistake.

Luckily, one can preconfigure the answers to the prompts through the use of debconf. For example, if one wants to automatically install mysql server on debian without seeing any pompts, you simply run the following commands before running

sudo apt-get install mysql-server

sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $DATABASE_PASS"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DATABASE_PASS"

However, how does one know what to pass to debconf-set-selections? Here is the script that I use. Make sure to update the PACKAGE_NAME variable

PACKAGE_NAME=""

cd /tmp
aptitude download $PACKAGE_NAME
mv $PACKAGE_NAME* $PACKAGE_NAME.deb

mkdir control_files
dpkg-deb -e $PACKAGE_NAME.deb control_files/

grep -e '^Template:' -e '^Type:' -e '^Default:' \
 control_files/templates | xargs | sed \
 -e 's/\s*Template: /\npackagename\t/g' \
 -e 's/\s*Type: */\t/g' \
 -e 's/\s*Default: */\t/g'

# cleanup
rm -rf control_files
rm $PACKAGE_NAME.deb
Example output:
packagename     glance/register-endpoint        boolean false
packagename     glance/keystone-ip      string
packagename     glance/keystone-auth-token      password
packagename     glance/endpoint-ip      string
packagename     glance/region-name      string  regionOne

Clearing Settings

If you ever remove a package, the debconf settings will still be there. This means that if you were to reinstall something like MySQL, it would re-use the original password settings rather than ask you for new ones!


To clear the debconf settings for a package, run the following command.

echo PURGE | sudo debconf-communicate $PACKAGE_NAME
To show any debconf settings for a package, use:
sudo debconf-show $PACKAGE_NAME

References

Java Include Packages in Netbeans

Once you have built your own packages, or if you want to use somebody elses, you will need to include them in other projects. Here is how one does that inside the Netbeans IDE.

Right-click on the libraries folder in the projects pane, and select add JAR/Folder.

Navigate to the jar you want to add to your project and click ok.

Add an import statement for the package you just included so that you can now use its classes. For example, my package "programster.core" had the Core class which I use as shown below:

Java - Create Packages

Creating packages is a great way to share and reuse code. Once you have developed/found lots of packages, you will find that you will be able to build complex applications rapidly by just glueing them together. You will need to write less code, thus have less code to maintain and debug.

    Create a set of useful classes that you want to turn into a package. I can't really help you with this one, but for this example, I am going to use the files shown below:
    Compile the source files using javac into class files.
    javac /path/to/source/*
    We need to know your "vendor" name. If you have a personal website, this would be your website's address in reverse, such as com.blogspot.programster, however, since I am not sharing this publicly, I am going to just use "programster".
    Think of a name for your package. E.g. for my first package, I am going to call it "core" because it forms my "core" libraries that I use in all projects.
    The vendor name and package name need to be all lowercase, not have any hyphens, but can have underscores.
    Place your
    *.class
    files, inside a folder that is named after the package, and place that folder within a folder named after the vendor. If your vendor name has
    .
    characters, such as for the reversed domain, create folders for each part of the name, not including the
    .
    . For example, my folder path (if I was using this domain for my vendor name) would be:
    com/blogspot/programster/core/[java source files here]
    Navigate to the folder that contains the top folder of the path you just created. and run the following command:
    jar -cf [package-name].jar [top folder name]
    For example:
    java -cf core.jar com
    Now you should have a file called [package name].jar in the folder that you just ran the command. This is your finished package that you can share with others and include in projects.

PHP - Including External Packages

To build complex applications in PHP, it is much quicker and simpler to just "glue together" relevant packages and configure them.

Related Posts

Steps

    Navigate to the root of your project's directory, or just create a new directory if you are starting from scratch.
    mkdir -p /path/to/project/directory
    cd /path/to/project/directory
    
    Create a composer.json file, listing all the packages that you require. If you are hosting your own private repository using Satis, you will need to list this as well using the
    repositories
    section as I have done below.
    {
        "repositories": [ { "type": "composer", "url": "http://satis.technostu.com/" } ],
        "require": {
            "Programster/CoreLibs": "dev-trunk",
            "Programster/CliMenu": "1.0.0",
            "Programster/DigitalOceanSdk": "2.*"
        }
    }
    
    Download all the packages using composer.
    composer update
    Running composer update again later may result in packages updating, especially if you use versions like
    dev-trunk
    or
    2.*
    , so using specific versions like
    1.0.0
    is somewhat safer!

Private PHP Packages - Setup Your Own Satis Server

Previously, we created a PHP "package", but this is useless unless we host it on Packagist, or set up our own private server for referencing them, which is what I will now show you how to do, using Satis.

Related Posts

Steps

    Install all the necessary packages.
    sudo apt-get install apache2 libapache2-mod-php5 php5 php5-cli subversion -y
    Navigate to your web folder and give yourself permission to write there.
    sudo chown $USER:www-data /var/www
    cd /var/www
    Install composer
    curl -sS https://getcomposer.org/installer | php
    Now you will see a directory called satis in /var/www
    Now install satis using composer.
    php composer.phar create-project composer/satis --stability=dev --keep-vcs
    create a file called satis.json containing all the configuration details for the packages you desire
    {
        "name": "MyDomain Packages",
        "homepage": "http://www.mydomain.com",
        "repositories": [
            {
                "type": "svn",
                "url": "svn://svn.mydomain.com/packages/CoreLibs"
            },
            {
                "type": "svn",
                "url": "svn://svn.mydomain.com/packages/Package2"
            },
            {
                "type": "svn",
                "url": "svn://svn.mydomain.com/packages/Package3"
            }
        ],
        "require-all": true
    }
    
    Now build the package list. You will need to enter your SVN username/password.
    php satis/bin/satis build satis.json .

    Configure Apache

    We need to update Apache to point to the correct directory, which is now /var/www instead of the default /var/www/html (in Ubuntu 14.04).
    sudo editor /etc/apache2/sites-enabled/000-default.conf

    [ Change DocumentRoot to /var/www ]
    Restart Apache for the changes to take effect.
    sudo service apache2 restart
    That's it! Your Satis server is now at this server's IP/domain. Now you just need to configure your firewall rules with UFW or IPtables, or even configure an Nginx reverse proxy to only allow/forward the IPs that you specify, so that only you can access the Satis server, unless you want to keep your packages open to the public.

References

Creating A PHP Package

You may or may not already be using Packagist in order to create PHP packages. By converting your code into packages, it becomes faster and simpler to develop more complex applications. Since these packages will be re-used, less time will be spent writing and debugging "new" code. One of the best aspects of packages is that they can automatically updated through Composer with a call to

composer update
. This tutorial is going to cover the creation of a "package" repository in SVN that we will reference with a private Satis server, rather than using Packagist ion order to keep our packages private.

Related Posts

Steps

    Create a new repository on your SVN server
    svnadmin create my-repo
    Check the new repository out
    svn checkout svn://my.domain.com/my-repo
    Navigate to within the directory that was just checked out and create the default folders that are expected by the package program trunk,branches, and tags
    cd my-repo
    mkdir trunk
    mkdir branches
    mkdir tags
    Create the src directory this will be referenced later.
    mkdir trunk/src
    Create the composer.json file which provides all the relevant packaging details This must go in the top level of the codebase (e.g. top of trunk or any branch)
    editor trunk/composer.json

    Template

    {
        "name": "[vendor name]/[package name]",
        "type": "library",
        "description": "[description]",
        "keywords": ["log","logging"],
        "homepage": "[project homepage]",
        "license": "none",
        "authors": [
            {
                "name": "[author name]",
                "email": "[author email]",
                "homepage": "[authors website]",
                "role": "[authors role]"
            }
        ],
        "require": {
            "php": ">=5.x.x"
        },
        "autoload": {
            "psr-4": {
                "[vendor name]\\[package name]\\": ""
                "[vendor name]\\[package name]\\": "subfolder1",
                "[vendor name]\\[package name]\\": "subfolder2"
            }
        }
    }
    

    Example

    {
        "name": "Programster/CoreLibs",
        "type": "library",
        "description": "Core libraries for PHP 5.3+",
        "keywords": ["core","library"],
        "homepage": "http://www.programster.blogspot.co.uk",
        "license": "none",
        "authors": [
            {
                "name": "Programster",
                "email": "my.email@gmail.com",
                "homepage": "http://programster.blogspot.co.uk/",
                "role": "Developer"
            }
        ],
        "require": {
            "php": ">=5.3.0"
        },
        "autoload": {
            "psr-4": {
                "Programster\\CoreLibs\\": ""
            }
        }
    }
    
    Add everything to SVN and commit it
    svn add *
    svn commit .
    
    Now all you have to do is add all the actual source code to the trunk directory and commit to SVN!

References