File size: 2,874 Bytes
f65fe85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# install.py
#
# This file is part of LilyPond, the GNU music typesetter.
#
# Copyright (C) 2005--2020 Han-Wen Nienhuys <[email protected]>
#
# LilyPond is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LilyPond is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.

import getopt
import sys
import os
import shutil
(opts, args) = getopt.getopt(sys.argv[1:], 'b:cdg:m:o:st:', [])
transform_base = None
group = None
owner = None
transform = None
mode = None
copy = False
create_dir = False

for (o, a) in opts:
    if o == '-b':
        transform_base = a
    elif o == '-c':
        copy = True
    elif o == '-d':
        create_dir = True
    elif o == '-g':
        group = a
    elif o == '-m':
        mode = int(a, base=8)
    elif o == '-o':
        owner = a
    elif o == '-s':
        strip = True
    elif o == '-t':
        transform = a
    elif o == '-h':
        print(''' Usage: $0 [OPTION]... SRCFILE DSTFILE
 or: $0 [OPTION]... SRCFILES... DIRECTORY
 or: $0 -d DIRECTORIES...

In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
In the second, create the directory path DIR.

Options:
-b=TRANSFORMBASENAME
-c         copy source (using $cpprog) instead of moving (using $mvprog).
-d         create directories instead of installing files.
-g GROUP   $chgrp installed files to GROUP.
-m MODE    $chmod installed files to MODE.
-o USER    $chown installed files to USER.
-s         strip installed files (using $stripprog).
-t=TRANSFORM
--help     display this help and exit.
--version  display version info and exit.''')
        sys.exit(0)

if not mode:
    if create_dir:
        mode = 0o755
    else:
        mode = 0o644


chown_me = []

dest = None
if not create_dir:
    dest = args.pop()

for f in args:
    if create_dir:
        if os.path.isdir(f):
            continue

        os.makedirs(f, mode=mode, exist_ok=True)
        chown_me.append(f)
    else:
        if copy:
            if os.path.exists(dest) and not os.path.isdir(dest):
                os.remove(dest)
            shutil.copy2(f, dest)
        else:
            shutil.move(f, dest)

        if os.path.isdir(dest):
            chown_me.append(os.path.join(dest, os.path.basename(f)))
        else:
            chown_me.append(dest)

for f in chown_me:
    os.chmod(f, mode)
    if group is not None or owner is not None:
        os.chown(f, group, owner)