-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmconsole_install_obsolete
executable file
·152 lines (121 loc) · 3.78 KB
/
gmconsole_install_obsolete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env perl
use strict;
use warnings;
use Term::ANSIColor qw(:constants);
use Data::Dumper;
use experimental qw( switch );
use Cwd 'abs_path';
use Sys::Hostname;
use File::Basename;
use Getopt::Long;
my $opt_branch='gmconsole';
my $opt_help=0;
my $opt_debug=0;
my $opt_verbose=0;
my $opt_repo='';
GetOptions(
"branch=s" => \$opt_branch,
"help" => \$opt_help,
"debug" => \$opt_debug,
"verbose" => \$opt_verbose,
"repo=s" => \$opt_repo
) || logmsg('error',"Invalid arguments\n");
my $dst=$ARGV[0];
show_help() if ($opt_help || !$dst);
$dst=abs_path($dst);
logmsg( "task", "Installation information\n" );
logmsg('info',"Destination: $dst\n");
logmsg('info',"Repo: $opt_repo\n");
logmsg('info',"Branch: $opt_branch\n");
logmsg('info',"Verbose: $opt_verbose\n");
logmsg('info',"Debug: $opt_debug\n");
############
my $PATH_ORIG = abs_path("."); # current cwd
my $PATH = dirname( abs_path($0) ); # path to location of this script
chdir($PATH);
logmsg( "info", "Path: $PATH\n" );
#############
logmsg( 'info', "Check destination..." );
if (-e $dst) {
logmsg('error',"Destination already exists\n");
}
logmsg('ok');
###########
my $tmp = join ' ', ( 'git', 'libyaml-libyaml-perl', 'vim');
logmsg( 'info', "Install prerequisites ($tmp)..." );
execute("apt-get update");
execute("apt-get install -y $tmp");
logmsg('ok');
###########
logmsg( 'info', "Cloning base installation..." );
execute("GIT_SSH_COMMAND=\"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\" git clone git\@github.com:bc547/gmconsole-default.git $dst");
logmsg('ok');
###########
chdir $dst;
logmsg( 'info', "Create new repo..." );
execute("git describe --tags --first-parent --abbrev=10 --long --dirty --always > gmconsole-default.version");
execute("rm -rf .git run_install.sh run_install");
execute("git init");
execute('git config user.email "bc547@proplab.be"');
execute('git config user.name "BC547"');
execute("git add *");
execute("git add .gitignore");
execute("git commit -m 'Initial commit'");
logmsg('ok');
###########
if ($opt_repo) {
logmsg( 'info', "Pushing new repo to $opt_repo and branch $opt_branch..." );
execute("git remote add origin $opt_repo");
execute("git branch -M $opt_branch");
execute("GIT_SSH_COMMAND=\"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\" git push -u origin $opt_branch");
logmsg('ok');
}
############
chdir($PATH_ORIG);
logmsg( 'task', "Done... Remember to execute run_system with real root privileges\n" );
###################################################################################
sub logmsg {
my ( $type, $msg ) = @_;
given ($type) {
when (/^skipped/) {
print BRIGHT_WHITE "SKIPPED\n", RESET;
}
when (/^ok/) {
print BRIGHT_GREEN "OK\n", RESET;
}
when (/^error/) {
print BRIGHT_RED "FAIL\n", RESET;
print $msg;
exit(1);
}
when (/^task/) {
print BRIGHT_YELLOW $msg, RESET;
}
when (/^info/) {
print $msg;
}
default {
print BRIGHT_RED "Unknown log type: $type\n", RESET;
}
}
}
sub execute {
my ( $cmd, $ignore_error ) = @_;
#print "$cmd\n";
# return;
print "\n-> $cmd\n" if ($opt_verbose);
my $output = `$cmd 2>&1`;
my $retcode = $?;
if ( $retcode != 0 && (! $ignore_error) ) {
logmsg( 'error', "CMD:\n$cmd\nOUTPUT:\n$output" );
}
#logmsg( 'info', "CMD:\n$cmd\nOUTPUT:\n$output" );
return $retcode, $cmd, $output;
}
sub show_help {
print <<"EOF";
Usage: $0 [--branch NAME] [--debug] [--verbose] [--repo GITREPO] DESTINATION_PATH
Example: ./gmconsole_install --branch erl_gang1 --repo git\@github.com:proplab-erl/kiosk.git /docker
EOF
exit 1;
}