9

I would like to enable the raspberry pi camera without using raspi-config, as I need to do this in an automated bash script.

Anyone know how?

ended up pulling this out of raspi-config

#!/bin/bash

set_config_var() {
  lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
  if line:match("^#?%s*"..key.."=.*$") then
    line=key.."="..value
    made_change=true
  end
  print(line)
end

if not made_change then
  print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}




[ -e /boot/config.txt ] || touch /boot/config.txt

set_config_var start_x 1 /boot/config.txt
set_config_var gpu_mem 128 /boot/config.txt
sed /boot/config.txt -i -e "s/^startx/#startx/"
sed /boot/config.txt -i -e "s/^fixup_file/#fixup_file/"
Tom
  • 91
  • 1
  • 4

3 Answers3

3

Raspi-Config is pointing at /boot/config.txt where the string start_x=# is located in the bottom of the document. the "#" represent either a "0" or a "1". 0 = Camera disabled and 1 = Camera enabled.

I solved this by making a script as follows:

#!/bin/bash
grep "start_x=1" /boot/config.txt
if grep "start_x=1" /boot/config.txt
then
        exit
else
        sed -i "s/start_x=0/start_x=1/g" /boot/config.txt
        reboot
fi
exit

Don't forget to chmod the script so that you can execute it, and after that run script as root.

Diego
  • 1,259
  • 10
  • 14
2

Generally you can use lsmod command for listing kernel modules names and after that you can install module with insmod [module_name]. rmmod [module_name] command is for removing modules.

cagdas
  • 41
  • 3
2

Based on How could one automate the raspbian raspi-config setup? this should work:

sudo raspi-config nonint do_camera 0

(Also, it works for me.)

nmichaels
  • 121
  • 2