upgrade_400.sh (AEN 4.0)
========================

.. raw:: html

    <div class="highlight-default"><div class="highlight"><pre><span></span>#!/usr/bin/env bash

    # Loop through each user folder in /projects
    sudo find /projects -maxdepth 1 -type d -print | while read f; do
        ownr=`echo &quot;${f}&quot; | cut -d&#39;/&#39; -f 3`
        # Skip blank owners (happens for /projects by itself)
        if [ -z &quot;$ownr&quot; ]; then continue; fi
        # Fix project rc (this should match the functionality in functions.sh -&gt; fix_project_rc)
        sudo find &quot;${f}&quot; -maxdepth 1 -type d -print | while read PROJECT_HOME; do
            project_name=`echo &quot;${PROJECT_HOME}&quot; | cut -d&#39;/&#39; -f 4`
            # Skip blank owners (happens for /projects/owner by itself)
            if [ -z &quot;$project_name&quot; ]; then continue; fi
            oldline=&#39;export CONDA_ENVS_PATH=$WAKARI_PROJECT_HOME/envs:$CONDA_ENVS_PATH&#39;
            newline=&#39;export CONDA_ENVS_PATH=$WAKARI_PROJECT_HOME/envs:${CONDA_ENVS_PATH:-DEFAULTS}&#39;
            sudo cp &quot;${PROJECT_HOME}&quot;/.projectrc &quot;${PROJECT_HOME}&quot;/.projectrc.new
            sudo sed &quot;s+$oldline+$newline+&quot; &quot;${PROJECT_HOME}&quot;/.projectrc.new | sudo tee &quot;${PROJECT_HOME}&quot;/.projectrc &gt; /dev/null
        done
        # Change /projects/owner to be owned by wakari
        echo &quot;Upgrading projects owned by ${ownr}. This could take several minutes...&quot;
        sudo chown wakari:wakari &quot;${f}&quot;
        sudo chmod 711 &quot;${f}&quot;
        sudo setfacl -m u:&quot;${ownr}&quot;:rwx &quot;${f}&quot;
        # Change ownership of any root-owned files to the project owner
        sudo find &quot;${f}&quot; -user root -exec chown &quot;${ownr}&quot;:&quot;${ownr}&quot; {} \;
        # Give wakari ACL permissions for all projects
        sudo find &quot;${f}&quot; -type d &#39;!&#39; -user wakari -exec setfacl -m u:wakari:rwX,d:u:wakari:rwX &#39;{}&#39; &#39;;&#39;
        sudo find &quot;${f}&quot; -type f &#39;!&#39; -user wakari -exec setfacl -m u:wakari:rwX &#39;{}&#39; &#39;;&#39;
        # Force re-granting of permissions at next project startup
        sudo find &quot;${f}&quot; -maxdepth 3 -name .skip_perms -exec rm {} \;
    done

    # Fix ownership of pidfiles
    echo &quot;Fixing pidfile ownership&quot;
    sudo chown -R wakari:wakari /opt/wakari/wakari-compute/var/run/compute-launcher-apps/

    # Fix ownership of logfiles
    echo &quot;Fixing logfile ownership&quot;
    sudo chown -R wakari:wakari /opt/wakari/wakari-compute/var/log/wakari/compute-launcher-apps/

    echo &quot;Done upgrading.&quot;
    </pre></div>
    </div>
