Path: blob/master/docker/install_script/stream.sh
1072 views
#!/bin/bash1set -e23# Function to check and install Docker4install_docker() {5if command -v docker &> /dev/null; then6echo "Docker is already installed."7docker_version=$(docker --version | awk '{print $3}')8echo "Docker version: $docker_version"9else10echo "Docker not found. Installing Docker..."11curl -fsSL https://get.docker.com -o get-docker.sh12sh get-docker.sh > /dev/null 2>&113echo "Docker installed successfully."14fi15}1617# Function to download Docker image18pull_docker_image() {19local image_name=$120echo "Downloading image..."21docker pull $image_name > /dev/null 2>&122echo "Image download complete."23}2425# Identify the operating system26lsb_dist=$(uname -s)27architecture=$(uname -m)28path_stream=$(pwd)2930echo "Operating System: $lsb_dist"31echo "Architecture: $architecture"3233# Install Docker if needed34install_docker3536# Function to get the value of the argument37get_value() {38echo "$1" | cut -d'=' -f239}4041# Default variables42plate_recognizer_token=""43license_key=""4445# Process command line arguments46for arg in "$@"; do47case "$arg" in48-t=*|--token=*)49plate_recognizer_token="$(get_value "$arg")"50;;51-l=*|--license_key=*)52license_key="$(get_value "$arg")"53;;54esac55done5657# Prompt for values if not provided as arguments58if [ -z "$plate_recognizer_token" ]; then59read -p "Enter your Plate Recognizer API token: " plate_recognizer_token60fi6162if [ -z "$license_key" ]; then63read -p "Enter your license key: " license_key64fi6566echo "Token: $plate_recognizer_token"67echo "License Key: $license_key"6869container_name="stream"7071# Create the folder instead if doesn't exist yet to prevent permission issues72mkdir -p "$container_name"7374# Set permissions for the current user75chmod 700 "$container_name"7677# Check if the container exists, and if so, stop and remove it78if docker ps -a --format "{{.Names}}" | grep -q "$container_name"; then79echo "Stopping and removing existing container: $container_name"80docker stop "$container_name" > /dev/null 2>&181docker rm "$container_name" > /dev/null 2>&182fi8384if [ "$architecture" == "x86_64" ]; then85pull_docker_image "platerecognizer/alpr-stream"86docker_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"8788elif [ "$architecture" == "armv7l" ] || [ "$architecture" == "aarch64" ] || [ "$architecture" == "armv7hf" ]; then89pull_docker_image "platerecognizer/alpr-stream:raspberry"90docker_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"9192else93echo "Unsupported architecture: $architecture"94exit 195fi9697echo "Running Stream..."98$docker_command99100101echo "Stream is now up and running and will automatically start after boot."102103104