install.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. sudo rm -rf /root/car/
  2. sudo systemctl stop car.service
  3. sudo rm /lib/systemd/system/car.service
  4. sudo mkdir /root/car/
  5. echo "下载安装包..."
  6. if sudo wget -O /root/car/car.zip https://cloud.caner.top/api/v3/file/get/4667/car.zip?sign=LHXY5OdRwtfqu7EaGYMC95DgKlPygn7S3VwScqG4vUs%3D%3A0; then
  7. echo ''
  8. else
  9. echo '下载失败,请重试!'
  10. exit
  11. fi
  12. if unzip -o /root/car/car.zip -d /root/car/;then
  13. rm /root/car/car.zip
  14. sudo chmod 744 /root/car/index.js
  15. sudo chmod 744 /root/car/lib/node
  16. echo ''
  17. else
  18. echo '解压失败!'
  19. exit
  20. fi
  21. echo '更换国内镜像'
  22. if echo "deb https://mirror.nju.edu.cn/debian/ bullseye main contrib non-free
  23. deb https://mirror.nju.edu.cn/debian-security/ bullseye-security main contrib non-free
  24. deb https://mirror.nju.edu.cn/debian bullseye-updates main contrib non-free
  25. " >> /etc/apt/sources.list;then
  26. echo ''
  27. else
  28. echo '更换失败,请手动更换!'
  29. exit
  30. fi
  31. if echo "deb https://mirror.nju.edu.cn/raspberrypi/debian/ bullseye main" >> /etc/apt/sources.list.d/raspi.list;then
  32. echo ''
  33. else
  34. echo '更换失败,请手动更换!'
  35. exit
  36. fi
  37. echo '更新镜像'
  38. if apt update && upgrade;then
  39. echo ''
  40. else
  41. echo '更新失败!'
  42. exit
  43. fi
  44. echo '开始安装gstreamer 依赖...'
  45. if sudo apt-get install libx264-dev libjpeg-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-pulseaudio -y;then
  46. echo 'gstreamer 安装成功'
  47. else
  48. echo 'gstreamer 安装失败,请重试!'
  49. exit
  50. fi
  51. read -p "输入车端socket地址(ws://ip:port):" URL
  52. URL=${URL:-URL}
  53. if [ ! -n "$URL" ] ;then
  54. echo "请输入车端socket地址"
  55. exit
  56. else
  57. echo "遥控端地址:$URL"
  58. fi
  59. if echo "[Unit]
  60. Description=Car-server
  61. After=network.target
  62. [Service]
  63. Type=simple
  64. User=root
  65. ExecStart=/root/car/lib/node /root/car/index.js $URL &
  66. Restart=always
  67. RestartSec=3s
  68. [Install]
  69. WantedBy=multi-user.target" >> /lib/systemd/system/car.service;then
  70. echo ''
  71. else
  72. echo '自动设置开机启动失败,请稍后手动添加!'
  73. exit
  74. fi
  75. sudo systemctl daemon-reload
  76. if sudo systemctl enable car.service;then
  77. echo ''
  78. else
  79. echo '开机添加失败,请重试!'
  80. exit
  81. fi
  82. if sudo systemctl start car.service;then
  83. echo '车端服务启动成功!'
  84. else
  85. echo '车端服务启动失败,请重试!'
  86. exit
  87. fi
  88. exit