-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetschunks
More file actions
executable file
·61 lines (48 loc) · 1.35 KB
/
etschunks
File metadata and controls
executable file
·61 lines (48 loc) · 1.35 KB
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
#!/bin/bash
pathToTs=$1
# this assumes that the .m3u8 and .ts share the same filename
filename=$2
options=$3
keyFile="$pathToTs/enc.key"
ivFile="$pathToTs/enc.iv"
OPTION_COPY="-c"
FOLDER_NAME="eTS"
if [ -e $keyFile ]
then
echo "Using $keyFile as key file"
else
openssl rand 16 > $keyFile
fi
if [ -e $ivFile ]
then
echo "Using $ivFile as key file"
else
openssl rand 16 > $ivFile
fi
# Get the key & iv values in hex
encKey=$(hexdump -v -e '16/1 "%02x"' $keyFile)
iv=$(tail $ivFile)
# 1. push the TS folder temporarily
pushd $pathToTs
# 2. create a folder to put the encrypted chunks
mkdir $FOLDER_NAME
# 3. if a -c is passed in as part of the options copy the manifest and the key file to the eTS folder
if [ "$options" == "$OPTION_COPY" ]
then
# copy the manifest to the Encrypted
cp ${filename}.m3u8 eTS/${filename}.m3u8
cp enc.key eTS/enc.key
cp enc.iv eTS/enc.iv
fi
# get the number of chunks
tsCount=$(ls *.ts | wc -l)
# we need to decrement by one cos the chunks start w/ 0 and to make it usable for the for loop
((tsCount--))
i=0
for i in $(seq -f "%01g" 0 $tsCount); do
tsFile=$filename$i.ts
openssl aes-128-cbc -e -in $tsFile -out $FOLDER_NAME/$tsFile -nosalt -iv $iv -K $encKey
echo "encrypting [$i] $tsFile ... done"
done
# return to the previous working directory i.e the directory the command was called from
popd