-
Notifications
You must be signed in to change notification settings - Fork 0
/
0ask-name-copy.sh
executable file
·95 lines (74 loc) · 1.97 KB
/
0ask-name-copy.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
#!/bin/bash
### START CONFIG ###
# number of seconds to wait before checking for a disc
SLEEP=30
# file to keep track of copied discs
COMPLETEDFILE="0done.list"
# working dir for copying DVD to ISO
WORKDIR="$PWD/0COPYING"
# location to save ISOs
OUTPUTDIR="/data/mirror0/ripping"
### END CONFIG ###
# grab drive number to use
DRIVE=$1
# setup environment
touch $COMPLETEDFILE
mkdir -p $WORKDIR
function logger {
TS=`date`
echo "[${TS}] $@"
}
function ejectdisc {
sudo eject /dev/sr${DRIVE}
}
function waitfordisc {
CHECKDISC=`ls -la /dev/disk/by-label/ | grep sr${DRIVE}`
if [ $? -eq 0 ]; then
logger "INFO: Disc detected... Processing..."
processdisc
else
logger "INFO: No disc found... Sleeping ${SLEEP} sec..."
sleep $SLEEP
fi
waitfordisc
}
function processdisc {
# check if disc processed
NAME=`ls -la /dev/disk/by-label/ | grep sr${DRIVE} | awk '{ print $9 }'`
PROCESSED=`grep $NAME ${COMPLETEDFILE}`
if [ $? -eq 0 ]; then
logger "ERROR: Disc already processed... $PROCESSED"
ejectdisc
sleep $SLEEP
waitfordisc
else
echo "DISC NAME: $NAME"
echo -n "Enter new name or press [ENTER] to continue: "
read NEWNAME
if [ "$NEWNAME" != "" ]; then
NAME="${NEWNAME}"
fi
logger "INFO: Disc not copied... Starting process for disc '$NAME'"
fi
# mount to get size
sudo mkdir -p /media/cdrom${DRIVE}
sudo mount /dev/sr${DRIVE} /media/cdrom${DRIVE} &> /dev/null
SIZE=`df | grep sr${DRIVE} | awk '{ print $2 }'`
sudo umount /dev/sr${DRIVE}
# start copy
sudo dd if=/dev/sr${DRIVE} | pv -s ${SIZE}K | dd of=${WORKDIR}/${NAME}.iso bs=2048 conv=noerror,notrunc
# disc processed
logger "INFO: Disc copied... Ejecting disc..."
logger "$NAME" >> ${COMPLETEDFILE}
# eject disc
ejectdisc
# move ISO
logger "INFO: Moving ISO..."
mv ${WORKDIR}/${NAME}.iso ${OUTPUTDIR}
logger "INFO: ISO moved..."
#wait for next disc
sleep $SLEEP
waitfordisc
}
# main process kick off
waitfordisc