From 3660bdfcf5c2417f0ebcee8113fb6d359be4f06c Mon Sep 17 00:00:00 2001 From: iliajie Date: Thu, 11 Aug 2022 16:23:29 +0300 Subject: [PATCH 1/9] Add support to install multiple versions of Webmin with `systemd` --- init/atboot.pl | 2 +- setup.pl | 30 ++++++++++++++++-------------- setup.sh | 30 ++++++++++++++++++------------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/init/atboot.pl b/init/atboot.pl index 569f8311c..17231df20 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -12,7 +12,7 @@ my $kill = &has_command("kill"); if ($init_mode eq "osx") { # Darwin System - &enable_at_boot("webmin", "Webmin administration server", + &enable_at_boot("$product", "Webmin administration server", "$config_directory/.start-init >/dev/null 2>&1 "$var_dir/miniserv.log", 'errorlog' => "$var_dir/miniserv.error", 'pidfile' => "$var_dir/miniserv.pid", + 'bootscript' => "$bootscript", 'logtime' => 168, 'ppath' => $ppath, 'ssl' => $ssl, @@ -540,7 +542,7 @@ if ($os_type eq "windows") { open(START, ">>$config_directory/start.bat"); print START "$perl \"$wadir/miniserv.pl\" $config_directory/miniserv.conf\n"; close(START); - $start_cmd = "sc start ".($ENV{'bootscript'} || "webmin"); + $start_cmd = "sc start $bootscript"; open(STOP, ">>$config_directory/stop.bat"); print STOP "echo Not implemented\n"; @@ -597,12 +599,12 @@ else { print STOP " touch $var_dir/stop-flag\n"; print STOP " if [ \"\$1\" = \"--kill\" ]; then\n"; print STOP " sleep 1\n"; - print STOP " ((ps axf | grep \"webmin\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null\n"; + print STOP " ((ps axf | grep \"$wadir\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null\n"; print STOP " fi\n"; print STOP " exit 0\n"; print STOP "else\n"; print STOP " if [ \"\$1\" = \"--kill\" ]; then\n"; - print STOP " (ps axf | grep \"webmin\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null\n"; + print STOP " (ps axf | grep \"$wadir\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null\n"; print STOP " fi\n"; print STOP "fi\n"; close(STOP); @@ -694,42 +696,42 @@ else { # Start systemd open(STARTD, ">$config_directory/start"); - print STARTD "$systemctlcmd start webmin\n"; + print STARTD "$systemctlcmd start $bootscript\n"; close(STARTD); # Stop systemd open(STOPD, ">$config_directory/stop"); - print STOPD "$systemctlcmd stop webmin\n"; + print STOPD "$systemctlcmd stop $bootscript\n"; close(STOPD); # Restart systemd open(RESTARTD, ">$config_directory/restart"); - print RESTARTD "$systemctlcmd restart webmin\n"; + print RESTARTD "$systemctlcmd restart $bootscript\n"; close(RESTARTD); # Force reload systemd open(FRELOADD, ">$config_directory/restart-by-force-kill"); - print FRELOADD "$systemctlcmd stop webmin\n"; + print FRELOADD "$systemctlcmd stop $bootscript\n"; print FRELOADD "$config_directory/.stop-init --kill >/dev/null 2>&1\n"; - print FRELOADD "$systemctlcmd start webmin\n"; + print FRELOADD "$systemctlcmd start $bootscript\n"; close(FRELOADD); # Reload systemd open(RELOADD, ">$config_directory/reload"); - print RELOADD "$systemctlcmd reload webmin\n"; + print RELOADD "$systemctlcmd reload $bootscript\n"; close(RELOADD); # Pre install open(PREINSTT, ">$config_directory/.pre-install"); print PREINSTT "#!/bin/sh\n"; - #print PREINSTT "$systemctlcmd kill --signal=SIGSTOP --kill-who=main webmin\n"; + #print PREINSTT "$systemctlcmd kill --signal=SIGSTOP --kill-who=main $bootscript\n"; close(PREINSTT); # Post install open(POSTINSTT, ">$config_directory/.post-install"); print POSTINSTT "#!/bin/sh\n"; - #print POSTINSTT "$systemctlcmd kill --signal=SIGCONT --kill-who=main webmin\n"; - print POSTINSTT "$systemctlcmd kill --signal=SIGHUP --kill-who=main webmin\n"; + #print POSTINSTT "$systemctlcmd kill --signal=SIGCONT --kill-who=main $bootscript\n"; + print POSTINSTT "$systemctlcmd kill --signal=SIGHUP --kill-who=main $bootscript\n"; close(POSTINSTT); chmod(0755, "$config_directory/start"); @@ -743,7 +745,7 @@ else { # Fix existing systemd webmin.service file to update start and stop commands my $perl = &get_perl_path(); chdir("$wadir/init"); - system("$perl "."e_path("$wadir/init/updateboot.pl")." webmin"); + system("$perl "."e_path("$wadir/init/updateboot.pl")." $bootscript"); } } print ".. done\n"; @@ -805,7 +807,7 @@ $gconfig{'product'} ||= "webmin"; if ($makeboot) { print "Configuring Webmin to start at boot time ..\n"; chdir("$wadir/init"); - system("$perl "."e_path("$wadir/init/atboot.pl")." ".$ENV{'bootscript'}); + system("$perl "."e_path("$wadir/init/atboot.pl")." $bootscript"); print ".. done\n"; print "\n"; } diff --git a/setup.sh b/setup.sh index a43832c3e..b979c7dc8 100755 --- a/setup.sh +++ b/setup.sh @@ -8,6 +8,11 @@ LANG= export LANG LANGUAGE= export LANGUAGE + +if [ "$bootscript" = "" ]; then + bootscript="webmin" +fi + cd `dirname $0` if [ -x /bin/pwd ]; then wadir=`/bin/pwd` @@ -489,6 +494,7 @@ else echo "logfile=$var_dir/miniserv.log" >> $cfile echo "errorlog=$var_dir/miniserv.error" >> $cfile echo "pidfile=$var_dir/miniserv.pid" >> $cfile + echo "bootscript=$bootscript" >> $cfile echo "logtime=168" >> $cfile echo "ssl=$ssl" >> $cfile echo "no_ssl2=1" >> $cfile @@ -653,12 +659,12 @@ echo " kill \$pid || exit 1" >>$config_dir/.stop-init echo " touch $var_dir/stop-flag" >>$config_dir/.stop-init echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init echo " sleep 1" >>$config_dir/.stop-init -echo " ((ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/.stop-init +echo " ((ps axf | grep \"$wadir\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/.stop-init echo " fi" >>$config_dir/.stop-init echo " exit 0" >>$config_dir/.stop-init echo "else" >>$config_dir/.stop-init echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init -echo " (ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null" >>$config_dir/.stop-init +echo " (ps axf | grep \"$wadir\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null" >>$config_dir/.stop-init echo " fi" >>$config_dir/.stop-init echo "fi" >>$config_dir/.stop-init # Restart main @@ -719,31 +725,31 @@ if [ -x "$systemctlcmd" ]; then echo "Creating start and stop scripts (systemd) .." # Start systemd echo "#!/bin/sh" >$config_dir/start - echo "$systemctlcmd start webmin" >>$config_dir/start + echo "$systemctlcmd start $bootscript" >>$config_dir/start # Stop systemd echo "#!/bin/sh" >$config_dir/stop - echo "$systemctlcmd stop webmin" >>$config_dir/stop + echo "$systemctlcmd stop $bootscript" >>$config_dir/stop # Restart systemd echo "#!/bin/sh" >$config_dir/restart - echo "$systemctlcmd restart webmin" >>$config_dir/restart + echo "$systemctlcmd restart $bootscript" >>$config_dir/restart # Force reload systemd echo "#!/bin/sh" >$config_dir/restart-by-force-kill - echo "$systemctlcmd stop webmin" >>$config_dir/restart-by-force-kill + echo "$systemctlcmd stop $bootscript" >>$config_dir/restart-by-force-kill echo "$config_dir/.stop-init --kill >/dev/null 2>&1" >>$config_dir/restart-by-force-kill - echo "$systemctlcmd start webmin" >>$config_dir/restart-by-force-kill + echo "$systemctlcmd start $bootscript" >>$config_dir/restart-by-force-kill # Reload systemd echo "#!/bin/sh" >$config_dir/reload - echo "$systemctlcmd reload webmin" >>$config_dir/reload + echo "$systemctlcmd reload $bootscript" >>$config_dir/reload # Pre-install on systemd echo "#!/bin/sh" >$config_dir/.pre-install - # echo "$systemctlcmd kill --signal=SIGSTOP --kill-who=main webmin" >>$config_dir/.pre-install + # echo "$systemctlcmd kill --signal=SIGSTOP --kill-who=main $bootscript" >>$config_dir/.pre-install # Post-install on systemd echo "#!/bin/sh" >$config_dir/.post-install - # echo "$systemctlcmd kill --signal=SIGCONT --kill-who=main webmin" >>$config_dir/.post-install - echo "$systemctlcmd kill --signal=SIGHUP --kill-who=main webmin" >>$config_dir/.post-install + # echo "$systemctlcmd kill --signal=SIGCONT --kill-who=main $bootscript" >>$config_dir/.post-install + echo "$systemctlcmd kill --signal=SIGHUP --kill-who=main $bootscript" >>$config_dir/.post-install # Fix existing systemd webmin.service file to update start and stop commands - (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "webmin") + (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "$bootscript") chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload $config_dir/.pre-install $config_dir/.post-install else From 6a5b605024c5358d150012aed812bcddfaaff22f Mon Sep 17 00:00:00 2001 From: iliajie Date: Thu, 11 Aug 2022 19:07:13 +0300 Subject: [PATCH 2/9] Remove redundant quotes --- init/atboot.pl | 2 +- setup.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/init/atboot.pl b/init/atboot.pl index 17231df20..954616fdb 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -12,7 +12,7 @@ my $kill = &has_command("kill"); if ($init_mode eq "osx") { # Darwin System - &enable_at_boot("$product", "Webmin administration server", + &enable_at_boot($product, "Webmin administration server", "$config_directory/.start-init >/dev/null 2>&1 "$var_dir/miniserv.log", 'errorlog' => "$var_dir/miniserv.error", 'pidfile' => "$var_dir/miniserv.pid", - 'bootscript' => "$bootscript", + 'bootscript' => $bootscript, 'logtime' => 168, 'ppath' => $ppath, 'ssl' => $ssl, From ea03e5a3382a351ca6bf1cec2cc1966484d17c75 Mon Sep 17 00:00:00 2001 From: iliajie Date: Thu, 11 Aug 2022 22:40:35 +0300 Subject: [PATCH 3/9] Fix to consider var directory and bootscript upon upgrades --- setup.pl | 15 ++++++++++++++- setup.sh | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/setup.pl b/setup.pl index 3eca7a87d..6b178cb66 100755 --- a/setup.pl +++ b/setup.pl @@ -122,8 +122,17 @@ if ($upgrading) { open(VAR, "$config_directory/var-path"); chop($var_dir = ); $var_directory = $var_dir; + $ENV{'WEBMIN_VAR'} = $var_directory; close(VAR); + # Get current bootscript name + if (-r "$config_directory/bootscript-name") { + open(BOOTVAR, "$config_directory/bootscript-name"); + chop($bootscript = ); + close(BOOTVAR); + $bootscript ||= ($ENV{'bootscript'} || "webmin"); + } + # Force creation if non-existant mkdir($var_dir, 0755); @@ -189,7 +198,8 @@ else { } # Ask for log directory - print "Log file directory [/var/webmin]: "; + my $envvardir = $ENV{'var_dir'} || "/var/webmin"; + print "Log file directory [$envvardir]: "; if ($ENV{'var_dir'}) { $var_dir = $ENV{'var_dir'}; } @@ -376,6 +386,9 @@ else { open(VAR, ">$config_directory/var-path"); print VAR $var_dir,"\n"; close(VAR); + open(BOOTS, ">$config_directory/bootscript-name"); + print BOOTS $bootscript,"\n"; + close(BOOTS); print "Creating web server config files ..\n"; $ufile = "$config_directory/miniserv.users"; diff --git a/setup.sh b/setup.sh index b979c7dc8..b271450bc 100755 --- a/setup.sh +++ b/setup.sh @@ -143,6 +143,14 @@ if [ "$upgrading" = 1 ]; then # Get current var path var_dir=`cat $config_dir/var-path` + # Get current bootscript + if [ -r "$config_dir/bootscript-name" ]; then + bootscript=`cat $config_dir/bootscript-name` + if [ "$bootscript" = "" ]; then + bootscript="webmin" + fi + fi + # Force creation if non-existant mkdir -p $var_dir >/dev/null 2>&1 @@ -216,7 +224,11 @@ else fi # Ask for log directory - printf "Log file directory [/var/webmin]: " + envvardir="$var_dir" + if [ "$envvardir" = "" ]; then + envvardir=/var/webmin + fi + printf "Log file directory [$envvardir]: " if [ "$var_dir" = "" ]; then read var_dir fi @@ -484,6 +496,7 @@ else # Create webserver config file echo $perl > $config_dir/perl-path echo $var_dir > $config_dir/var-path + echo $bootscript > $config_dir/bootscript-name echo "Creating web server config files .." cfile=$config_dir/miniserv.conf echo "port=$port" >> $cfile From b1fd91034f7430ac7c547026099f0089c6b157b5 Mon Sep 17 00:00:00 2001 From: iliajie Date: Fri, 12 Aug 2022 12:55:56 +0300 Subject: [PATCH 4/9] Fix to consider config directory upon upgrades --- setup.pl | 8 ++++++-- setup.sh | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/setup.pl b/setup.pl index 6b178cb66..7c0f902f4 100755 --- a/setup.pl +++ b/setup.pl @@ -84,9 +84,13 @@ print "Webmin uses separate directories for configuration files and log files.\n print "Unless you want to run multiple versions of Webmin at the same time\n"; print "you can just accept the defaults.\n"; print "\n"; -print "Config file directory [/etc/webmin]: "; +my $envetcdir = $ENV{'config_directory'} || "/etc/webmin"; +print "Config file directory [$envetcdir]: "; if ($ENV{'config_directory'}) { $config_directory = $ENV{'config_directory'}; + print "$envetcdir\n"; + print ".. predefined\n"; + $envetcdirexists = 1; } else { chop($config_directory = ); @@ -101,7 +105,7 @@ if (!-d $config_directory) { &errorexit("Failed to create directory $config_directory"); } if (-r "$config_directory/config") { - print ".. found\n"; + print ".. found\n" if (!$envetcdirexists); $upgrading = 1; } diff --git a/setup.sh b/setup.sh index b271450bc..864698d83 100755 --- a/setup.sh +++ b/setup.sh @@ -110,7 +110,12 @@ echo "Webmin uses separate directories for configuration files and log files." echo "Unless you want to run multiple versions of Webmin at the same time" echo "you can just accept the defaults." echo "" -printf "Config file directory [/etc/webmin]: " +envetcdir="$config_dir" +if [ "$envetcdir" = "" ]; then + envetcdir=/etc/webmin + envetcdirnotfound=1 +fi +printf "Config file directory [$envetcdir]: " if [ "$config_dir" = "" ]; then read config_dir fi @@ -132,8 +137,17 @@ if [ ! -d $config_dir ]; then fi fi if [ -r "$config_dir/config" -a -r "$config_dir/var-path" -a -r "$config_dir/perl-path" ]; then - echo ".. found" + if [ "$envetcdirnotfound" = "" ]; then + echo "$envetcdir" + echo ".. predefined" + else + echo ".. found" + fi upgrading=1 +else + if [ "$envetcdirnotfound" = "" ]; then + echo "$envetcdir" + fi fi # Check if upgrading from an old version @@ -227,6 +241,7 @@ else envvardir="$var_dir" if [ "$envvardir" = "" ]; then envvardir=/var/webmin + envvardirnotfound=1 fi printf "Log file directory [$envvardir]: " if [ "$var_dir" = "" ]; then @@ -254,6 +269,9 @@ else exit 3 fi fi + if [ "$upgrading" != 1 -a "$envetcdirnotfound" = "" ]; then + echo "$envvardir" + fi echo "" # Ask where perl is installed From 65b1d881d8424955bdefce53ebaaed92defe1d04 Mon Sep 17 00:00:00 2001 From: iliajie Date: Fri, 12 Aug 2022 13:00:42 +0300 Subject: [PATCH 5/9] Create given config and log directory recursively for `setup.sh` --- setup.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/setup.sh b/setup.sh index 864698d83..60aad7bcc 100755 --- a/setup.sh +++ b/setup.sh @@ -129,11 +129,14 @@ if [ "$abspath" = "" ]; then exit 2 fi if [ ! -d $config_dir ]; then - mkdir $config_dir; + mkdir -p $config_dir; if [ $? != 0 ]; then - echo "ERROR: Failed to create directory $config_dir" - echo "" - exit 2 + mkdir $config_dir; + if [ $? != 0 ]; then + echo "ERROR: Failed to create directory $config_dir" + echo "" + exit 2 + fi fi fi if [ -r "$config_dir/config" -a -r "$config_dir/var-path" -a -r "$config_dir/perl-path" ]; then @@ -262,11 +265,14 @@ else exit 3 fi if [ ! -d $var_dir ]; then - mkdir $var_dir + mkdir -p $var_dir if [ $? != 0 ]; then - echo "ERROR: Failed to create directory $var_dir" - echo "" - exit 3 + mkdir $var_dir + if [ $? != 0 ]; then + echo "ERROR: Failed to create directory $var_dir" + echo "" + exit 3 + fi fi fi if [ "$upgrading" != 1 -a "$envetcdirnotfound" = "" ]; then From dcdf0c59ae16449e48d06acf8831fd1338d0cf46 Mon Sep 17 00:00:00 2001 From: iliajie Date: Fri, 12 Aug 2022 13:01:25 +0300 Subject: [PATCH 6/9] Create given config and log directory recursively for `setup.pl` .. apply permissions only if a new directory was created --- setup.pl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/setup.pl b/setup.pl index 7c0f902f4..b16c4b935 100755 --- a/setup.pl +++ b/setup.pl @@ -101,7 +101,7 @@ if ($config_directory !~ /^([a-z]:)?\//i) { &errorexit("Config directory must be an absolute path"); } if (!-d $config_directory) { - mkdir($config_directory, 0755) || + make_dir_recursive_local($config_directory, 0755) || &errorexit("Failed to create directory $config_directory"); } if (-r "$config_directory/config") { @@ -220,7 +220,7 @@ else { &errorexit("Log directory cannot be /"); } if (!-d $var_dir) { - mkdir($var_dir, 0755) || + make_dir_recursive_local($var_dir, 0755) || &errorexit("Failed to create directory $var_dir"); } $ENV{'WEBMIN_VAR'} = $var_dir; @@ -1010,3 +1010,19 @@ closedir(DIR); return @rv; } +sub make_dir_recursive_local +{ +my ($dir, $mod) = @_; +my @folders = split /\//, $dir; +map { + if ($_) { + if (mkdir $_) { + chmod($mod, $_) if ($mod && -d $_); + } + chdir $_;} + else { + chdir '/'; + } +} @folders; +return -d $dir; +} From 7a5b09464525c94da0d5ba9b7246d5ebd68ec8ae Mon Sep 17 00:00:00 2001 From: iliajie Date: Sat, 13 Aug 2022 12:54:13 +0300 Subject: [PATCH 7/9] Don't call `mkdir` another time as `mkdir -p` seems to be cross-platform --- setup.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/setup.sh b/setup.sh index 60aad7bcc..d71c07325 100755 --- a/setup.sh +++ b/setup.sh @@ -131,12 +131,9 @@ fi if [ ! -d $config_dir ]; then mkdir -p $config_dir; if [ $? != 0 ]; then - mkdir $config_dir; - if [ $? != 0 ]; then - echo "ERROR: Failed to create directory $config_dir" - echo "" - exit 2 - fi + echo "ERROR: Failed to create directory $config_dir" + echo "" + exit 2 fi fi if [ -r "$config_dir/config" -a -r "$config_dir/var-path" -a -r "$config_dir/perl-path" ]; then @@ -267,12 +264,9 @@ else if [ ! -d $var_dir ]; then mkdir -p $var_dir if [ $? != 0 ]; then - mkdir $var_dir - if [ $? != 0 ]; then - echo "ERROR: Failed to create directory $var_dir" - echo "" - exit 3 - fi + echo "ERROR: Failed to create directory $var_dir" + echo "" + exit 3 fi fi if [ "$upgrading" != 1 -a "$envetcdirnotfound" = "" ]; then From baadd9c9940d278186475065df16469512e26a6c Mon Sep 17 00:00:00 2001 From: iliajie Date: Sat, 13 Aug 2022 12:57:04 +0300 Subject: [PATCH 8/9] Fix not store redundant `bootscript` record in `miniserv.conf` file --- setup.pl | 1 - setup.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/setup.pl b/setup.pl index b16c4b935..64ce37d44 100755 --- a/setup.pl +++ b/setup.pl @@ -405,7 +405,6 @@ else { 'logfile' => "$var_dir/miniserv.log", 'errorlog' => "$var_dir/miniserv.error", 'pidfile' => "$var_dir/miniserv.pid", - 'bootscript' => $bootscript, 'logtime' => 168, 'ppath' => $ppath, 'ssl' => $ssl, diff --git a/setup.sh b/setup.sh index d71c07325..8a50e1270 100755 --- a/setup.sh +++ b/setup.sh @@ -525,7 +525,6 @@ else echo "logfile=$var_dir/miniserv.log" >> $cfile echo "errorlog=$var_dir/miniserv.error" >> $cfile echo "pidfile=$var_dir/miniserv.pid" >> $cfile - echo "bootscript=$bootscript" >> $cfile echo "logtime=168" >> $cfile echo "ssl=$ssl" >> $cfile echo "no_ssl2=1" >> $cfile From 82937d72963ff8309bd4914690dbf1f3b85aa168 Mon Sep 17 00:00:00 2001 From: iliajie Date: Sat, 13 Aug 2022 18:44:48 +0300 Subject: [PATCH 9/9] Fix to create parent folders without `chdir` --- setup.pl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/setup.pl b/setup.pl index 64ce37d44..524c6216e 100755 --- a/setup.pl +++ b/setup.pl @@ -1012,16 +1012,15 @@ return @rv; sub make_dir_recursive_local { my ($dir, $mod) = @_; -my @folders = split /\//, $dir; -map { - if ($_) { - if (mkdir $_) { - chmod($mod, $_) if ($mod && -d $_); - } - chdir $_;} - else { - chdir '/'; +my @folders = split(/\//, $dir); +my $folder_created; +foreach my $folder (@folders) { + next if (!$folder); + $folder_created .= "/$folder"; + if (mkdir($folder_created)) { + chmod($mod, $folder_created) + if ($mod && -d $folder_created); } -} @folders; + } return -d $dir; }