Jump to content

techc0de

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by techc0de

  1. I tried the curl module, but it downloaded 0 bytes file. Why is it so difficult to download a file with PHP module ? It's much easier to download with wget module. #!/usr/bin/php <?php $url = "https://download.nextcloud.com/server/releases/nextcloud-22.0.0.zip"; $path = '/tmp/nextcloud.zip'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); file_put_contents($path, $data);
  2. That's odd, I just tried once, and I got that message.
  3. switch ($verify_version) { case "y": case "Y": if(!@copy("https://download.nextcloud.com/server/releases/nextcloud-{$version}.zip", "nextcloud.zip")) { $errors= error_get_last(); echo "Can't download Nextcloud zip folder: ".$errors['type']; echo "<br />\n".$errors['message']; } else { echo "Nextcloud zipped file downloaded!"; } break; case "n": case "N": exit; } I tried this method, but received error: Can't download Nextcloud zip folder: 2<br /> copy(https://download.nextcloud.com/server/releases/nextcloud-22.0.0.zip): failed to open stream: HTTP request failed! HTTP/1.1 429 Too Many Requests
  4. I agree with you that PHP is not the best tool for this task, so far this is the first script that I converted to PHP from Bash. When you said using arguments, did you mean using functions or a class ? regarding download file, I tried curl but it didn't work. If you can show some examples, that would be helpful.
  5. Hello, I have a bash script for the task, but if I continue to use it, then I'm not going to learn anything new. People have the tendency to stick within their comfort zone.
  6. Hi all, I'm been writing Bash script for a while now, and I use it for most of the Linux servers. My current workplace is currently using PHP to maintain web servers. So I'm try to learn PHP by write PHP scripts for my servers. I wrote this script for my Nextcloud server, and I would like to know if there is room for improvement. I tried to use curl to check for header but it didn't work. Therefore, I'm using wget module instead. Thanks #!/usr/bin/php <?php # prerequisites packages: apt-get install php7.4-cli php-zip wget $today = date('m-d-Y'); $WWWpath = "/config/www"; $NCpath = "/config/www/nextcloud"; $user = 'xfs'; shell_exec("cd $NCpath"); echo "Current working directory: " . getcwd(); echo "\n"; function ask_for_backup() { $prompt = readline('Would you like to make a back up of the current Nextcloud ? [y|n] ' ); echo "You selected '$prompt' . \n"; switch ($prompt) { case "y": case "Y": $backup_version = readline('Please enter a version of Nextcloud you want to backup: '); echo "\n"; $verify = readline("Is this the correct version ? [y|n]: '{$backup_version}' "); echo "$verify\n"; if($verify == "y" || $verify == "Y"){ echo "Backing up current Nextcloud directory... \n"; shell_exec("cp -r $NCpath nextcloud-old_${backup_version}"); break; } case "n": case "N": break; } } // execute function ask_for_backup(); echo "turn on Nextcloud maintenance mode." . "\n"; shell_exec("occ maintenance:mode --on"); shell_exec("cd $WWWpath"); $version = readline('Please enter the Nextcloud version you want to update: '); echo "\n"; $verify_version = readline("Is this the correct version ? [y|n]: '{$version}' "); switch ($verify_version) { case "y": case "Y": $url = "https://download.nextcloud.com/server/releases/nextcloud-{$version}.zip"; shell_exec("wget $url -O nextcloud.zip"); break; case "n": case "N": exit; } // extract Nextcloud zipped file shell_exec("unzip nextcloud.zip"); shell_exec("cd $NCpath"); // copy Nextcloud old 'config.php' to new installation folder shell_exec("cp $WWWpath/nextcloud-old_${backup_version}/config/config.php $NCpath/config/config.php"); echo "change user/group permission to xfs.\n"; shell_exec("chown -R $user:$user $NCpath"); echo "performing upgrade ..."; $cmd = "occ upgrade; echo $?"; $status = shell_exec("$cmd"); $status = rtrim($status); echo "turn off Nextcloud maintenance mode"; echo "\n"; shell_exec('occ maintenance:mode --off'); if ( (int) $status == "0") { echo "Awesome, Nextcloud upgrade is done."; } else { exit("Nextcloud Upgrade Failed !"); } // delete downloaded zip file echo "\n"; shell_exec("cd $WWWpath"); $file = "nextcloud.zip"; // Use unlink() function to delete a file if (!unlink($file)) { echo ("$file cannot be deleted due to an error."); } else { echo ("$file has been deleted."); }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.