summaryrefslogtreecommitdiff
path: root/install
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2025-03-01 12:42:23 +0800
committerkaiwu <kaiwu2004@gmail.com>2025-03-01 12:42:23 +0800
commit3f33461e4948bf05e60bdff35ec6c57a649c7860 (patch)
tree284c2ba95a41536ae1bff6bea710db0709a64739 /install
downloadopenresty-3f33461e4948bf05e60bdff35ec6c57a649c7860.tar.gz
openresty-3f33461e4948bf05e60bdff35ec6c57a649c7860.zip
openresty bundle
Diffstat (limited to 'install')
-rwxr-xr-xinstall98
1 files changed, 98 insertions, 0 deletions
diff --git a/install b/install
new file mode 100755
index 0000000..34ae937
--- /dev/null
+++ b/install
@@ -0,0 +1,98 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Getopt::Std qw(getopts);
+
+my %opts;
+getopts("dm:", \%opts) or usage();
+
+my $mode = $opts{m};
+
+if ($opts{d}) {
+ shell("mkdir -p @ARGV");
+ exit;
+}
+
+if (@ARGV < 2) {
+ usage();
+}
+
+my $dst = pop;
+
+my @src = @ARGV;
+
+my $target_dir;
+
+if (@src > 1 || $dst =~ m{/$}) {
+ $target_dir = $dst;
+
+} elsif (-d $dst) {
+ $target_dir = $dst;
+
+} elsif ($dst =~ m{(.+)/}) {
+ $target_dir = $1;
+
+} else {
+ $target_dir = '.';
+}
+
+if (!-d $target_dir) {
+ shell("mkdir -p $target_dir");
+}
+
+if (-f $dst) {
+ shell("rm $dst");
+
+} else {
+ for my $f (@src) {
+ if (-f $f) {
+ (my $name = $f) =~ s{.*/}{}g;
+ my $target = "$target_dir/$name";
+ if (-f $target) {
+ shell("rm $target");
+ }
+ }
+ }
+}
+
+shell("cp @src $dst");
+
+if (-f $dst) {
+ if (defined $mode) {
+ chmod oct($mode), $dst or
+ die "failed to change mode of $dst to $mode.\n";
+ }
+
+ exit;
+}
+
+for my $src (@src) {
+ my $name;
+
+ if ($src =~ m{/([^/]+)$}) {
+ $name = $1;
+
+ } else {
+ $name = $src;
+ }
+
+ if (defined $mode) {
+ my $target = "$target_dir/$name";
+ chmod oct($mode), $target or
+ die "failed to change mode of $target to $mode.\n";
+ }
+}
+
+sub usage {
+ die "Usage: install [-d] [-m <attrs>] <src>... <dst>\n";
+}
+
+sub shell {
+ my $cmd = shift;
+ #warn $cmd;
+ system($cmd) == 0 or
+ die "failed to run command $cmd\n";
+}
+