Added comments, updated TODO

This commit is contained in:
Logan G 2020-08-14 22:29:17 -06:00
parent 7b769e7ade
commit 2fb67941f5
Signed by: logan
GPG key ID: E328528C921E7A7A
9 changed files with 56 additions and 12 deletions

View file

@ -13,3 +13,4 @@
## Things to consider ## Things to consider
- Wayland using labwc/waybox - Wayland using labwc/waybox
- Python 3

View file

@ -1,12 +1,29 @@
#!/bin/bash #!/bin/bash
# Grabs the port (and IP) out of the nginx config
LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}') LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}')
if [[ -f ~/.overrideurl.sh ]]; then source ./.overrideurl.sh; fi # If the value we just grabbed doesn't contain an IP, prepend localhost
if ! echo $LISTEN | grep ":" 2>&1; then
ADDRESS="localhost:$LISTEN"
else
ADDRESS=$LISTEN
fi
# Override the automatically detected address if the user wants to
if [[ -f ~/.overrideurl.sh ]]; then source ~/.overrideurl.sh; fi
# Wait until OctoPrint comes up # Wait until OctoPrint comes up
while ! curl "$LISTEN" 2>&1 >/dev/null; do while ! curl "$ADDRESS" 2>&1 >/dev/null; do
sleep 1 sleep 1
done done
surf -d -F -g -K -n -p "$LISTEN" ######
## Opens browser
# -d | Disable disk caching
# -F | Fullscreen
# -g | Disable giving away geolocation
# -K | Enable kiosk mode (doesn't seem to do anything?)
# -n | Disable web inspector
# -p | Disable plugins
surf -d -F -g -K -n -p "$ADDRESS"

View file

@ -6,15 +6,18 @@ install -m 644 files/nginx.conf ${ROOTFS_DIR}/etc/nginx/nginx.conf
echo -e "listen 80;" > ${ROOTFS_DIR}/etc/nginx/listen.conf echo -e "listen 80;" > ${ROOTFS_DIR}/etc/nginx/listen.conf
on_chroot << EOF on_chroot << EOF
systemctl enable nginx # If OctoPrint already exists, skip this (for debugging)
if ! pip list | grep -F octoprint; then if [[ ! -f /srv/octoprint/venv/bin/octoprint ]]; then
if [[ ! -d /srv/octoprint ]]; then mkdir -p /srv/octoprint; fi if [[ ! -d /srv/octoprint ]]; then mkdir -p /srv/octoprint; fi
cd /srv/octoprint || exit 1 cd /srv/octoprint || exit 1
chown octoprint:octoprint /srv/octoprint || exit 1 # https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspbian/2337/
virtualenv venv || exit 1 virtualenv venv || exit 1
source venv/bin/activate || exit 1 source venv/bin/activate || exit 1
pip install pip --upgrade pip install pip --upgrade
pip install octoprint || exit 1 pip install octoprint || exit 1
# Fix permissions
chown -R octoprint:octoprint /srv/octoprint chown -R octoprint:octoprint /srv/octoprint
fi fi
# Enable the reverse proxy
systemctl enable nginx
EOF EOF

View file

@ -4,14 +4,17 @@ install -m 644 files/mjpg-streamer.service ${ROOTFS_DIR}/etc/systemd/system/mjpg
install -m 755 files/start-mjpg ${ROOTFS_DIR}/usr/local/bin/start-mjpg install -m 755 files/start-mjpg ${ROOTFS_DIR}/usr/local/bin/start-mjpg
on_chroot << EOF on_chroot << EOF
# If mjpg is already installed, skip this (for debugging)
if ! which mjpg_streamer; then if ! which mjpg_streamer; then
cd /tmp cd /tmp
# Making sure that this directory doesn't exist
rm -rf /tmp/mjpg-streamer rm -rf /tmp/mjpg-streamer
git clone https://github.com/jacksonliam/mjpg-streamer/ git clone https://github.com/jacksonliam/mjpg-streamer/
cd mjpg-streamer/mjpg-streamer-experimental/ cd mjpg-streamer/mjpg-streamer-experimental/
make make
make install make install
cd / cd /
# Cleanup
rm -rf /tmp/mjpg-streamer rm -rf /tmp/mjpg-streamer
fi fi
EOF EOF

View file

@ -5,6 +5,7 @@ install -m 755 files/octo-config "${ROOTFS_DIR}/usr/local/bin/octo-config"
install -m 755 files/first-time.sh "${ROOTFS_DIR}/etc/profile.d/first-time.sh" install -m 755 files/first-time.sh "${ROOTFS_DIR}/etc/profile.d/first-time.sh"
install -m 755 files/octo-lib.sh "${ROOTFS_DIR}/usr/local/lib/octo-lib.sh" install -m 755 files/octo-lib.sh "${ROOTFS_DIR}/usr/local/lib/octo-lib.sh"
# Autologin on first boot
mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/ mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/
cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF' cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
[Service] [Service]
@ -12,6 +13,7 @@ ExecStart=
ExecStart=-/usr/sbin/agetty --autologin root --noclear %I $TERM ExecStart=-/usr/sbin/agetty --autologin root --noclear %I $TERM
EOF EOF
# Don't boot to a GUI
on_chroot << EOF on_chroot << EOF
systemctl set-default multi-user.target systemctl set-default multi-user.target
EOF EOF

View file

@ -1,17 +1,18 @@
#!/bin/bash #!/bin/bash
# This should never happen, no harm in checking though ;)
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
echo "This image has not been configured properly. Please complain to Logan" echo "This image has not been configured properly. Please complain to Logan"
bash bash
exit 1 exit 1
fi fi
# Import common functions
source /usr/local/lib/octo-lib.sh source /usr/local/lib/octo-lib.sh
install_package () { install_package () {
echo "==========Installing $1==========" >>/home/pi/install.log echo "==========Installing $1==========" >>/home/pi/install.log
cd /srv/octoprint/ || return 1 source /srv/octoprint/venv/bin/activate || return 1
source venv/bin/activate || return 1
pip install $1 2>&1 >>/home/pi/install.log || return 1 pip install $1 2>&1 >>/home/pi/install.log || return 1
} }
@ -64,29 +65,36 @@ suggested_menu () {
} }
dialog --title "NOTICE" --nocancel --colors --msgbox "This collection of software is currently in alpha. It is lacking several critical features. \Zb\Z1DO NOT\Zn use this in a production environment. This image has been provided for testing purposes only." 10 50 dialog --title "NOTICE" --nocancel --colors --msgbox "This collection of software is currently in alpha. It is lacking several critical features. \Zb\Z1DO NOT\Zn use this in a production environment. This image has been provided for testing purposes only." 10 50
change_password || return 1
# Force the user to change the pi user's password before the RPi gets botnetted
change_password
dialog --title "Network Configuration" --nocancel --msgbox "Setup will now open nmtui, a program to help configure your ethernet/wireless interfaces. Hit Quit when you are done." 10 50 dialog --title "Network Configuration" --nocancel --msgbox "Setup will now open nmtui, a program to help configure your ethernet/wireless interfaces. Hit Quit when you are done." 10 50
nmtui nmtui
service_select || return 1 # Enable/disable OctoPrint, GUI, MJPG and SSH
service_select
screen_timeout || return 1 screen_timeout
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "OctoPrint Config" --yesno "Do you wish to change the default OctoPrint listening address and/or port?" 10 60; then # If OctoPrint is running locally, ask if the user wants to change the default listening port/IP (optional)
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "Nginx Config" --yesno "Do you wish to change the default OctoPrint listening address and/or port?" 10 60; then
nginx_config nginx_config
fi fi
# If MJPG service is enabled, ask user which video device to use
if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then
video_config video_config
fi fi
# If OctoPrint is running locally, ask if user wants to preinstall recommended plugins
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then
recommended_menu || return 1 recommended_menu || return 1
suggested_menu || return 1 suggested_menu || return 1
chown -R octoprint:octoprint /srv/octoprint chown -R octoprint:octoprint /srv/octoprint
fi fi
# Delete the autologin override and first-time setup utility
rm /etc/systemd/system/getty@tty1.service.d/override.conf rm /etc/systemd/system/getty@tty1.service.d/override.conf
rm /etc/profile.d/first-time.sh rm /etc/profile.d/first-time.sh
reboot reboot

View file

@ -5,6 +5,7 @@ if [ "$EUID" -ne 0 ]; then
exit 1 exit 1
fi fi
# Import shared functions
source /usr/local/lib/octo-lib.sh source /usr/local/lib/octo-lib.sh
main_menu () { main_menu () {

View file

@ -1,6 +1,8 @@
change_password () { change_password () {
local PASSWORD="$(dialog --title "Change Password" --nocancel --insecure --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" local PASSWORD="$(dialog --title "Change Password" --nocancel --insecure --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)"
# If the password field was left blank, exit
if [[ $? -ne 0 ]] || [[ $PASSWORD == "" ]]; then return 1; fi if [[ $? -ne 0 ]] || [[ $PASSWORD == "" ]]; then return 1; fi
# If the password is raspberry, tell the user he is an idiot
if [[ "$PASSWORD" == "raspberry" ]]; then if [[ "$PASSWORD" == "raspberry" ]]; then
dialog --title "Change Password" --nocancel --msgbox "That password sucks. Please use a different one :)" 10 50 dialog --title "Change Password" --nocancel --msgbox "That password sucks. Please use a different one :)" 10 50
change_password change_password
@ -18,6 +20,7 @@ change_password () {
} }
service_select () { service_select () {
# Toggle the checkboxes if the service is active or not
local SERVICE_MENU=$(dialog --separate-output --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \ local SERVICE_MENU=$(dialog --separate-output --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \
"1" "OctoPrint" $(if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "ON"; else echo "OFF"; fi) \ "1" "OctoPrint" $(if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "ON"; else echo "OFF"; fi) \
"2" "MJPG-Streamer" $(if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "ON"; else echo "OFF"; fi) \ "2" "MJPG-Streamer" $(if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "ON"; else echo "OFF"; fi) \
@ -97,6 +100,7 @@ EOF
nginx_config () { nginx_config () {
local LISTEN="" local LISTEN=""
# Grab the variable from the nginx conf if it exists, otherwise use default
if [[ -f /etc/nginx/listen.conf ]]; then if [[ -f /etc/nginx/listen.conf ]]; then
LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}') LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}')
else else
@ -105,14 +109,17 @@ nginx_config () {
LISTEN=$(dialog --title "Nginx Config" --nocancel --inputbox "Configure what port and IP Nginx should listen on.\nTo listen on all IPs, just enter the port.\nDefault: 80" 11 50 "$LISTEN" 3>&1 1>&2 2>&3) LISTEN=$(dialog --title "Nginx Config" --nocancel --inputbox "Configure what port and IP Nginx should listen on.\nTo listen on all IPs, just enter the port.\nDefault: 80" 11 50 "$LISTEN" 3>&1 1>&2 2>&3)
# Write new value to nginx
echo "listen $LISTEN;" > /etc/nginx/listen.conf echo "listen $LISTEN;" > /etc/nginx/listen.conf
} }
video_config () { video_config () {
# Grab all video devices
local DEVICES=($(ls /dev/video*)) local DEVICES=($(ls /dev/video*))
local DEVICELIST="" local DEVICELIST=""
# Generate a menu from said video devices
for ((i = 0; i < ${#DEVICES[@]}; i++)); do for ((i = 0; i < ${#DEVICES[@]}; i++)); do
DEVICELIST+="${DEVICES[$i]} $i OFF " DEVICELIST+="${DEVICES[$i]} $i OFF "
done done
@ -121,5 +128,6 @@ video_config () {
[[ "$DEVICE_MENU" == "" ]] && return 0 [[ "$DEVICE_MENU" == "" ]] && return 0
# Write selected value to startup script
echo -e '#!/bin/bash'"\n/usr/local/bin/mjpg_streamer -i \"input_uvc.so -d $DEVICE_MENU\" -o \"output_http.so --port 8080\"" > /usr/local/bin/start-mjpg echo -e '#!/bin/bash'"\n/usr/local/bin/mjpg_streamer -i \"input_uvc.so -d $DEVICE_MENU\" -o \"output_http.so --port 8080\"" > /usr/local/bin/start-mjpg
} }

View file

@ -37,6 +37,7 @@ NODM_MIN_SESSION_TIME=60
NODM_X_TIMEOUT=300 NODM_X_TIMEOUT=300
EOF EOF
# Probably not needed
on_chroot << EOF on_chroot << EOF
update-alternatives --install /usr/bin/x-www-browser \ update-alternatives --install /usr/bin/x-www-browser \
x-www-browser /usr/bin/surf 86 x-www-browser /usr/bin/surf 86