-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases
290 lines (238 loc) · 6.84 KB
/
.bash_aliases
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# https://www.raspberrypi.com/documentation/accessories/camera.html
pathmunge () {
if ! echo "$PATH" | grep -Eq "(^|:)$1($|:)"; then
if [ "$2" = "after" ] ; then
PATH="$PATH:$1"
else
PATH="$1:$PATH"
fi
fi
}
# Setup
## Make directories for HLS and Dash (used in apache2 for the camera output)
mkdir -p /dev/shm/hls
if [ ! /var/www/html/hls ] ; then
ln -s /dev/shm/hls /var/www/html/hls
fi
mkdir -p /dev/shm/dash
# Sys
alias sys="uname -a"
alias listservices="sudo systemctl list-unit-files"
alias rconfig="sudo raspi-config"
alias update="sudo apt update"
alias upgrade="sudo apt full-upgrade"
alias upclean="sudo apt clean"
alias uprem="sudo apt autoremove"
alias listusb="lsusb"
alias listvideo="ls /dev/video*"
alias record="libcamera-vid -t 0 --width 1080 --height 720 --shutter 120 --framerate 30 -q 100 -n --inline --listen -o tcp://0.0.0.0:8888 -v"
alias recordd="libcamera-vid -t 0 --width 1080 --height 720 -q 100 -n --inline --listen -o tcp://0.0.0.0:8888 -v &"
alias play="ffplay tcp://0.0.0.0:8888 -vf \"setpts=N/30\" -fflags nobuffer -flags low_delay -framedrop"
alias driverinfo="v4l2-ctl -d /dev/video0 --all"
alias listdevices="v4l2-ctl --list-devices"
alias supportedformats="v4l2-ctl --list-formats"
alias listencoders="ffmpeg -hide_banner -encoders | grep -E \"h264|mjpeg\""
alias listallencoders="ffmpeg -encoders"
alias listsupportedformats="ffmpeg -h encoder=h264_omx"
alias listcodecs="ffmpeg -codecs"
alias listh264="ffmpeg -codecs | grep -E \"h264\""
alias restart="sudo reboot"
alias reload="source ~/.profile"
alias c="clear"
alias installneovim="sudo apt-get install neovim" # is an older version, use snap (see further down)
alias installcurl="sudo apt install curl"
alias vi="nvim"
# RVM
alias installrvm="\curl -sSL https://get.rvm.io | bash -s stable --ruby"
# list aliases
alias commands="grep -in --color -e '^alias\s+*' ~/.bash_aliases | sed 's/alias //' | grep --color -e ':[a-z][a-z0-9]*'"
alias installsnap="sudo apt install snapd"
alias installngrok="sudo snap install ngrok"
alias installnewerneovim="sudo snap install --classic nvim"
alias installnvchad="git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1
nvim +'hi NormalFloat guibg=#1e222a' +PackerSync"
installNvchad () {
if [ ! -d /snap/bin ] ; then
installsnap
echo "pathmunge \"/snap/bin\"" >> ~/.bash_aliases
fi
if [ ! -d /home/pi/.config/nvim ] ; then
installnewerneovim
installnvchad
echo "alias vi=\"nvim\"" >> ~/.bash_aliases
fi
reload
}
# Nerd fonts
installNerdFonts () {
mkdir -p ~/Development
cd ~/Development
if [ ! -d "./nerd-fonts" ] ; then
git clone --depth 1 https://github.com/ryanoasis/nerd-fonts.git
fi
cd nerd-fonts
./install.sh SpaceMono
}
# Writes to output.mp4 from the libcamera-vid stream (record alias)
fftest () {
ffmpeg -y \
-input_format h264 \
-i tcp://0.0.0.0:8888 \
-c: copy \
output.mp4
}
# HLS output
ffhls () {
ffmpeg -y \
-i tcp://0.0.0.0:8888 \
-c: copy \
-f hls \
-hls_time 1 \
-hls_list_size 0 \
-hls_delete_threshold 2 \
/dev/shm/hls/live.m3u8
}
alias serve="ffhls"
# Dash output
ffdash () {
ffmpeg \
-i tcp://0.0.0.0:8888 \
-c:v copy \
-f dash \
-seg_duration 1 \vcgencmd get_camera
-streaming 1 \
-window_size 30 -remove_at_exit 1 \
/dev/shm/dash/live.mpd
}
writeToHlsFile () {
cat << EOF > $1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Live Stream</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<video id="video" controls autoplay></video>
<script>
var video = document.getElementById("video");
var videoSrc = "hls/live.m3u8";
// First check for native browser HLS support
if (video.canPlayType("application/vnd.apple.mpegurl")) {
video.src = videoSrc;
}
// If no native HLS support, check if hls.js is supported
else if (Hls.isSupported()) {
var hls = new Hls();
hls.loadSource(videoSrc);
hls.attachMedia(video);
}
</script>
</body>
</html>
EOF
}
setHlsFiles () {
sudo chown pi:pi /var/www/html
touch /var/www/html/hls.html
chown pi:pi /var/www/html/hls.html
writeToHlsFile /var/www/html/hls.html
}
writeToRecordFile () {
sudo cat << EOF > $1
[Unit]
Description=Start the record alias on startup
After=multi-user.target
[Service]
ExecStart=/usr/bin/bash /home/pi/Development/record.sh
User=pi
[Install]
WantedBy=multi-user.target
EOF
}
# NOT WORKING
# /bin/sleep 5 && ~/Development/serve
writeToServeFile () {
sudo cat << EOF > $1
[Unit]
Description=Serve the record command up over http
After=multi-user.target
[Service]
ExecStart=/usr/bin/bash /home/pi/Development/serve.sh
User=pi
[Install]
WantedBy=multi-user.target
EOF
}
writeToRecord () {
cat << EOF > $1
#!/bin/bash
shopt -s expand_aliases
source ~/.bash_aliases
record
EOF
}
writeToServe () {
cat << EOF > $1
#!/bin/bash
shopt -s expand_aliases
source ~/.bash_aliases
sudo touch ~/Development/serving.log
/bin/sleep 10 && ffhls
EOF
}
setStartup () {
sudo touch ~/Development/record.sh
writeToRecord ~/Development/record.sh
sudo touch ~/Development/serve.sh
writeToServe ~/Development/serve.sh
sudo touch /lib/systemd/system/startup-record.service
sudo chown pi:pi /lib/systemd/system/startup-record.service
writeToRecordFile /lib/systemd/system/startup-record.service
sudo chown root:root /lib/systemd/system/startup-record.service
sudo touch /lib/systemd/system/startup-serve.service
sudo chown pi:pi /lib/systemd/system/startup-serve.service
writeToServeFile /lib/systemd/system/startup-serve.service
sudo chown root:root /lib/systemd/system/startup-serve.service
sudo systemctl daemon-reload
sudo systemctl enable startup-record.service
sudo systemctl enable startup-serve.service
}
postImageSetup () {
update
upgrade
# Install ffmpeg
sudo apt install -y ffmpeg
# Install Apache
sudo apt install -y apache2
setHlsFiles
setStartup
# Install curl
installcurl
# Install RVM
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
installrvm
# Install NvChad
installNvchad
# Install Nerd Fonts
installNerdFonts
}
# sudo mv /var/www/html/hls.html /var/www/html/index.html <- maybe add to post setup,
pathmunge /snap/bin
pathmunge ~/.rvm/bin
# De-dupe path and enforce order
if [ -n "$PATH" ]; then
old_PATH=$PATH:; PATH=/home/pi/.rvm/gems/ruby-3.0.0/bin
while [ -n "$old_PATH" ]; do
x=${old_PATH%%:*} # the first remaining entry
case $PATH: in
*:"$x":*) ;; # already there
*) PATH=$PATH:$x;; # not there yet
esac
old_PATH=${old_PATH#*:}
done
PATH=${PATH#:}
unset old_PATH x
fi