Skip to content

Commit

Permalink
[FIX] permissions: refactor to plumbum
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-wtioit committed Jun 16, 2021
1 parent 33764d7 commit 679ead6
Showing 1 changed file with 68 additions and 12 deletions.
80 changes: 68 additions & 12 deletions build.d/800-permissions
Original file line number Diff line number Diff line change
@@ -1,17 +1,73 @@
#!/bin/bash
set -e
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os.path

from doodbalib import AUTO_DIR, CUSTOM_DIR

from plumbum import FG, local

find, xargs, chmod, chown = (
local.cmd.find,
local.cmd.xargs,
local.cmd.chmod,
local.cmd.chown,
)

# find all files where group or user are not odoo that are not a symlink, and fix permissions for those
# we use find and xargs because chown -R can be very slow on certain systems: https://github.com/docker/for-linux/issues/388
find /opt/odoo \( -not -user root -or -not -group odoo \) -and -not -type l -print0 | xargs -0 --no-run-if-empty chown root:odoo
find /opt/odoo \( -type d -not -perm u=rwx,g=rx,o= \) -o \( -type f -not -perm u=rw,g=r,o= -not -perm u=rwx,g=rx,o= \) -print0 | xargs -0 --no-run-if-empty chmod u+rwX,g+rX-w,o=
(
find[
"/opt/odoo",
"(",
"-not",
"-user",
"root",
"-or",
"-not",
"-group",
"odoo",
")",
"-and",
"-not",
"-type",
"l",
"-print0",
]
| xargs["-0", "--no-run-if-empty", "chown", "root:odoo"]
) & FG
(
find[
"/opt/odoo",
"(",
"-type",
"d",
"-not",
"-perm",
"u=rwx,g=rx,o=",
")",
"-o",
"(",
"-type",
"f",
"-not",
"-perm",
"u=rw,g=r,o=",
"-not",
"-perm",
"u=rwx,g=rx,o=",
")",
"-print0",
]
| xargs["-0", "--no-run-if-empty", "chmod", "u+rwX,g+rX-w,o="]
) & FG

chmod["-R", "g+w", AUTO_DIR] & FG

chmod -R g+w /opt/odoo/auto
custom_ssh_dir = os.path.join(CUSTOM_DIR, "ssh")
if os.path.isdir(custom_ssh_dir):
chmod["-R", "u=rwx,go=", custom_ssh_dir] & FG

if [ -d /opt/odoo/custom/ssh ]; then
chmod -R u=rwX,go= /opt/odoo/custom/ssh
fi
if [ -d ~odoo/.ssh ]; then
chown -R odoo:odoo ~odoo/.ssh
chmod -R u=rwX,go= ~odoo/.ssh
fi
odoo_ssh_dir = '/home/odoo/.ssh'
if os.path.isdir(odoo_ssh_dir):
chown["-R", "odoo:odoo", odoo_ssh_dir] & FG
chmod["-R", "u=rwx,go=", odoo_ssh_dir] & FG

0 comments on commit 679ead6

Please sign in to comment.