-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.pl
executable file
·81 lines (63 loc) · 1.87 KB
/
setup.pl
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
#!/opt/perl/bin/perl
#
use Mojo::Base -strict, -signatures;
use Data::Dumper::Concise;
use JSON;
use Getopt::Long;
my $install_dir = "/opt/scot4-inbox";
my $inbox_user = "scotinbox";
my $inbox_group = "scotinbox";
my $nocontainer = 0; # 0 = in container
my $clean = 0;
####
#### NON DOCKER/Container install script
#### only use if you wish to install directly on a host
####
GetOptions(
"instdir=s" => \$install_dir,
"user=s" => \$inbox_user,
"group=s" => \$inbox_group,
"nocontainer" => \$nocontainer,
) or die <<EOF;
Usage:
$0
[--instdir /path/to/dir] where to install
[--user username] unix user to own this process
[--group group] unix group to own this process
[--nocontainer] install to not be run inside container
[--clean] delete contents of instdir prior to install
EOF
if ( $> != 0 ) {
die "You must execute this script with effective root privileges. try: sudo $0";
}
if ($install_dir eq '/' or $install_dir eq ' ' or $install_dir eq '') {
die 'Can not install on / or blank install dir!';
}
my $prep = << "EOF";
if grep --quiet -c $inbox_group: /etc/group; then
echo "$inbox_group already exists, reusing..."
else
groupadd $inbox_group
fi
if grep --quiet -c $inbox_user: /etc/passwd; then
echo "$inbox_user already exists, reusing..."
else
useradd -c "Scot Inbox User" -g $inbox_group -d $install_dir -M -s /bin/bash $inbox_user
fi
EOF
system($prep);
if (-d $install_dir) {
say "$install_dir exists...";
if ($clean) {
say "...you asked to clean it...";
system("rm -rf $install_dir/*");
system("mkdir -p $install_dir");
}
}
else {
system("mkdir -p $install_dir");
}
my $copyscript = << "EOF";
tar --exclude-vcs -cf - . | (cd $install_dir; tar xf -)
EOF
system($copyscript);