Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/docker/install_script/stream.sh
1072 views
1
#!/bin/bash
2
set -e
3
4
# Function to check and install Docker
5
install_docker() {
6
if command -v docker &> /dev/null; then
7
echo "Docker is already installed."
8
docker_version=$(docker --version | awk '{print $3}')
9
echo "Docker version: $docker_version"
10
else
11
echo "Docker not found. Installing Docker..."
12
curl -fsSL https://get.docker.com -o get-docker.sh
13
sh get-docker.sh > /dev/null 2>&1
14
echo "Docker installed successfully."
15
fi
16
}
17
18
# Function to download Docker image
19
pull_docker_image() {
20
local image_name=$1
21
echo "Downloading image..."
22
docker pull $image_name > /dev/null 2>&1
23
echo "Image download complete."
24
}
25
26
# Identify the operating system
27
lsb_dist=$(uname -s)
28
architecture=$(uname -m)
29
path_stream=$(pwd)
30
31
echo "Operating System: $lsb_dist"
32
echo "Architecture: $architecture"
33
34
# Install Docker if needed
35
install_docker
36
37
# Function to get the value of the argument
38
get_value() {
39
echo "$1" | cut -d'=' -f2
40
}
41
42
# Default variables
43
plate_recognizer_token=""
44
license_key=""
45
46
# Process command line arguments
47
for arg in "$@"; do
48
case "$arg" in
49
-t=*|--token=*)
50
plate_recognizer_token="$(get_value "$arg")"
51
;;
52
-l=*|--license_key=*)
53
license_key="$(get_value "$arg")"
54
;;
55
esac
56
done
57
58
# Prompt for values if not provided as arguments
59
if [ -z "$plate_recognizer_token" ]; then
60
read -p "Enter your Plate Recognizer API token: " plate_recognizer_token
61
fi
62
63
if [ -z "$license_key" ]; then
64
read -p "Enter your license key: " license_key
65
fi
66
67
echo "Token: $plate_recognizer_token"
68
echo "License Key: $license_key"
69
70
container_name="stream"
71
72
# Create the folder instead if doesn't exist yet to prevent permission issues
73
mkdir -p "$container_name"
74
75
# Set permissions for the current user
76
chmod 700 "$container_name"
77
78
# Check if the container exists, and if so, stop and remove it
79
if docker ps -a --format "{{.Names}}" | grep -q "$container_name"; then
80
echo "Stopping and removing existing container: $container_name"
81
docker stop "$container_name" > /dev/null 2>&1
82
docker rm "$container_name" > /dev/null 2>&1
83
fi
84
85
if [ "$architecture" == "x86_64" ]; then
86
pull_docker_image "platerecognizer/alpr-stream"
87
docker_command="docker run -t -d --restart="unless-stopped" --name stream -v $path_stream/stream:/user-data --user $(id -u):$(id -g) -e LICENSE_KEY=$license_key -e TOKEN=$plate_recognizer_token platerecognizer/alpr-stream"
88
89
elif [ "$architecture" == "armv7l" ] || [ "$architecture" == "aarch64" ] || [ "$architecture" == "armv7hf" ]; then
90
pull_docker_image "platerecognizer/alpr-stream:raspberry"
91
docker_command="docker run -t -d --restart="unless-stopped" --name stream -v $path_stream/stream:/user-data --user $(id -u):$(id -g) -e LICENSE_KEY=$license_key -e TOKEN=$plate_recognizer_token platerecognizer/alpr-stream:raspberry"
92
93
else
94
echo "Unsupported architecture: $architecture"
95
exit 1
96
fi
97
98
echo "Running Stream..."
99
$docker_command
100
101
102
echo "Stream is now up and running and will automatically start after boot."
103
104