Willkommen bei WordPress. Dies ist dein erster Beitrag. Bearbeite oder lösche ihn und beginne mit dem Schreiben!
Hallo Welt!
von raredesign | Dez 3, 2019 | Allgemein | 0 Kommentare
Cokiee Shell
Current Path : /usr/local/siteapps/xoops-2.3.0-3/scripts/ |
Current File : //usr/local/siteapps/xoops-2.3.0-3/scripts/postinstall |
#!/usr/bin/perl -w use strict; use File::Copy; use File::Find; use XML::XPath; use XML::XPath::XMLParser; use File::Basename; ## edited and simplified by michaw ## you dont have to change anything here. ## just edit the info.xml file in info/ directory ## create this file to let the script CHMOD the files in info.xml ## entries looks like: <FILE name="filename" value="777" /> my $check_for_mod_php = "/usr/local/siteapps/.use_mod_php"; ######################### # Quote Section # ######################### sub quote { my ($qstr) = @_; $qstr =~ s/\\/\\\\/g; $qstr =~ s/'/\\'/g; return $qstr; } sub shell_quote { my ($qstr) = @_; # replace ' for \' # replace \ for \\ $qstr =~ s/\\/\\\\/g; $qstr =~ s/"/\\\"/g; $qstr =~ s/\$/\\\$/g; return $qstr; } sub parse_input_to_hash { my %params = (); while (<STDIN>) { my ($k,$v); if (/^([^=]+)=(.+)$/){ $v = $2; chomp $v; $k = $1; $params{"$k"} = $v; } } return %params; } sub parse_plesk_config_file { my %psa_params = (); open PSACONF, '/etc/psa/psa.conf'; print "opening psa config\n"; while (<PSACONF>){ chomp; unless (/^#/){ if (/^(\s*[_a-zA-Z]+)\s+(.+?)\s*$/){ # print "$1 : $2\n"; $psa_params{$1} = $2; } } } close PSACONF; return %psa_params; } ################################# # Remote Databese Section # ################################# sub get_dbhost { my ($p_dbhost) = @_; my $dbhost; if (defined $p_dbhost && $p_dbhost ne '') { $dbhost = $p_dbhost; } else { $dbhost = 'localhost'; } return $dbhost; } sub get_dbport { my ($p_dbport) = @_; my $dbport; if (defined $p_dbport && $p_dbport ne '') { $dbport = $p_dbport; } else { $dbport = '3306'; } return $dbport; } sub get_dbremote_params { my ($p_dbhost, $p_dbport) = @_; my $dbremote_params = ''; my ($m_dbhost, $m_dbport); if (defined $p_dbhost && $p_dbhost ne '') { $m_dbhost = shell_quote($p_dbhost); $dbremote_params .= " --host=\"${m_dbhost}\" "; } else { $m_dbhost = shell_quote('localhost'); $dbremote_params .= " --host=\"${m_dbhost}\" "; } if (defined $p_dbport && $p_dbport ne '') { $m_dbport = shell_quote($p_dbport); $dbremote_params .= " --port=\"${m_dbport}\" "; } return $dbremote_params; } sub get_dbstring { my ($p_dbhost, $p_dbport) = @_; my $dbstring = ''; my $dbhost = ''; my $dbport = ''; if (defined $p_dbhost && $p_dbhost ne '') { $dbhost = $p_dbhost; } else { $dbhost = 'localhost'; } $dbstring .= $dbhost; if (defined $p_dbport && $p_dbport ne '') { $dbport = $p_dbport; $dbstring .= ":$dbport"; } return $dbstring; } ################################################# # Modification of configuration files # ################################################# sub modify_file { my ($fname, $fparams) = @_; unless (open F, $fname){ print STDERR "postinstall: can't open file `$fname` for reading\n"; return 0; } my $file_content; while (<F>){ $file_content .= $_; } close F; my ($k,$v); while (($k,$v)=each(%$fparams)){ $file_content =~ s/\@\@${k}\@\@/$v/g; } unless (open F, ">$fname"){ print STDERR "postinstall: can't open file `$fname` for writing\n"; return 0; } print F $file_content; close F; return 1; } sub config_file_modification { my ($root_dir, $config_files, %config_params) = @_; foreach my $config_file (@$config_files) { my $config_file_full = $config_file; unless (modify_file($config_file_full, \%config_params)) { print STDERR "couldn't change file ${config_file_full}\n"; exit 1; } } } sub schema_file_modification { my ($p_mysql_bin, $p_dbname, $p_dbuser, $p_dbpasswd, $dbremote_params, $root_dir, $schema_files, %sql_params) = @_; my $mysql_bin = $p_mysql_bin.'/mysql'; my $m_dbname = shell_quote($p_dbname); my $m_dbuser = shell_quote($p_dbuser); my $m_dbpass = shell_quote($p_dbpasswd); foreach my $sql_file (@$schema_files) { unless (modify_file($sql_file, \%sql_params)){ print STDERR "couldn't change file ${sql_file}\n"; exit 1; } if ($m_dbpass ne '' && $m_dbuser ne '') { my $mysql_cmd = "${mysql_bin} ${dbremote_params} -u\"${m_dbuser}\" -p\"${m_dbpass}\" \"${m_dbname}\" <${sql_file}"; my $str_res = `$mysql_cmd`; if ($?){ # error occured during mysql print STDERR "unable to import sql data:\n${str_res}\n"; print STDERR "$mysql_cmd\n"; exit 1; } } } } ################################################# # set permissions for dirs and files # ################################################# sub set_permissions { my %perm_elems = @_; foreach my $pe (keys %perm_elems) { unless( chmod (oct($perm_elems{$pe}),"$pe") ) { print STDERR "... couldnt chmod $pe"; } } } ##################################################################################### ##################################################################################### ######################### # Quote Section # ######################### my %params = parse_input_to_hash(); my %psa_params = parse_plesk_config_file(); ################################# # Path to root directory # ################################# my $proto = 'http://'; my $root_dir = $params{'vhost_path'}.'/html/'.$params{'install_prefix'}; my $root_url = $proto.$params{'domain_name'}.'/'.$params{'install_prefix'}; my $root_dir_cgi = $params{'vhost_path'}.'/html/cgi-bin/'.$params{'install_prefix'}; my $root_url_cgi = $proto.$params{'domain_name'}.'/cgi-bin/'.$params{'install_prefix'}; ################################# # GET FILES OUT OFF info.xml # ################################# my @config_files = (); my @schema_files = (); my %perm_elems = (); my ($nodes, $xp); $xp = XML::XPath->new(filename => dirname(dirname($0)).'/info/info.xml'); $nodes = $xp->findnodes('/WEBAPP/FILES/CONFIG/FILE'); while (my $node = $nodes->pop) { push(@config_files, $root_dir.'/'.$node->getAttribute('name')); } $nodes = $xp->findnodes('/WEBAPP/FILES/SCHEMA/FILE'); while (my $node = $nodes->pop) { push(@schema_files, $root_dir.'/'.$node->getAttribute('name')); } $nodes = $xp->findnodes('/WEBAPP/FILES/PERMISSIONS/FILE'); while (my $node = $nodes->pop) { $perm_elems{$root_dir.'/'.$node->getAttribute("name")} = $node->getAttribute("value"); } ################################# # Remote Databese Section # ################################# my $dbhost = get_dbhost($params{'dbhost'}); my $dbport = get_dbport($params{'port'}); my $dbremote_params = get_dbremote_params($params{'dbhost'}, $params{'port'}); my $dbstring = get_dbstring($params{'dbhost'}, $params{'dbport'}); ################################################# # Modification of configuration files # ################################################# my %config_params = ( "PROTO" => quote($proto), "ROOT_DIR" => quote($root_dir), "ROOT_DIR_CGI" => quote($root_dir_cgi), "ROOT_URL" => quote($root_url), "ROOT_URL_CGI" => quote($root_url_cgi), "DBHOST" => quote($dbhost), "DBPORT" => quote($dbport), "DBSTRING" => quote($dbstring), ); ## add params to replacements hash foreach (keys %params) { $config_params{ uc $_ } = quote($params{$_}); } print "this are params and replacements:\n"; foreach (sort keys %config_params) { print '> @@'.$_.'@@ => '.$config_params{$_}."\n" } ### call file modifications config_file_modification($root_dir, \@config_files, %config_params); schema_file_modification($psa_params{'MYSQL_BIN_D'}, $params{'dbname'}, $params{'dbuser'}, $params{'dbpasswd'}, $dbremote_params, $root_dir, \@schema_files, %config_params); ## delete old schema.sql file(s) foreach my $sql_file (@schema_files) { unlink($sql_file); } ################################################# # set permissions for dirs and files # ################################################# if (-e $check_for_mod_php) { print "Using mod_php chmodding files...\n"; set_permissions(%perm_elems); } exit 0
Cokiee Shell Web 1.0, Coded By Razor
Neueste Kommentare