#!/system/bin/sh
#
#	This file is part of the OrangeFox Recovery Project
# 	Copyright (C) 2026 The OrangeFox Recovery Project
#
#	OrangeFox 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
#	any later version.
#
#	OrangeFox 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.
#
# 	This software is released under GPL version 3 or any later version.
#	See <http://www.gnu.org/licenses/>.
#
# 	Please maintain this if you use this script or any part of it
#

set_permissions() {
	chcon -R "u:object_r:media_rw_data_file:s0" "$1";
	chown -R media_rw:media_rw "$1";
	chmod -R 0777 "$1";
}

# --- #
if [ -n "$1" -a -e $1 ]; then
	echo "Setting media_rw permissions and selinux context for $1" >> /tmp/recovery.log;
	set_permissions $1;
	sync;
	exit 0;
else
	exit 1;
fi
#
