-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnimbie.sh
193 lines (141 loc) · 5.39 KB
/
nimbie.sh
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
# NOTE: THIS IS A LOCALIZED VERSION - CONTAINS REFERENCE TO AUTOLOADER THAT DOES NOT MATCH DEFAULT INSTALL
# jess whyte, @jesswhyte Aug 2018
# usage example : bash nimbie.sh /media/storage/Nimbie_ISOs/
# you have to request and download linux SDK from Acronova
# make /64/autoloader executable
## jess notes: continue points = not iso, blank blocksize or blank blockcount or dd status != 0
## jess notes: autoloader status on LOAD, +s14 = no disk there [DONE WITH PILE], +s07 = OK, + s10 = drive closed, + s12 = disk already in
function show_help() {
echo
echo -e "USAGE: bash nimbie.sh <output directory>"
echo -e "-This script relies on the Acronova autoloader SDK, which should be installed at /usr/local/bin/autoloader"
echo -e "-Autoloader requires sudo access to run"
echo -e "-ISOs will be stored in the <output directory>"
echo -e 'Example:\nbash nimbie.sh /mnt/data/Nimbie_ISOs/'
}
# Parse arguments
while getopts "h?" opt; do
case "$opt" in
h|\?)
show_help
exit
esac
done
##if you don't want nautilus to launch a window every time it mounts a disk
gsettings set org.gnome.desktop.media-handling automount-open false
autoloader="sudo /usr/local/bin/autoloader" # path to executable on local machine - not needed if added to path, etc.
## sometimes, the cd tray doesn't want to eject the first few times, but a warmup helps. TODO: look into this, but this works for now...
echo && echo "warming up CD tray..." && echo
eject /dev/sr1
eject -t /dev/sr1
eject /dev/sr1
eject -t /dev/sr1
echo "warmup done..." && echo
cdcheck(){
# this function adapted from cd.close - written by https://superuser.com/users/464868/allan
CDROM=/dev/sr1
TRIES="1 2 3 4"
INTERVAL=5
MOUNT=0
TOKENS=( $TRIES )
STOP=${TOKENS[-1]}
for i in $TRIES; do
#echo close: ATTEMPT $i of $STOP
output=`file -s $CDROM`
#echo OUTPUT $output
if [[ "$output" != "/dev/sr1: writable, no read permission" ]]; then #to do: think about ways to do this better, e.g. another method w/ clearer status exits
MOUNT=1
break
fi
if [ $i -eq $STOP ]; then
break
fi
#echo sleep: $INTERVAL SECONDS...
sleep $INTERVAL
done
if [ $MOUNT -eq 1 ]; then
#echo final: $CDROM
#printf "final: LABEL "
volname $CDROM
else
echo "final: NO MEDIA DETECTED"
reject
break
fi
}
reject(){
echo "REJECTING CD...will eject underneath the Nimbie..." && echo
eject /dev/sr1 && $autoloader PICK && eject -t /dev/sr1 && $autoloader REJECT
}
## initialize autoloader
echo "Intizializing Autoloader..." && echo
$autoloader INIT ## initialize the nimbie
echo
s_status="+S07" ## set starting s_status
while [ "s_status" != "+S14" ]; do
eject /dev/sr1 ## eject the drive tray
output=`$autoloader LOAD` ## load a disk
s_status=`echo $output | grep -oP "\+S\d\d"` # get the S-code from the $autoloader response, $autoloader S14 = no more disks
if [[ $s_status == "+S14" ]]; then
echo && echo "Done all the disks!" && echo
eject -t /dev/sr1
exit 0
fi
eject -t /dev/sr1 ## close the drive tray
cdcheck ## check cd is loaded
#cdinfo=`isoinfo -d -i /dev/sr1` # get isoinfo
time=`date +%Y%m%d_%H%M%S` # make a time stamp
## Set Volume name as variable
volume=`isoinfo -d -i /dev/sr1 | grep "^Volume id:" | cut -d ":" -f 2` # gets volume name
volume=`echo $volume | tr -d [:punct:] | sed 's/\s/\_/g'` # strips out punctuation and converts spaces to _
#if volume name is null set it to the timestamp...
if [[ -z "$volume" ]]; then
volume="null-volume-$time"
fi
path=`realpath $1` # assumes you gave a path as an argument
echo "Creating: ${path}/${volume}.iso" # assemble file name for destination .iso, echo for error checking
# Display cd Info
echo "---------------------CD INFO-----------------------"
isoinfo -d -i /dev/sr1
echo "----------------------------------------------------"
## Get Block size of CD ## NOTE: IF the CD is NOT AN ISO, IT IS REJECTED!
blocksize=`isoinfo -d -i /dev/sr1 | grep "^Logical block size is:" | cut -d ":" -f 2 | tr -d '[:space:]'` # gets blocksize from isoinfo output, if I do as variable, the string is too tricky
if test "$blocksize" = ""; then
echo catdevice FATAL ERROR: Blank blocksize. Rejecting disk. >&2
reject
continue
fi
## Get Block count of CD
blockcount=`isoinfo -d -i /dev/sr1 | grep "^Volume size is:" | cut -d ":" -f 2 | tr -d '[:space:]'` # gets blockcount from isoinfo output
if test "$blockcount" = ""; then
echo catdevice FATAL ERROR: Blank blockcount. Rejecting disk. >&2
reject
continue
fi
echo ""
echo "blocksize of CD is: "$blocksize
echo "blockcount of CD is: "$blockcount
echo ""
## Run dd on disc
dd if=/dev/sr1 of=$path/$volume.iso bs=$blocksize count=$blockcount status=progress
status=$?
if [ $status != 0 ]; then #not yet tested
reject
continue
fi
chgrp floppy $path/$volume.iso #change the owner group of iso to floppy
sleep 5
eject /dev/sr1 ## eject the drive tray
outputpick=`$autoloader PICK` ## pick up the disk
s_statuspick=`echo $outputpick | grep -oP "\+S\d\d"` # get the S-code from the $autoloader response, $autoloader S10 = drive closed, can't pick, sometimes there is an issue here
if [[ $s_statuspick == "+S10" ]]; then
echo "Drive is still closed, not ejecting...EXITING SCRIPT"
exit 0
fi
sleep 5
eject -t /dev/sr1 ##close the drive tray
sleep 5
$autoloader UNLOAD ##unload the disk
sleep 5
done