#!/bin/sh # ------- # File: lliurex-vault-owner # Description: LliureX uid+gid backup tool # Author: Luis Garcia Gisbert # # 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 2 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, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- do_usage(){ echo "$0 --backup RESTORE_SCRIPT_PATH NAME_PREFIX BACKUP_DIR SOURCE..." >&2 exit 1 } do_gen_script(){ cat < "$RESTORE_SCRIPT" while [ "$1" ] ; do if [ -e "$1" ] ; then USER_GROUP="$(find "$1" -maxdepth 0 -mindepth 0 -printf "%u:%g")" USER_NAME="${USER_GROUP%%:*}" if [ "$USER_NAME" ] && grep -q "^$USER_NAME:" /etc/passwd && grep -q "^$USER_NAME:" /etc/shadow ; then USER_SELL="$(grep "^$USER_NAME:" /etc/passwd |cut -f 7 -d ":" |tr -d "\n")" printf "$USER_NAME:" >> "$OUTPUT_FILE" USER_HOME="$(grep "^$USER_NAME:" /etc/passwd |cut -f 6 -d ":" |tr -d "\n")" grep "^$USER_NAME:" /etc/passwd |cut -f 5 -d ":" |tr "\n" ":" >> "$OUTPUT_FILE" grep "^$USER_NAME:" /etc/shadow |cut -f 2 -d ":" |tr "\n" ":" >> "$OUTPUT_FILE" echo "verify_user \"${USER_NAME}\" \"${USER_GROUP##*:}\" \"$USER_SELL\"" "$USER_HOME" "./$PREFIX_NAME.user" "$(groups "${USER_NAME}")" >> "$RESTORE_SCRIPT" echo "chown -R \"$USER_GROUP\" \"$1\" || true" >> "$RESTORE_SCRIPT" fi fi shift done echo "exit 0" >> "$RESTORE_SCRIPT" chmod +x "$RESTORE_SCRIPT" exit 0