summaryrefslogtreecommitdiffstats
path: root/src/oh-fixperms.sh
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-10-21 17:33:27 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-10-21 17:44:10 (EDT)
commit0e12876e56e414f8df1b4ce111e1d11d5b733771 (patch)
tree0109c175b7888461648554c9a0f5147c7b7fb314 /src/oh-fixperms.sh
parentd42160e298f920b093ff490a045b42fe1410c598 (diff)
Write and document oh-fixperms.
Diffstat (limited to 'src/oh-fixperms.sh')
-rw-r--r--src/oh-fixperms.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/oh-fixperms.sh b/src/oh-fixperms.sh
new file mode 100644
index 0000000..d7779aa
--- /dev/null
+++ b/src/oh-fixperms.sh
@@ -0,0 +1,82 @@
+#!@@SH@@
+#
+# opkhelper
+# src/oh-fixperms
+# Fix permissions and ownerships of data files.
+#
+# Copyright (C) 2012 Patrick "P. J." McDermott
+#
+# This program 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.
+#
+# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+. '@@LIBOPKBUILD_1@@/load.sm'
+
+ob_use locale
+ob_use output
+
+main()
+{
+ dir='dest'
+
+ ob_set_locale_path '@@LOCALEDIR@@/%s/LC_MESSAGES/%s.ms'
+ ob_set_text_domain 'opkhelper'
+
+ while getopts 'd:' opt; do
+ case "${opt}" in
+ d)
+ dir="${OPTARG}"
+ ;;
+ ?)
+ ob_error "$(ob_get_msg 'bad_opt')"
+ exit 1
+ ;;
+ esac
+ done
+
+ # Ensure that everything is owned by UID 0 and GID 0.
+ ob_info "$(ob_get_msg 'chown')"
+ find "${dir}" \
+ -exec 'chown' '-h' '0:0' '{}' ';'
+
+ # Ensure that shared libraries, static libraries, and libtool archives have
+ # a rw-r--r-- mode.
+ ob_info "$(ob_get_msg 'chmod_lib')"
+ find "${dir}" -type f -a ! -perm 644 \
+ -a \( -name '*.so*' -o -name '*.a' -o -name '*.la' \) \
+ -exec 'chmod' '644' '{}' ';'
+
+ # Ensure that header files have a rw-r--r-- mode.
+ if [ -d "${dir}/usr/include" ]; then
+ ob_info "$(ob_get_msg 'chmod_include')"
+ find "${dir}/usr/include" -type f -a ! -perm 644 \
+ -exec 'chmod' '644' '{}' ';'
+ fi
+
+ # Ensure that manual pages have a rw-r--r-- mode.
+ if [ -d "${dir}/usr/share/man" ]; then
+ ob_info "$(ob_get_msg 'chmod_man')"
+ find "${dir}/usr/share/man" -type f -a ! -perm 644 \
+ -exec 'chmod' '644' '{}' ';'
+ fi
+
+ # Ensure that binary programs and service scripts have a rwxr-xr-x mode.
+ for bindir in /usr/sbin /usr/bin /sbin /bin /usr/games /etc/init.d; do
+ if [ -d "${dir}/${bindir}" ]; then
+ ob_info "$(ob_get_msg 'chmod_bin')" "${bindir}"
+ find "${dir}/${bindir}" -type f -a ! -perm 755 \
+ -exec 'chmod' '755' '{}' ';'
+ fi
+ done
+}
+
+main "${@}"