300 lines
9.9 KiB
Bash
Executable File
300 lines
9.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
user_groups() {
|
|
|
|
echo 'Adding current user to dialout and video groups.'
|
|
usermod -a -G dialout,video $user
|
|
|
|
if [ $INSTALL -eq 4 ]; then
|
|
usermod -a -G uucp,video $user
|
|
fi
|
|
}
|
|
|
|
prepare () {
|
|
echo "Checking if Docker is installed....."
|
|
if command_exists docker; then
|
|
echo "Docker found at `which docker`"
|
|
else
|
|
echo "Docker not found, will install."
|
|
DOCKERINSTALL=1
|
|
fi
|
|
|
|
echo
|
|
echo
|
|
|
|
PS3="${green}Installation type: ${white}"
|
|
local options=("Ubuntu 20+, Mint, Debian, Raspberry Pi OS" "Fedora/CentOS" "ArchLinux" "openSUSE" "Quit")
|
|
select opt in "${options[@]}"
|
|
do
|
|
case $opt in
|
|
"Ubuntu 20+, Mint, Debian, Raspberry Pi OS")
|
|
INSTALL=2
|
|
break
|
|
;;
|
|
"Fedora/CentOS")
|
|
INSTALL=3
|
|
break
|
|
;;
|
|
"ArchLinux")
|
|
INSTALL=4
|
|
break
|
|
;;
|
|
"openSUSE")
|
|
INSTALL=5
|
|
break
|
|
;;
|
|
"Quit")
|
|
exit 1
|
|
;;
|
|
*) echo "invalid option $REPLY";;
|
|
esac
|
|
done
|
|
|
|
if prompt_confirm "Ready to begin?"; then
|
|
install
|
|
fi
|
|
main_menu
|
|
}
|
|
|
|
install() {
|
|
user_groups
|
|
OCTOEXEC=/usr/local/bin/octoprint
|
|
echo "Adding systemctl and reboot to sudo"
|
|
echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl
|
|
echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot
|
|
echo "This will install necessary packages, install OctoPrint and setup an instance."
|
|
|
|
#SELinux
|
|
if command_exists getenforce && [ "$(getenforce)" == "Enforcing" ]; then
|
|
echo "SELinux is enabled"
|
|
echo "This causes a fair bit of trouble for running OctoPrint."
|
|
echo "You have the option of disabling this now."
|
|
if prompt_confirm "${green}Disable SELinux?${white}"; then
|
|
sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config
|
|
echo "${magenta}You will need to reboot after system preparation.${white}"
|
|
fi
|
|
fi
|
|
if [ -n "$DOCKERINSTALL" ]; then
|
|
curl -sL https://get.docker.com | sh
|
|
fi
|
|
|
|
echo "Enabling ssh server..."
|
|
systemctl enable ssh.service
|
|
|
|
haproxy_install
|
|
streamer_install
|
|
|
|
#These will retreived as settings
|
|
echo "octoexec: /usr/local/bin/octoprint" >> /etc/octodocker_deploy
|
|
echo "octopip: /usr/local/bin/pip" >> /etc/octodocker_deploy
|
|
|
|
#Create first instance
|
|
echo
|
|
echo
|
|
echo
|
|
echo
|
|
echo "${cyan}It is time to create your first OctoPrint instance!!!${white}"
|
|
new_instance true
|
|
echo
|
|
echo
|
|
if prompt_confirm "Would you like to install recommended plugins now?"; then
|
|
plugin_menu
|
|
fi
|
|
|
|
}
|
|
|
|
haproxy_install() {
|
|
|
|
echo
|
|
echo
|
|
echo 'You have the option of setting up haproxy.'
|
|
echo 'This binds instances to a name on port 80 instead of having to type the port.'
|
|
echo
|
|
echo
|
|
if prompt_confirm "Use haproxy?"; then
|
|
echo 'haproxy: true' >> /etc/octodocker_deploy
|
|
#Check if using improved haproxy rules
|
|
#echo 'haproxynew: true' >> /etc/octodocker_deploy
|
|
systemctl stop haproxy
|
|
#get haproxy version
|
|
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
|
|
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.orig
|
|
if [ $HAversion -gt 1 ]; then
|
|
cp $SCRIPTDIR/haproxy2x.basic /etc/haproxy/haproxy.cfg
|
|
else
|
|
cp $SCRIPTDIR/haproxy1x.basic /etc/haproxy/haproxy.cfg
|
|
fi
|
|
systemctl start haproxy
|
|
systemctl enable haproxy
|
|
else
|
|
systemctl stop haproxy
|
|
systemctl disable haproxy
|
|
fi
|
|
|
|
echo
|
|
echo
|
|
echo
|
|
}
|
|
|
|
streamer_install() {
|
|
PS3="${green}Which video streamer you would like to install?: ${white}"
|
|
options=("ustreamer (recommended)" "camera-streamer" "None/Skip")
|
|
select opt in "${options[@]}"
|
|
do
|
|
case $opt in
|
|
"mjpeg-streamer")
|
|
VID=1
|
|
break
|
|
;;
|
|
"ustreamer (recommended)")
|
|
VID=2
|
|
break
|
|
;;
|
|
"camera-streamer")
|
|
VID=4
|
|
break
|
|
;;
|
|
"None/Skip")
|
|
VID=3
|
|
break
|
|
;;
|
|
*) echo "invalid option $REPLY";;
|
|
esac
|
|
done
|
|
|
|
#If we run this function directly, clean up streamer setting before installing
|
|
get_settings
|
|
sed -i "/streamer/d" /etc/octodocker_deploy
|
|
|
|
if [ $VID -eq 1 ]; then
|
|
rm -rf /opt/octoprint/mjpg_streamer 2>/dev/null
|
|
#install mjpg-streamer, not doing any error checking or anything
|
|
echo 'Installing mjpeg-streamer'
|
|
git -C /opt/octoprint/ clone https://github.com/jacksonliam/mjpg-streamer.git mjpeg
|
|
#apt -y install
|
|
make -C /opt/octoprint/mjpeg/mjpg-streamer-experimental > /dev/null
|
|
|
|
mv /opt/octoprint/mjpeg/mjpg-streamer-experimental /opt/octoprint/mjpg-streamer
|
|
rm -rf /opt/octoprint/mjpeg
|
|
if [ -f "/opt/octoprint/mjpg-streamer/mjpg_streamer" ]; then
|
|
echo "Streamer installed successfully"
|
|
else
|
|
echo "${red}WARNING! WARNING! WARNING!${white}"
|
|
echo "Streamer has not been installed correctly."
|
|
if prompt_confirm "Try installation again?"; then
|
|
streamer_install
|
|
fi
|
|
fi
|
|
echo 'streamer: mjpg-streamer' >> /etc/octodocker_deploy
|
|
fi
|
|
|
|
if [ $VID -eq 2 ]; then
|
|
rm -rf /opt/octoprint/ustreamer 2>/dev/null
|
|
#install ustreamer
|
|
git -C /opt/octoprint clone --depth=1 https://github.com/pikvm/ustreamer
|
|
make -C /opt/octoprint/ustreamer > /dev/null
|
|
if [ -f "/opt/octoprint/ustreamer/ustreamer" ] || [ -f "/opt/octoprint/ustreamer/ustreamer.bin" ]; then
|
|
echo "Streamer installed successfully"
|
|
else
|
|
echo "${red}WARNING! WARNING! WARNING!${white}"
|
|
echo "Streamer has not been installed correctly."
|
|
if prompt_confirm "Try installation again?"; then
|
|
streamer_install
|
|
fi
|
|
fi
|
|
if [ -f "/opt/octoprint/ustreamer/ustreamer.bin" ]; then
|
|
ln -s /opt/octoprint/ustreamer/ustreamer.bin /opt/octoprint/ustreamer/ustreamer
|
|
fi
|
|
echo 'streamer: ustreamer' >> /etc/octodocker_deploy
|
|
fi
|
|
|
|
if [ $VID -eq 4 ]; then
|
|
rm -rf /opt/octoprint/camera-streamer 2>/dev/null
|
|
#install camera-streamer
|
|
git -C /opt/octoprint clone https://github.com/ayufan-research/camera-streamer.git --recursive
|
|
make -C /opt/octoprint/camera-streamer > /dev/null
|
|
if [ -f "/opt/octoprint/camera-streamer/camera-streamer" ]; then
|
|
echo "Streamer installed successfully"
|
|
else
|
|
echo "${red}WARNING! WARNING! WARNING!${white}"
|
|
echo "Streamer has not been installed correctly."
|
|
if prompt_confirm "Try installation again?"; then
|
|
streamer_install
|
|
fi
|
|
fi
|
|
echo 'streamer: camera-streamer' >> /etc/octodocker_deploy
|
|
fi
|
|
|
|
if [ $VID -eq 3 ]; then
|
|
echo 'streamer: none' >> /etc/octodocker_deploy
|
|
echo "Good for you! Cameras are just annoying anyway."
|
|
fi
|
|
|
|
}
|
|
|
|
firstrun_install() {
|
|
echo
|
|
echo
|
|
echo 'The first instance can be configured at this time.'
|
|
echo 'This includes setting up the admin user and finishing the startup wizards.'
|
|
echo
|
|
echo
|
|
if prompt_confirm "Do you want to setup your admin user now?"; then
|
|
while true; do
|
|
echo 'Enter admin user name (no spaces): '
|
|
read OCTOADMIN
|
|
if [ -z "$OCTOADMIN" ]; then
|
|
echo -e "No admin user given! Defaulting to: \033[0;31moctoadmin\033[0m"
|
|
OCTOADMIN=octoadmin
|
|
fi
|
|
if ! has-space "$OCTOADMIN"; then
|
|
break
|
|
else
|
|
echo "Admin user name must not have spaces."
|
|
fi
|
|
done
|
|
echo "Admin user: ${cyan}$OCTOADMIN${white}"
|
|
|
|
while true; do
|
|
echo 'Enter admin user password (no spaces): '
|
|
read OCTOPASS
|
|
if [ -z "$OCTOPASS" ]; then
|
|
echo -e "No password given! Defaulting to: ${cyan}fooselrulz${white}. Please CHANGE this."
|
|
OCTOPASS=fooselrulz
|
|
fi
|
|
|
|
if ! has-space "$OCTOPASS"; then
|
|
break
|
|
else
|
|
echo "Admin password cannot contain spaces"
|
|
fi
|
|
|
|
done
|
|
echo "Admin password: ${cyan}$OCTOPASS${white}"
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE user add $OCTOADMIN --password $OCTOPASS --admin
|
|
fi
|
|
|
|
if [ -n "$OCTOADMIN" ]; then
|
|
echo
|
|
echo
|
|
echo "The script can complete the first run wizards now."
|
|
echo "For more information on these, see the OctoPrint website."
|
|
echo "It is standard to accept this, as no identifying information is exposed through their usage."
|
|
echo
|
|
echo
|
|
if prompt_confirm "Complete first run wizards now?"; then
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.firstRun false --bool
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.seenWizards.backup null
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.seenWizards.corewizard 4 --int
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.onlineCheck.enabled true --bool
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set server.pluginBlacklist.enabled true --bool
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set plugins.tracking.enabled true --bool
|
|
docker exec -it $INSTANCE $OCTOEXEC --basedir $BASE config set printerProfiles.default _default
|
|
fi
|
|
fi
|
|
|
|
echo "Restarting instance....."
|
|
systemctl restart $INSTANCE
|
|
}
|
|
|