diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -121,6 +121,8 @@ PYTHON_3 = getVersionTuple()>= (3, 0) +GID = grp.getgrnam('admin').gr_gid + USAGE = textwrap.dedent("""\ Usage: build_python [options] @@ -468,6 +470,8 @@ os.environ['PATH'] = '/bin:/sbin:/usr/bin:/usr/sbin' print "Setting default PATH: %s"%(os.environ['PATH']) + # Make sure files we create get the correct permissions + os.umask(0o022) def parseOptions(args=None): """ @@ -766,6 +770,36 @@ os.mkdir(docdir) os.rename(os.path.join(buildDir, 'build', 'html'), docdir) +def fixFilePermissions(p): + mode = os.lstat(p).st_mode + if stat.S_ISLNK(mode): + return + + mode = stat.S_IMODE(mode) + + # chmod a+r,u+w,go+X,go-w + mode |= 0o644 + mode &= ~0o022 + if mode & stat.S_IXUSR: + mode |= 0o011 + + os.chmod(p, mode) + os.chown(p, -1, GID) + +def fixDirectoryPermissions(dir): + for dirpath, dirnames, filenames in os.walk(dir): + for dn in dirnames: + p = os.path.join(dirpath, dn) + os.chmod(p, 0o755) + os.chown(p, -1, GID) + + for fn in filenames: + p = os.path.join(dirpath, fn) + fixFilePermissions(p) + +def copy(src, dst): + shutil.copy(src, dst) + fixFilePermissions(dst) def buildPython(): print "Building a universal python for %s architectures" % UNIVERSALARCHS @@ -831,26 +865,6 @@ 'Python.framework', 'Versions', getVersion(), 'lib')))) - print "Fix file modes" - frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') - gid = grp.getgrnam('admin').gr_gid - - for dirpath, dirnames, filenames in os.walk(frmDir): - for dn in dirnames: - os.chmod(os.path.join(dirpath, dn), 0775) - os.chown(os.path.join(dirpath, dn), -1, gid) - - - for fn in filenames: - if os.path.islink(fn): - continue - - # "chmod g+w $fn" - p = os.path.join(dirpath, fn) - st = os.stat(p) - os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IWGRP) - os.chown(p, -1, gid) - if PYTHON_3: LDVERSION=None VERSION=None @@ -895,6 +909,7 @@ if os.path.exists(usr_local_bin): shutil.rmtree(usr_local_bin) os.makedirs(usr_local_bin) + frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') for fn in os.listdir( os.path.join(frmDir, 'Versions', version, 'bin')): os.symlink(os.path.join(to_framework, fn), @@ -928,7 +943,7 @@ fp = open(outPath, 'wb') fp.write(data) fp.close() - os.chmod(outPath, 0755) + os.chmod(outPath, 0o755) @@ -970,6 +985,7 @@ os.makedirs(packageContents) if srcdir is not None: + fixDirectoryPermissions(srcdir) os.chdir(srcdir) runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) @@ -1091,11 +1107,11 @@ for fn in os.listdir('resources'): if fn == '.svn': continue if fn.endswith('.jpg'): - shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) + copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) else: patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) - shutil.copy("../../LICENSE", os.path.join(rsrcDir, 'License.txt')) + copy("../../LICENSE", os.path.join(rsrcDir, 'License.txt')) def installSize(clear=False, _saved=[]): @@ -1136,7 +1152,7 @@ shellQuote(imagepath + ".tmp.dmg"), shellQuote(os.path.join(WORKDIR, "mnt")))) # Custom icon for the DMG, shown when the DMG is mounted. - shutil.copy("../Icons/Disk Image.icns", + copy("../Icons/Disk Image.icns", os.path.join(WORKDIR, "mnt", volname, ".VolumeIcon.icns")) runCommand("/Developer/Tools/SetFile -a C %s/"%( shellQuote(os.path.join(WORKDIR, "mnt", volname)),)) @@ -1209,7 +1225,6 @@ folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( getVersion(),)) - os.chmod(folder, 0755) setIcon(folder, "../Icons/Python Folder.icns") # Create the installer @@ -1219,7 +1234,7 @@ patchFile('resources/ReadMe.txt', os.path.join(WORKDIR, 'installer', 'ReadMe.txt')) # Ditto for the license file. - shutil.copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) + copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') print>> fp, "# BUILD INFO" diff --git a/Mac/BuildScript/scripts/postflight.framework b/Mac/BuildScript/scripts/postflight.framework --- a/Mac/BuildScript/scripts/postflight.framework +++ b/Mac/BuildScript/scripts/postflight.framework @@ -17,6 +17,5 @@ "${FWK}/lib/python${PYVER}" chgrp -R admin "${FWK}" -chmod -R g+w "${FWK}" exit 0