-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] permissions: refactor to plumbum
- Loading branch information
Showing
1 changed file
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |