User Tools

Site Tools


de:start:howto:package_installation_script

Wenn Du ein eigenes Softwarepaket erstellen möchtest, benötigst Du dieses Script als Vorlage. Mit diesem Script bist Du in der Lage alle Perlfunktionen von i-MSCP zu nutzen (imscp_common_methods.pl)…

default_install

#!/usr/bin/perl
# i-MSCP a internet Multi Server Control Panel
#
# Copyright (C) 2010 by internet Multi Server Control Panel - http://i-mscp.net
#
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is "i-MSCP a internet Multi Server Control Panel".
#
# The Initial Developer of the Original Code is ispCP Team.
# Portions created by Initial Developer are Copyright (C) 2010 by
# i-MSCP a internet Multi Server Control Panel. All Rights Reserved.
#
# The i-MSCP Home Page is:
#
#    http://i-mscp.net
#

use Digest::MD5 qw(md5_hex);

use strict;
use warnings;

################################################################################
#
# Load configuration from i-MSCP configuration file
#
# @return int 0 on success, negative int otherwise
#
sub getConf {
	my $file;
	if(-e '/usr/local/etc/imscp/imscp.conf'){
		$file = '/usr/local/etc/imscp/imscp.conf';
	} elsif(-e '/etc/imscp/imscp.conf') {
		$file = '/etc/imscp/imscp.conf';
	} else {
		return -1;
	}
	return -1 if ! open F, '<', $file;
	%main::cfg = join('', <F>) =~ /^\s*(\w+)\s*=\s*(.*)$/gm;
	close F;
	%main::cfg ? 0 : 1;
}

my ($sw_database_pass_clear, $sw_database_pass_md5, $sw_install_pass_clear, $sw_install_pass_md5, $sql, $url_path, $DBname, $hostname, $dbUser, $dbPassword);
my ($processing_type,$sw_software_db,$sw_software_prefix,$sw_database,$sw_database_user,$sw_database_tmp_pwd,$sw_install_username,$sw_install_password,$sw_install_email,$domain_name,$sw_dest_path,$sw_path);

sub extract_variables {
	my $crypted_array = shift;
	my $uncrypted_array = decode_base64($crypted_array);
	($processing_type,$sw_software_db,$sw_software_prefix,$sw_database,$sw_database_user,$sw_database_tmp_pwd,$sw_install_username,$sw_install_password,$sw_install_email,$domain_name,$sw_dest_path,$sw_path)=split(/,/, $uncrypted_array);
	if($processing_type && $sw_software_prefix && $sw_database && $sw_database_user && $sw_database_tmp_pwd && $sw_install_username && $sw_install_password && $sw_install_email && $domain_name && $sw_dest_path && $sw_path) {
		if ($sw_database ne "not_required") {
			$sw_database_pass_clear = $sw_database_tmp_pwd;
			$sw_database_pass_md5 = md5_hex($sw_database_pass_clear);
			#New database connection to the user database
			imscp_installer_set_new_db_connection($sw_database,$sw_database_user,$sw_database_pass_clear);
		} else {
			$sw_database_pass_clear = $sw_database_tmp_pwd;
			$sw_database_pass_md5 = $sw_database_tmp_pwd;
		}
		$sw_install_pass_clear = $sw_install_password;
		$sw_install_pass_md5 = md5_hex($sw_install_pass_clear);
	} else {
		print "[DEGUB] i-MSCP installer file - Some variables not defined in the uncrytped string\n";
		exit();
	}
}

sub imscp_installer_set_new_db_connection {
	@main::db_connect = undef;
	$DBname = shift;
	$dbUser = shift;
	$dbPassword = shift;
	$hostname = 'localhost';
	@main::db_connect = ("DBI:mysql:$DBname:$hostname", $dbUser, $dbPassword);
}

sub imscp_installer_package_start {
	if($processing_type eq "install") {
		print "[DEGUB] i-MSCP installer file - installation process start\n";
	} elsif ($processing_type eq "uninstall") {
		print "[DEGUB] i-MSCP installer file - uninstallation process start\n";
	}
}

sub imscp_installer_package_end {
	if($processing_type eq "install") {
		print "[DEGUB] i-MSCP installer file - installation process end\n";
	} elsif ($processing_type eq "uninstall") {
		print "[DEGUB] i-MSCP installer file - uninstallation process end\n";
	}
	setup_main_vars();
}

if(getConf() != 0) {
	print "[DEGUB] i-MSCP installer file - Can't load imscp.conf\n";
} else {
	#
	# Do not make changes to this static vars
	#
	
	sub get_inc_path {
		if(getConf() != 0) {
			print "[DEGUB] i-MSCP installer file - Can't load imscp.conf\n";
		} else {
			my $imscp_path = $main::cfg{'ROOT_DIR'}.'/engine';
		}
	}
	use lib get_inc_path();
	require 'imscp_common_code.pl';
	
	my $crypted_array = $ARGV[0];
	if ($crypted_array) {
		extract_variables("$crypted_array");
		my $db_tables = "sql_tables";
		$url_path = $sw_path;
		$url_path =~ s/^\/.*htdocs//g;

		#
		# This is the place for dynamic vars
		#
		
		
		if($processing_type eq "install") {
			## Don't remove this line below ##
			imscp_installer_package_start(); 
			##################################
			
			## Don't remove this line below ##
			imscp_installer_package_end();
			##################################
		} elsif ($processing_type eq "uninstall") {
			## Don't remove this line below ##
			imscp_installer_package_start(); 
			##################################
			
			## Don't remove this line below ##
			imscp_installer_package_end();
			##################################
		}
	} else {
		print "[DEGUB] i-MSCP installer file - No Input Data available\n";
	}	
}
/var/www/virtual/i-mscp.net/wiki/htdocs/data/pages/de/start/howto/package_installation_script.txt · Last modified: 2012/02/26 11:18 by TheCry