first commit
This commit is contained in:
131
createapp.pl
Normal file
131
createapp.pl
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::Printer;
|
||||
use File::Find;
|
||||
use File::Copy;
|
||||
use Cwd;
|
||||
use File::Slurp;
|
||||
|
||||
my $secret = `openssl rand -base64 48`;
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
|
||||
$year = $year+1900;
|
||||
|
||||
chomp $secret;
|
||||
|
||||
my $rc = system('git --version');
|
||||
if ( $rc < 0) {
|
||||
print STDOUT "GIT scheint nicht installiert zu sein, Programm wird geschlossen\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
print "Wie soll das neue Programm heißen: ";
|
||||
chomp( my $name = <ARGV> );
|
||||
|
||||
if ( $name !~ /^[a-z]*$/ ) {
|
||||
print STDOUT "Programmname muss existieren und darf nur kleinbuchstaben beinhalten, Programm wird geschlossen\n";
|
||||
exit 0;
|
||||
} elsif ( $name eq 'xxx' ) {
|
||||
print STDOUT "Programmname darf nicht xxx heißen, Programm wird geschlossen\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
print "Wohin soll das neue Programm kopiert werden ( $ENV{'HOME'}/mojo ): ";
|
||||
chomp( my $wohin = <ARGV> );
|
||||
|
||||
if ( $wohin eq "" ) {
|
||||
$wohin = "$ENV{'HOME'}/mojo";
|
||||
};
|
||||
if ( !-d $wohin ) {
|
||||
print STDOUT "Ordner existiert nicht, Programm wird geschlossen\n";
|
||||
exit 0;
|
||||
} elsif ( $wohin =~ /create_mojo_app/ ) {
|
||||
print STDOUT "Ordner mit create_mojo_app im Namen sind nicht erlaubt, Programm wird geschlossen\n";
|
||||
exit 0;
|
||||
} elsif ( !-w $wohin ) {
|
||||
print STDOUT "in Ordner $wohin kann nicht geschrieben werden, Programm wird geschlossen\n";
|
||||
exit 0;
|
||||
} else {
|
||||
|
||||
}
|
||||
$wohin = $wohin =~ s/\/*$//r; # letztes / entfernen
|
||||
|
||||
my $lname = lcfirst $name;
|
||||
my $uname = ucfirst $name;
|
||||
|
||||
print "Wofür ist $lname: ";
|
||||
chomp( my $wofuer = <ARGV> );
|
||||
|
||||
print "auf welchem Port soll $uname laufen (Default 3000): ";
|
||||
chomp( my $port = <ARGV> );
|
||||
if ( $port eq "" ) { $port = 3000 }
|
||||
|
||||
my $dir = getcwd;
|
||||
|
||||
# Ordner und Dateinamen in xxx durchgehen und XXX mit neuen Appnamen ersetzen
|
||||
find( \&files, 'xxx' );
|
||||
|
||||
sub files {
|
||||
my $str = $File::Find::name;
|
||||
$str =~ s/Xxx/$uname/g;
|
||||
$str =~ s/xxx/$lname/g;
|
||||
|
||||
if (-d) {
|
||||
mkdir $wohin . '/' . $str;
|
||||
}
|
||||
else {
|
||||
copy( $dir . '/' . $File::Find::name, $wohin . '/' . $str )
|
||||
or die "The move operation failed: $!";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# Dateien in neuen Appordner durchgehen und Werte mit neuen ersetzen
|
||||
find( \&newfiles, "$wohin/$lname" );
|
||||
|
||||
sub newfiles {
|
||||
|
||||
if (-f) {
|
||||
|
||||
#print "File: $dir/$File::Find::name\n";
|
||||
if ( $File::Find::name !~ m/.png/g ) {
|
||||
my @lines = read_file($File::Find::name);
|
||||
write_file($File::Find::name, '');
|
||||
|
||||
for my $line (@lines) {
|
||||
$line =~ s/mojocreateyear/$year/g;
|
||||
$line =~ s/Xxx/$uname/g;
|
||||
$line =~ s/xxx/$lname/g;
|
||||
$line =~ s/mojoappsecret/$secret/g;
|
||||
$line =~ s/hypnotoadport/$port/g;
|
||||
$line =~ s/wofuer/$wofuer/g;
|
||||
append_file($File::Find::name, $line);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# Rechte der Datei ändern
|
||||
|
||||
chmod( 0755, "$wohin/$lname/app/morbo.sh" );
|
||||
chmod( 0755, "$wohin/$lname/app/test.sh" );
|
||||
chmod( 0755, "$wohin/$lname/deb/DEBIAN/postinst" );
|
||||
chmod( 0755, "$wohin/$lname/deb/DEBIAN/prerm" );
|
||||
chmod( 0755, "$wohin/$lname/deb/pbuild.sh" );
|
||||
|
||||
print "App: $uname erstellt\n";
|
||||
chdir "$wohin/$lname/";
|
||||
system( "git init" );
|
||||
system( "git add ." );
|
||||
system( "git commit -m 'initialer Commit'" );
|
||||
system( "git remote add origin git\@git:WebApps/$uname.git" );
|
||||
|
||||
system( "$wohin/$lname/deb/pbuild.sh" ) == 0
|
||||
or die "Bash Script failed";
|
||||
1;
|
||||
|
||||
system( "$wohin/$lname/app/morbo.sh" ) == 0
|
||||
or die "Bash Script failed";
|
||||
1;
|
||||
Reference in New Issue
Block a user