-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·95 lines (69 loc) · 2.18 KB
/
deploy
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
#!/usr/bin/perl
use Term::ANSIColor;
use Switch;
#Some Config
require "./config/config.conf"; # This file has a list of Paths used
$appName = "Deploy"; # App Name
$version = "0001"; # Version
# Check for root level access before proceeding
checkForRoot($appName);
# Check to see if we're parsing an image file
if ( $ARGV[0] eq "" ) {
displayError("$appName requires image file as argument");
}
else {
$imageFile = $ARGV[0];
}
switch ($ARGV[0]) {
case '-h' { print "Usage: ./deploy <imageFile.dmg>\n"; exit(); }
case 'h' { print "Usage: ./deploy <imageFile.dmg>\n"; exit(); }
case 'H' { print "Usage: ./deploy <imageFile.dmg>\n"; exit(); }
case 'help' { print "Usage: ./deploy <imageFile.dmg>\n"; exit(); }
case '-help' { print "Usage: ./deploy <imageFile.dmg>\n"; exit(); }
case 'Help' { print "Usage: ./deploy <imageFile.dmg>\n"; exit(); }
}
sub checkForRoot{
$appName = shift;
if ( $< != 0 ) {
displayError("$appName must be run as root (or use sudo).");
}
}
###Mount the disk image path passed from the file###
# Check if image on path exists
checkPathExists($imageFile);
# Index /Volumes for a first time
$dirtoget="/Volumes/";
opendir(IMD, $dirtoget) || die("Cannot open directory");
@thefiles= readdir(IMD);
closedir(IMD);
foreach $f (@thefiles)
{
unless ( ($f eq ".") || ($f eq "..") )
{
#print "$f\n";
}
}
# Mount the image
$cmd = 'open ./blah.dmg';
system $cmd;
sleep(10); # Sleep the script, hopefully the disk image will be mounted by the time we wake up...
# Reindex /Volumes to see what the changes were
#mount the dmg
$dirtoget="/Volumes/";
opendir(IMD, $dirtoget) || die("Cannot open directory");
@thefiles2= readdir(IMD);
closedir(IMD);
# Put the results differences between the two indexes into an array
for $i (@thefiles2) {
print "$i\n" if ! grep {$i == $_} @thefiles;
}
# Check to see if there array has more than one element (if it does, we've picked up more than one item)
# Pull the new volume name out and assign it to a variable name
sub displayError {
$errorText = shift;
print color 'bold red';
print "ERROR: ";
print color 'reset';
print "$errorText\n\n";
exit 1;
}