donovan6000 / M33-Fio

The ultimate OctoPrint plugin
GNU General Public License v3.0
125 stars 38 forks source link

Added an install-fedora.sh script for the Fedora operating system #166

Closed Enygma2002 closed 8 years ago

Enygma2002 commented 8 years ago

The changes include:

I`ve just made some time to share this install script. It took me many hours to find and adapt all the Debian/Ubuntu details to the Fedora operating system that I am running.

I am happily running and printing on Fedora, so I hope it will help others avoid the unnecessary trouble.

Enygma2002 commented 8 years ago

Hi @donovan6000. I hope it`s not too much of a bother to include my adapted script, with your retirement from the active development of the plugin and all...

For a quicker review (and anyone else interested, since the script is inside a zip), the content of the install-fedora.sh script is the following:

#!/bin/sh

#
# Fedora install script using Fedora specific dependency packages and the DNF package manager.
# Adapted by @Enygma2002
#

# Request elevated privileges
[ "$(whoami)" != "root" ] && exec sudo "$0" "$@"

# Check if not run as root
if [ "$(id -u)" != "0" ]; then

    # Display message
    echo
    echo 'Root privileges required.'
    echo

# Otherwise
else

    # Check if connected to the internet
    wget -q --tries=1 --timeout=5 --spider http://google.com
    if [ $? -eq 0 ]; then

        # Move to temporary location
        cd $(dirname $(mktemp -u))

        # Set if using OctoPi
        if [ -f /etc/init.d/octoprint ]; then
            usingOctoPi=true
        else
            usingOctoPi=false
        fi

        # Check if not using OctoPi
        if ! $usingOctoPi
        then

            # Install OctoPrint and M33 Fio dependencies
            dnf update
            dnf -y install python python-pip python-devel libyaml-devel make automake gcc gcc-c++ kernel-devel pygame libjpeg-turbo-devel zlib-devel
            sudo -u $SUDO_USER pip install regex --user
            sudo -u $SUDO_USER pip install pillow --user

            # Install OctoPrint
            killall -w octoprint
            wget https://github.com/foosel/OctoPrint/archive/master.zip
            sudo -u $SUDO_USER unzip master.zip
            cd OctoPrint-master
            sudo -u $SUDO_USER python setup.py install --user
            cd ..
            sudo -u $SUDO_USER mkdir -p '/home/'"$SUDO_USER"'/.octoprint'
            rm -rf '/home/'"$SUDO_USER"'/.octoprint/checkout'
            sudo -u $SUDO_USER mv OctoPrint-master '/home/'"$SUDO_USER"'/.octoprint/checkout'
            rm master.zip

            # Install M33 Fio
            echo 'y' | sudo -u $SUDO_USER pip uninstall OctoPrint-M33Fio
            wget https://github.com/donovan6000/M33-Fio/archive/master.zip
            while ! sudo -u $SUDO_USER pip install master.zip --user
            do
                :
            done
            rm master.zip

        # Otherwise
        else

            # Install M33 Fio
            echo 'y' | sudo -u pi /home/pi/oprint/bin/pip uninstall OctoPrint-M33Fio
            wget https://github.com/donovan6000/M33-Fio/archive/master.zip
            while ! sudo -u pi /home/pi/oprint/bin/pip install master.zip
            do
                :
            done
            rm master.zip
        fi

        # Apply printer udev rule
        wget -O /etc/udev/rules.d/90-micro-3d-local.rules https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/90-micro-3d-local.rules

        # Apply heatbed udev rule
        wget -O /etc/udev/rules.d/91-micro-3d-heatbed-local.rules https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/91-micro-3d-heatbed-local.rules

        # Reload udev rules to read the newly added rules
        udevadm control --reload-rules
        udevadm trigger --attr-match=subsystem=usb

        # Check if not using OctoPi
        if ! $usingOctoPi
        then

            # Add OctoPrint to list of startup commands
            # Remove the startup of any existing systemwide install since we will be using the new installation
            sed -i '/octoprint/d' /etc/rc.local
            # Note: use 'echo' for the case when rc.local is empty or does not exist
            echo 'sudo -u '"$SUDO_USER"' "/home/'"$SUDO_USER"'/.local/bin/octoprint"' >> /etc/rc.local
            echo >> /etc/rc.local
            # Make sure rc.local is executable (in case we have just created it)
            chmod +x /etc/rc.local

            # Create URL link on desktop
            wget https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/octoprint.png
            mv octoprint.png '/usr/share/icons'
            sudo -u $SUDO_USER wget https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/OctoPrint.desktop
            mv OctoPrint.desktop '/home/'"$SUDO_USER"'/Desktop'

            # Start OctoPrint
            rm -rf '/home/'"$SUDO_USER"'/.python-eggs'
            sudo -u $SUDO_USER nohup '/home/'"$SUDO_USER"'/.local/bin/octoprint' >/dev/null 2>&1 &

            # Display message
            echo 'OctoPrint and M33 Fio have been successfully installed. Go to http://localhost:5000 in any web browser to access OctoPrint.'
            echo

        # Otherwise
        else

            # Display message
            echo
            echo 'M33 Fio has been successfully installed.'
            echo
        fi

    # Otherwise
    else

        # Display message
        echo
        echo 'An internet connection is required.'
        echo
    fi
fi
donovan6000 commented 8 years ago

I like it! How about we combine the Debian and Fedora installers into one though, like this. It'll use the package manager based on the detected distro, and it'll create rc.local if it doesn't exist. I just tested it on a fresh install of Ubuntu 16.04 and it worked fine.

#!/bin/sh

# Request elevated privileges
[ "$(whoami)" != "root" ] && exec sudo "$0" "$@"

# Check if not run as root
if [ "$(id -u)" != "0" ]; then

    # Display message
    echo
    echo 'Root privileges required.'
    echo

# Otherwise
else

    # Check if connected to the internet
    wget -q --tries=1 --timeout=5 --spider http://google.com
    if [ $? -eq 0 ]; then

        # Move to temporary location
        cd $(dirname $(mktemp -u))

        # Set if using OctoPi
        if [ -f /etc/init.d/octoprint ]; then
            usingOctoPi=true
        else
            usingOctoPi=false
        fi

        # Check if not using OctoPi
        if ! $usingOctoPi
        then

            # Install OctoPrint and M33 Fio dependencies
            if [ -f /etc/debian_version ]; then
                apt-get update
                apt-get -y install python python-pip python-dev libyaml-dev build-essential python-pygame libjpeg-dev zlib1g-dev
            elif [ -f /etc/fedora-release ]; then
                dnf update
                dnf -y install python python-pip python-devel libyaml-devel make automake gcc gcc-c++ kernel-devel pygame libjpeg-turbo-devel zlib-devel
            fi
            sudo -u $SUDO_USER pip install regex --user
            sudo -u $SUDO_USER pip install pillow --user

            # Install OctoPrint
            killall -w octoprint
            wget https://github.com/foosel/OctoPrint/archive/master.zip
            sudo -u $SUDO_USER unzip master.zip
            cd OctoPrint-master
            sudo -u $SUDO_USER python setup.py install --user
            cd ..
            sudo -u $SUDO_USER mkdir -p '/home/'"$SUDO_USER"'/.octoprint'
            rm -rf '/home/'"$SUDO_USER"'/.octoprint/checkout'
            sudo -u $SUDO_USER mv OctoPrint-master '/home/'"$SUDO_USER"'/.octoprint/checkout'
            rm master.zip

            # Install M33 Fio
            echo 'y' | sudo -u $SUDO_USER pip uninstall OctoPrint-M33Fio
            wget https://github.com/donovan6000/M33-Fio/archive/master.zip
            while ! sudo -u $SUDO_USER pip install master.zip --user
            do
                :
            done
            rm master.zip

        # Otherwise
        else

            # Install M33 Fio
            echo 'y' | sudo -u pi /home/pi/oprint/bin/pip uninstall OctoPrint-M33Fio
            wget https://github.com/donovan6000/M33-Fio/archive/master.zip
            while ! sudo -u pi /home/pi/oprint/bin/pip install master.zip
            do
                :
            done
            rm master.zip
        fi

        # Apply printer udev rule
        wget -O /etc/udev/rules.d/90-micro-3d-local.rules https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/90-micro-3d-local.rules

        # Apply heatbed udev rule
        wget -O /etc/udev/rules.d/91-micro-3d-heatbed-local.rules https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/91-micro-3d-heatbed-local.rules

        # Reload udev rules
        udevadm control --reload-rules
        udevadm trigger

        # Check if not using OctoPi
        if ! $usingOctoPi
        then

            # Check if startup file doesn't exist
            if [ ! -f /etc/rc.local ]; then

                # Create startup file
                touch /etc/rc.local
                echo "#!/bin/sh -e" >> /etc/rc.local
                chmod +x /etc/rc.local
            fi

            # Check if startup file doesn't contain exit 0
            if ! grep -q "^exit 0$" /etc/rc.local; then

                # Append exit 0 to the end of startup file
                echo "exit 0" >> /etc/rc.local
            fi

            # Remove existing OctoPrint startup commands
            sed -i '/octoprint/d' /etc/rc.local

            # Add OctoPrint to list of startup commands
            sed -i -e 's|^exit 0$|sudo -u '"$SUDO_USER"' "/home/'"$SUDO_USER"'/.local/bin/octoprint"\n&|' /etc/rc.local

            # Create URL link on desktop
            wget https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/octoprint.png
            mv octoprint.png '/usr/share/icons'
            sudo -u $SUDO_USER wget https://raw.githubusercontent.com/donovan6000/M33-Fio/master/installers/Linux/OctoPrint.desktop
            mv OctoPrint.desktop '/home/'"$SUDO_USER"'/Desktop'

            # Start OctoPrint
            rm -rf '/home/'"$SUDO_USER"'/.python-eggs'
            sudo -u $SUDO_USER nohup '/home/'"$SUDO_USER"'/.local/bin/octoprint' >/dev/null 2>&1 &

            # Display message
            echo 'OctoPrint and M33 Fio have been successfully installed. Go to http://localhost:5000 in any web browser to access OctoPrint.'
            echo

        # Otherwise
        else

            # Display message
            echo
            echo 'M33 Fio has been successfully installed.'
            echo
        fi

    # Otherwise
    else

        # Display message
        echo
        echo 'An internet connection is required.'
        echo
    fi
fi
Enygma2002 commented 8 years ago

Nice improvements, @donovan6000 ! Much better to use a single install script. Not sure what`s the reason for the install/uninstall.sh files to be zipped (harder to work with), but you must have some reason.

A bit bummed out that I did not make it into the git commit log / contributors section, even if the PR got merged, (some git back magic?) but I`m thankful for the credits in the changelog ;)

Oh, one thing more. After installing with the script, I had some issues updating both octoprint and the fio plugin. I eventually figured it out (by reading the error logs) and I managed to produce the following instructions to be able to upgrade:

1. Properly initialize the sources folder as a git repo. The install script fails to do this because it does not use git (just zip download of the sources of the master branch). Do it only once.

cd ~/.octoprint/checkout
git init
git remote add origin https://github.com/foosel/OctoPrint.git
git reset --hard origin/master
git branch --set-upstream-to=origin/master master

2.  Manually run the update script in user mode. The UI has no access in root mode, as it assumes by default, since the install script did a user install.

python setup.py install --user

3. Manually reinstall the M3DFio plugin since it can not be simply upgraded with pip (it was installed from zip).

echo 'y' | sudo -u `whoami` pip uninstall OctoPrint-M3DFio
wget https://github.com/donovan6000/M3D-Fio/archive/master.zip
while ! sudo -u `whoami` pip install master.zip --user
do
        :
done
rm master.zip

4. Restart the octoprint server for the updated version to be loaded.

Ideally, many of the issues that lead to the inability to upgrade could be fixed:

Hope you can include the above in some upgrade guide/instructions for anyone else to use.

Thanks for doing an awesome job with Fio and with making it able for me to use my printer on Linux!