App-WordPressTools
view release on metacpan or search on metacpan
to install the wp-tools executable to a system directory, like
/usr/local/bin/wp-tools (depending on your perl).
Downloading just the executable
You may also choose to download wp-tools as a single executable, like
this:
curl -OL https://raw.githubusercontent.com/bluehost/wp-tools/solo/wp-tools
chmod +x wp-tools
This executable includes all the non-core Perl module dependencies
built-in.
For developers
If you're a developer and want to hack on the source, clone the
repository and pull the dependencies:
git clone https://github.com/bluehost/wp-tools.git
script/wp-tools view on Meta::CPAN
cpanm --sudo App::WordPressTools
to install the F<wp-tools> executable to a system directory, like F</usr/local/bin/wp-tools> (depending on your perl).
=head2 Downloading just the executable
You may also choose to download F<wp-tools> as a single executable, like this:
curl -OL https://raw.githubusercontent.com/bluehost/wp-tools/solo/wp-tools
chmod +x wp-tools
This executable includes all the non-core Perl module dependencies built-in.
=head2 For developers
If you're a developer and want to hack on the source, clone the repository and pull the dependencies:
git clone https://github.com/bluehost/wp-tools.git
cd wp-tools
cpanm -n Dist::Zilla
script/wp-tools view on Meta::CPAN
}
chdir($home_dir);
### prevent too many concurrent executions
our %pid_files;
sub create_pid_file {
my $file = shift;
return $pid_files{$file} if $pid_files{$file};
sysopen(my $fh, $file, O_RDWR|O_CREAT) or die "Open pid file failed: $!";
flock($fh, LOCK_EX|LOCK_NB) or die "Locking pid file ($file) failed: $!";
chmod(0666, $file); # explicitly ignore chmod errors since we may not be the owner
print $fh "$$\n";
return $pid_files{$file} = $fh;
}
sub unlink_pid_file {
my $file = shift;
my $fh = $pid_files{$file} or return;
close($fh);
unlink($file); # explicitly ignore unlink errors since we may not be the owner
}
for my $i (1..$args->{max_run}) {
script/wp-tools view on Meta::CPAN
$password =~ s/^[\r\n]+//;
$database =~ s/^[\r\n]+//;
chomp $username;
chomp $password;
chomp $database;
if ($username =~ /[\r\n]/ || $password =~ /[\r\n]/ || $database =~ /[\r\n]/) {
die "Multiple credentials found in $args->{'path'}/wp-config.php. Cannot determine which to use. Backup operation halted.";
}
open (my $fh, '>', $defaults_file) or die "Cannot write to $defaults_file: $!";
close $fh;
chmod(0600, $defaults_file) or die "Cannot chmod $defaults_file: $!";
write_text($defaults_file,"[client]\nuser=$username\npassword=$password");
my $databaseq = shell_quote($database);
$dump_command = "mysqldump --defaults-file=$defaults_file $databaseq 2>&1 >$db_file";
my $result = `$dump_command`;
#acceptable failure states for databaseless accounts
if ($result =~ $no_db_regex) {
$args->{'__skip_database'} = 1;
$db_file = '';
}
elsif ($?) {
script/wp-tools view on Meta::CPAN
$password =~ s/^[\r\n]+//;
$database =~ s/^[\r\n]+//;
chomp $username;
chomp $password;
chomp $database;
if ($username =~ /[\r\n]/ || $password =~ /[\r\n]/ || $database =~ /[\r\n]/) {
die "Multiple credentials found in $args->{'path'}/wp-config.php. Cannot determine which to use. Restoration operation halted.";
}
open (my $fh, '>', $defaults_file) or die "Cannot write to $defaults_file: $!";
close $fh;
chmod(0600, $defaults_file) or die "Cannot chmod $defaults_file: $!";
write_text($defaults_file,"[client]\nuser=$username\npassword=$password");
my $databaseq = shell_quote($database);
`mysql --defaults-file=$defaults_file $databaseq <$db_file`;
if ($?) {
die "Failed to restore database";
}
}
}
# if we skipped large directories in the backup procedure
script/wp-tools view on Meta::CPAN
my $backup = !$args->{'skip_backup'} ? backup() : undef;
die "Unable to make backup." if !$args->{'skip_backup'} && (!$backup || !ref $backup || !$backup->{'success'});
if ($backup && ref $backup && $backup->{'success'}) {
$args->{'backup_file'} = $backup->{'backup_file'};
}
if (!$args->{'skip_backup'} && (length($args->{'backup_file'}) == 0 || !-e $args->{'backup_file'} || !-s $args->{'backup_file'})) {
die "Unable to read backup file - upgrade stopped.";
}
#find all non-executable directories and make the executable (for listing)
my $fix_directories = `find $pathq -type d ! -perm /u+x -exec chmod u+x {} \\; ;`;
#find all non-writable files and make them user writable
my $set_permissions = `find $pathq ! -perm /u+w -exec chmod u+w {} \\; ;`;
#if a backup is made, disable maintenance mode temporarily
if (-e '.maintenance') {
$maintenance = '.not.maintenance';
rename('.maintenance',$maintenance);
}
my $current_status;
my $http = HTTP::Tiny->new(timeout => 30);
if ($plus3713) {
script/wp-tools view on Meta::CPAN
chomp $password;
chomp $database;
if ($username =~ /[\r\n]/ || $password =~ /[\r\n]/ || $database =~ /[\r\n]/) {
die "Multiple credentials found in $args->{'path'}/wp-config.php. Cannot determine which to use. Upgrade operation halted.";
}
if ($prefix =~ /[\r\n]/) {
die "Multiple database prefixes found in $args->{'path'}/wp-config.php. Cannot determine which to use. Upgrade operation halted.";
}
open (my $fh, '>', $defaults_file) or die "Cannot write to $defaults_file: $!";
close $fh;
chmod(0600, $defaults_file) or die "Cannot chmod $defaults_file: $!";
write_text($defaults_file,"[client]\nuser=$username\npassword=$password");
my $table = "${prefix}options";
my $databaseq = shell_quote($database);
my $siteurl_sql = qq{mysql -N -B -e --defaults-file=$defaults_file $databaseq "SELECT option_value FROM $table WHERE option_name = 'siteurl'"};
$current_status->{'siteurl'} = `$siteurl_sql`;
$current_status->{'adminurl'} = "$current_status->{'siteurl'}/wp-admin";
my $resp = $http->head($current_status->{'siteurl'});
$current_status->{'code'} = $resp->{'status'};
$current_status->{'size'} = $resp->{'headers'}{'content-length'} || 1;
my $aresp = $http->head($current_status->{'adminurl'});
script/wp-tools view on Meta::CPAN
if ($?) {
die "Could not copy $config_file to $config_backup: $err_out";
}
# generate the new config
open(my $in, '<', $config_backup) or die "Failed to open (cbf) $config_backup: $!";
#temporarily set permissions to rw?
$mode = (stat($config_file))[2] & 0777;
my $modestr = sprintf qq{%04o}, $mode;
if ($modestr !~ /^.[67]/) {
chmod($mode | 0600, $config_file);
}
else {
undef $mode;
}
open(my $out, '>', $config_file) or die "Failed to open (cfw) $config_file $!";
print $out "<?php\n";
print $out "/* WARNING: This config is auto-generated from $config_backup for wpcli compatibility! */\n";
while (my $line = <$in>) {
if ($line =~ /(?:define\((.+?),.+\)\s*;|\$\w+\s*=\s*['"].*['"]\s*;)/) {
$line = "if (!defined($1)) {$definition_check_string\n$line\n}$definition_check_string\n" if $1;
script/wp-tools view on Meta::CPAN
sub _restore_wp_config {
our $config_file;
our $config_backup;
# restore original wp-config.php
if ($config_backup && -e $config_backup) {
unlink($config_file);
rename($config_backup, $config_file);
}
chmod($mode, $config_file) if $mode;
}
( run in 0.362 second using v1.01-cache-2.11-cpan-496ff517765 )