making shell zip accessible to php - shell

Hi got a LEMP stack un Ubuntu 18.04 with php 7.2.5
server info says
Shell Exec Is Supported
Shell Exec Zip Not Supported
therefore some of my plugins says
This server is not configured for the Shell Zip engine - please use a different engine mode. To make 'Shell Zip' available, ask your host to:
1. Install the zip executable and make it accessible to PHP.
I have tries this code
PHP - How to know if server allows shell_exec
if(function_exists('shell_exec')) {
echo "exec is enabled";
}
and the function is enabled
however when i test if it is executable with the code below nothing happens.
As DanFromGermany pointed out, you probably check then if it is
executable. Something like this would do it
if(shell_exec('echo foobar') == 'foobar'){
echo 'shell_exec works';
}
or tried this, returns nothing as well just white page
// Exec function exists.
// Exec is not disabled.
// Safe Mode is not on.
$exec_enabled =
function_exists('exec') &&
!in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions')))) &&
strtolower(ini_get('safe_mode')) != 1
;
if($exec_enabled) { exec('blah'); }
I have also checked with the code below from https://wpguru.co.uk/2014/01/how-to-test-if-a-shell-command-will-work-in-php/ and it does work
// helper function
function checkShellCommand($command) {
$returnValue = shell_exec("$command");
if(empty($returnValue)) {
return false;
} else {
return true;
}
}
// test the shell command you'd like to use
if (!checkShellCommand('uname -a')) {
print 'This command cannot be executed.';
} else {
echo shell_exec('uname -a');
}
So, could anyone tell me how can I make it accessible to PHP
Many thanks

this was solved by
apt-get install zip unzip

Related

Laravel Seeder error Cannot write to directory "public/storage/.."

I got this DatabaseSeeder.php in laravel where I create a Directory:
public function run()
{
Storage::deleteDirectory('posts');
Storage::makeDirectory('posts');
// Etcetera ...
}
And then I run
$ php artisan migrate:fresh --seed
This works flawlessly in my development environment (Laravel Homestead).
However, if I run that same command inside a Docker container using Laradock, I get the following error:
Seeding: Database\Seeders\PostsSeeder
InvalidArgumentException
Cannot write to directory "public/storage/posts"
at vendor/fakerphp/faker/src/Faker/Provider/Image.php:90
86▕ ) {
87▕ $dir = is_null($dir) ? sys_get_temp_dir() : $dir; // GNU/Linux / OS X / Windows compatible
88▕ // Validate directory path
89▕ if (!is_dir($dir) || !is_writable($dir)) { ➜ 90▕ throw new \InvalidArgumentException(sprintf('Cannot write to directory
"%s"', $dir));
91▕ }
92▕
93▕ // Generate a random filename. Use the server address so that a file
94▕ // generated at the same time on a different server won't have a collision.
+3 vendor frames
database/factories/ImageFactory.php:25
Faker\Generator::__call()
Why is this happening?
How do I fix it?
Workaround
To easily solve it simply create those directories:
$ ls -lah public/
$ cd public/ && mkdir storage && cd storage && mkdir posts && cd ../..
Try again
$ artisan migrate:refresh --seed
This error is because one of your "Factory" files, in the "faker" method in this case, the "posts" folder does not exist.
Faker does not have the ability to create a new folder and since the folder does not exist, I get that error.
So in this case you have to create the posts folder first. To do this, inside your "DatabaseSeeder.php" file, place the following line of code inside the run () method at the beginning:
use Illuminate\Support\Facades\Storage;
public function run()
{
Storage::deleteDirectory('public/posts');
Storage::makeDirectory('public/posts');
...
}
I had the same problem, I create the folder using the workaround, and it works, but running artisan migrate: refresh --seed doesn't remove the directories but creates more.
public function run()
{
Storage::deleteDirectory('posts');
Storage::makeDirectory('posts');
// Etcetera ...
}

'No such file or directory' error when using buildGoPackage in nix

I'm trying to build the hasura cli: https://github.com/hasura/graphql-engine/tree/master/cli with the following code (deps derived from dep2nix):
{ buildGoPackage, fetchFromGitHub }:
buildGoPackage rec {
version = "1.0.0-beta.2";
name = "hasura-${version}";
goPackagePath = "github.com/hasura/graphql-engine";
subPackages = [ "cli" ];
src = fetchFromGitHub {
owner = "hasura";
repo = "graphql-engine";
rev = "v${version}";
sha256 = "1b40s41idkp1nyb9ygxgsvrwv8rsll6dnwrifpn25bvnfk8idafr";
};
goDeps = ./deps.nix;
}
but I get the following errors after the post-installation fixup step:
find: '/nix/store/gkck68cm2z9k1qxgmh350pq3kwsbyn8q-hasura-cli-1.0.0-beta.2': No such file or directory.
What am I doing wrong here? For reference, I'm on macOS and using home-manager.
For anyone still wondering:
There are a couple of things to consider:
dep has been deprecated in favor of go modules
This is also reflected in Nix, as buildGoPackage is now legacy and moved to buildGoModule
There is already a hasura-cli package in nixpkgs. You can just use it with nix-shell -p hasura-cli

Yocto/Bitbake recipe for adding empty directory to rootfs Embedded Linux

Is there any recipe for adding a new, empty directory to the rootfs? I tried adding this into one of my bbappend file:
do_install() {
install -d ${D}/tmp/myNewDir
}
FILES_${PN} += "/tmp/myNewDir"
but I am getting a non descriptive error, Function failed: do_install
There are several ways. The image command way is already described by StackedUser.
You can also try to extend some of your recipes (as you are doing in your question). I guess that you are seeing the error because you are overwriting the do_install task. You are probably wanting to extend it, so you should add _append to the task name, i.e.:
do_install_append () {
install -d ${D}/tmp/myNewDir
}
BTW, the error "Function failed: do_install" you are hitting usually show an error code or a problematic command. Maybe there is something.
Another way is to create a simple recipe and add it to the image, here is a stub:
SUMMARY = "XXX project directory structure"
# FIXME - add proper license below
LICENSE = "CLOSED"
PV = "1.0"
S = "${WORKDIR}"
inherit allarch
do_install () {
install -d ${D}/foo/bar
}
FILES_${PN} = "/foo/bar"
In our image recipe we have something like this to create a new directory:
create_data_dir() {
mkdir -p ${IMAGE_ROOTFS}/data
}
IMAGE_PREPROCESS_COMMAND += "create_data_dir;"

Why won't gradle Exec task run my command?

I have read around stackoverflow and the gradle forms, but I am still stumped. The ultimate goal here is that after I copy some files, I want to set the writable flag -- because 'copy' doesn't like overwriting read-only files on 'nix (huh...), nor can it be forced to do so (harumph!).
Here is the outline of what I have:
task setPermissions (type : Exec) {
executable = 'chmod -R +w'
}
// ... a little while later ...
task('somethingElse') << {
// ... unrelated stuff ...
def String targetDir = "$aVar/theTarget"
// >> TASK CALL <<
setPermissions {
commandLine = [executable + " $targetDir"]
}
// but that doesn't work... this does...
proc = Runtime.getRuntime().exec("chmod -R +w $deployDir")
proc.waitFor()
}
I have tried variations in "setPermissions".
Trial 1:
commandLine = 'chmod'
args = '-R', '+w'
In which case I appended the target directory to "args" when I called setPermissions.
Trial 2:
commandLine = 'chmod -R +w'
In which case I appended the target directory to "commandLine" when I called setPermissions. I also tried making it the only "args" value.
Trial 3:
commandLine = 'chmod', '-R', '+w'
In which case I appended the target directory to "commandLine" when I called setPermissions. I also tried making it the only "args" value.
So what am I doing wrong here that an Exec task won't run this properly, but the Rt.gR.exec() will?
You can't call a task from another task. You'll have to make one depend on the other, or call the Project.exec method from a task action. The syntax for configuring the exec method is exactly the same as for the Exec task.
PS: Have you tried to use Copy.fileMode instead of chmod?

How to continue a Jenkins build even though a build step failed?

I am using a Phing build script with Jenkins and would like to run it end to end on a job and capture all the reports. The problem is it stop building on a failed build step. Is there a way or a plugin that would continue the job even on failures?
Thanks
I don't know a lot about Phing but, since it's based on Ant, if the build step you are executing has a "failonerror" attribute you should be able to set it to false so that the entire build doesn't fail if the step returns an error.
Yes, use try, catch block in you pipeline scripts
example:
try {
// do some stuff that potentially fails
} catch (error) {
// do stuff if try fails
} finally {
// when you need some clean up to do
}
Or alternatively if you use sh commands to run these tests, consider running your sh scripts with the "|| true" suffix, this tells the linux sh script to exit with a result code of 0, even if your real command exited with an exit code.
example:
stage('Test') {
def testScript = ""
def testProjects = findFiles(glob: 'test/**/project.json')
if (!fileExists('reports/xml')) {
if (!fileExists('reports')) {
sh "mkdir reports"
}
sh "mkdir reports/xml"
}
for(prj in testProjects) {
println "Test project located, running tests: " + prj.path
def matcher = prj.path =~ 'test\\/(.+)\\/project.json'
testScript += "dotnet test --no-build '${prj.path}' -xml 'reports/xml/${matcher[0][1]}.Results.xml' || true\n"
}
sh testScript

Resources