Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[userids] Fix user ids to match the new ids in Mer.
Signed-off-by: Marko Saukko <marko.saukko@jollamobile.com>
- Loading branch information
Marko Saukko
committed
Jun 11, 2013
1 parent
81c226d
commit 2d1aa3f
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/sh | ||
| # Copyright (C) 2013 Jolla Ltd. | ||
| # Contact: Islam Amer <islam.amer@jollamobile.com> | ||
| # All rights reserved. | ||
| # | ||
| # Redistribution and use in source and binary forms, with or without | ||
| # modification, are permitted provided that the following conditions are met: | ||
| # * Redistributions of source code must retain the above copyright | ||
| # notice, this list of conditions and the following disclaimer. | ||
| # * Redistributions in binary form must reproduce the above copyright | ||
| # notice, this list of conditions and the following disclaimer in the | ||
| # documentation and/or other materials provided with the distribution. | ||
| # * Neither the name of the <organization> nor the | ||
| # names of its contributors may be used to endorse or promote products | ||
| # derived from this software without specific prior written permission. | ||
| # | ||
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
| # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| # only works as root | ||
| [ $UID -eq 0 ] || exit 0 | ||
|
|
||
| # requires old passwd and group files in /var/lib/misc | ||
| [ -f /var/lib/misc/passwd.old ] || exit 0 | ||
| [ -f /var/lib/misc/group.old ] || exit 0 | ||
|
|
||
| # Get system's default min gid and uid | ||
| GID_MIN=$(grep "^GID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) | ||
| UID_MIN=$(grep "^UID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) | ||
|
|
||
| # Get users that have a /home dir | ||
| for user in "$(grep "/home/" /etc/passwd)"; do | ||
| # get user's old info | ||
| uname=$(echo "$user" | cut -d: -f1) | ||
| old_uid=$(grep $uname /var/lib/misc/passwd.old | cut -d: -f3) | ||
| old_gid=$(grep $uname /var/lib/misc/passwd.old | cut -d: -f4) | ||
| gname=$(grep ":$old_gid:" /var/lib/misc/group.old | cut -d: -f1) | ||
|
|
||
| new_gid=$old_gid | ||
| # compare them to system's min gid and uid | ||
| if test $old_gid -lt $GID_MIN ; then | ||
| new_gid=$(( $old_gid + 99000 )) | ||
| fi | ||
|
|
||
| new_uid=$old_uid | ||
| if test $old_uid -lt $UID_MIN ; then | ||
| new_uid=$(( $old_uid + 99000 )) | ||
| fi | ||
|
|
||
| # correct user's uid and gid and reown it's files to it | ||
| if test \! "$new_uid" -eq "$old_uid" -o \! "$new_gid" -eq "$old_gid" ; then | ||
| groupmod -g $new_gid $gname | ||
| usermod -u $new_uid $uname | ||
| find / -xdev \( -group $old_gid -o -user $old_uid \) -exec chown -h $new_uid:$new_gid {} + | ||
| fi | ||
| done | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters