Fix upgrade script 31/163231/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 8 Dec 2017 05:34:20 +0000 (14:34 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 15 Dec 2017 06:12:27 +0000 (06:12 +0000)
- Change code to use mv instead of cp.
- Remove some unnecessary definitions.
- Integrate some internal functions which has duplicated operations.

Change-Id: I6cc37d2129419065c1667c4035b0f58e91d75875
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
data/700.pkgmgr.patch.sh.in

index 8b9fdfefa15d693189fd04839984ed796975087d..366e156df55e535deddd73254d530b59c12e12bb 100644 (file)
@@ -44,7 +44,6 @@ DEFAULT_RO_SMACK_LABEL=User::Home
 TIZEN_MANIFEST=tizen-manifest.xml
 
 OWNER_SYSTEM_SHARE=owner:system_share
-TRUSTED_LABEL=User::Author::1
 
 RESTRICTION_DBPATH=/var/lib/package-manager
 RESTRICTION_DBNAME=restriction.db
@@ -90,69 +89,67 @@ function remove_unregistered_pkg(){
        done
 }
 
-function move_user_tpk_ro_files(){
-       #this copy will copy whole things include userdata
+function move_user_pkg_ro_files(){
        local package=$1
-       cp -af $OPT_USR_APPS/$package $DEFAULT_PKG_APP_LOCATION/
-       chown -R $DEFAULT_RO_OWNER_GROUP $DEFAULT_PKG_APP_LOCATION/$package
-       chsmack -E $DEFAULT_PKG_APP_LOCATION/$package/bin/*
-
-       #remove file except author-signature.xml, bin, lib, res, shared/res, signature1.xml, tizen-manifest.xml
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/data" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/data"
-       fi
 
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/cache" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/cache"
-       fi
+       mkdir $DEFAULT_PKG_APP_LOCATION/$package
+       mkdir $DEFAULT_PKG_APP_LOCATION/$package/shared
+       chown -R $DEFAULT_RO_OWNER_GROUP $DEFAULT_PKG_APP_LOCATION/$package
 
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/shared/cache" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/shared/cache"
-       fi
+       #move only readonly files
+       ls $OPT_USR_APPS/$package | while read filename
+       do
+               if [ $filename != "data" ] && [ $filename != "cache" ] && [ $filename != "shared" ]
+               then
+                       mv $OPT_USR_APPS/$package/$filename $DEFAULT_PKG_APP_LOCATION/$package
+               fi
+       done
 
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/shared/data" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/shared/data"
+       if [ -e "$OPT_USR_APPS/$package/shared/res" ]; then
+               mv $OPT_USR_APPS/$package/shared/res $DEFAULT_PKG_APP_LOCATION/$package/shared
        fi
 
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/shared/trusted" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/shared/trusted"
+       if [ -e $DEFAULT_PKG_APP_LOCATION/$package/bin/ ]; then
+               chsmack -E $DEFAULT_PKG_APP_LOCATION/$package/bin/*
        fi
-
        chsmack -r -a $DEFAULT_SMACK_LABEL $DEFAULT_PKG_APP_LOCATION/$package/*
 }
 
-function move_user_tpk_rw_files(){
+function move_user_pkg_rw_files(){
        local package=$1
 
+       local source="$OPT_USR_APPS/$package"
        local target="$DEFAULT_USER_APPS_RW/$package"
        chown -R $DEFAULT_RW_OWNER_GROUP $target
 
-       local source="$OPT_USR_APPS/$package"
-
-       rm -rf $source/shared/cache
        if [ -e $source/cache ]; then
-               cp -aR --no-preserve=mode,ownership,context $source/cache $target/
-               chown -R owner:system_share $target/cache/
+               mv $source/cache/* $target/cache/
+               chown -R $OWNER_SYSTEM_SHARE $target/cache/
+               chsmack -r -a $DEFAULT_RW_SMACK_LABEL$package $target/cache
        fi
        if [ -e $source/data ]; then
-               cp -aR --no-preserve=mode,ownership,context $source/data $target/
-               chown -R owner:system_share $target/data/
+               mv $source/data/* $target/data/
+               chown -R $OWNER_SYSTEM_SHARE $target/data/
+               chsmack -r -a $DEFAULT_RW_SMACK_LABEL$package $target/data
        fi
-       if [ -e $source/shared ]; then
-               cp -aR --no-preserve=mode,ownership,context $source/shared $target/
-               if [ -e $target/shared/data ]; then
-                       chown -R owner:system_share $target/shared/data
-               fi
-               if [ -e $target/shared/trusted ]; then
-                       chown -R owner:users $target/shared/trusted
-               fi
+
+       if [ -e $source/shared/data ]; then
+               mv $source/shared/data/* $target/shared/data/
+               chsmack -r -a $DEFAULT_RW_SMACK_LABEL$package::SharedRO $target/shared/data
+               chown -R $OWNER_SYSTEM_SHARE $target/shared/data
+       fi
+
+       if [ -e $source/shared/trusted ] && [ -e $target/shared/trusted ]; then
+               cp -aR --no-preserve=mode,ownership,context $source/shared/trusted/* $target/shared/trusted
+               chown -R owner:users $target/shared/trusted
        fi
+
        rm -rf $source
 }
 
 function copy_user_tpk_manifest(){
        local package=$1
-       cp $DEFAULT_PKG_APP_LOCATION/$1/$TIZEN_MANIFEST $DEFAULT_PKG_MANIFEST_LOCATION/$package.xml
+       cp $DEFAULT_PKG_APP_LOCATION/$package/$TIZEN_MANIFEST $DEFAULT_PKG_MANIFEST_LOCATION/$package.xml
        chsmack -a System $DEFAULT_PKG_MANIFEST_LOCATION/$package.xml
 }
 
@@ -164,73 +161,12 @@ function move_user_tpk_files(){
        while read package
        do
                echo "processing user tpk $package..."
-               move_user_tpk_ro_files $package
+               move_user_pkg_ro_files $package
                copy_user_tpk_manifest $package
        done < $DB_RESULT_FILE
        rm -f $DB_RESULT_FILE
 }
 
-function move_user_wgt_ro_files(){
-       #this copy will copy whole things include userdata
-       local package=$1
-       cp -af $OPT_USR_APPS/$package $DEFAULT_PKG_APP_LOCATION/
-       chown -R $DEFAULT_RO_OWNER_GROUP $DEFAULT_PKG_APP_LOCATION/$package
-       chsmack -E $DEFAULT_PKG_APP_LOCATION/$package/bin/*
-
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/data" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/data"
-       fi
-
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/cache" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/cache"
-       fi
-
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/shared/cache" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/shared/cache"
-       fi
-
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/shared/data" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/shared/data"
-       fi
-
-       if [ -e "$DEFAULT_PKG_APP_LOCATION/$package/shared/trusted" ]; then
-               rm -r "$DEFAULT_PKG_APP_LOCATION/$package/shared/trusted"
-       fi
-
-       chsmack -r -a $DEFAULT_SMACK_LABEL $DEFAULT_PKG_APP_LOCATION/$package/*
-}
-
-function move_user_wgt_rw_files(){
-       local package=$1
-
-       local target="$DEFAULT_USER_APPS_RW/$package"
-       chown -R $DEFAULT_RW_OWNER_GROUP $target
-
-       local source="$OPT_USR_APPS/$package"
-
-       rm -rf $source/shared/cache
-       if [ -e $source/cache ]; then
-               cp -aR --no-preserve=mode,ownership,context $source/cache $target/
-               chown -R owner:system_share $target/cache/
-       fi
-       if [ -e $source/data ]; then
-               cp -aR --no-preserve=mode,ownership,context $source/data $target/
-               chown -R owner:system_share $target/data/
-       fi
-       if [ -e $source/shared ]; then
-               cp -aR --no-preserve=mode,ownership,context $source/shared/ $target/
-               if [ -e $target/shared/data ]; then
-                       chown -R owner:system_share $target/shared/data
-               fi
-               if [ -e $target/shared/trusted ]; then
-                       chown -R owner:users $target/shared/trusted
-               fi
-
-       fi
-       rm -r $source
-}
-
-
 function move_user_wgt_files(){
        echo "#move user WGT's files"
        echo "SELECT package FROM package_info WHERE package_readonly='false' COLLATE NOCASE AND package_type='wgt' COLLATE NOCASE;" |
@@ -239,7 +175,7 @@ function move_user_wgt_files(){
        while read package
        do
                echo "processing user wgt $package..."
-               move_user_wgt_ro_files $package
+               move_user_pkg_ro_files $package
        done < $DB_RESULT_FILE
        rm -f $DB_RESULT_FILE
 
@@ -251,7 +187,7 @@ function initdb(){
 
        mkdir -m 770 -p /opt/dbspace/user/5001
        chmod 755 /opt/dbspace/user
-       chsmack -r -a User::Home /opt/dbspace/user
+       chsmack -r -a $DEFAULT_RO_SMACK_LABEL /opt/dbspace/user
        chown $OWNER_SYSTEM_SHARE /opt/dbspace/user/5001
 
        pkg_initdb --uid 5001
@@ -284,25 +220,26 @@ function move_preload_pkg_userdata(){
                echo "processing preload pkg $package..."
                local source="$OPT_USR_APPS/$package"
                local target="$DEFAULT_USER_APPS_RW/$package"
-               rm -rf $source/shared/cache
                if [ -e $source/cache ]; then
-                       cp -aR --no-preserve=mode,ownership,context $source/cache $target/
-                       chown -R owner:system_share $target/cache/
+                       mv $source/cache/* $target/cache/
+                       chown -R $OWNER_SYSTEM_SHARE $target/cache/
+                       chsmack -r -a $DEFAULT_RW_SMACK_LABEL$package $target/cache
                fi
                if [ -e $source/data ]; then
-                       cp -aR --no-preserve=mode,ownership,context $source/data $target/
-                       chown -R owner:system_share $target/data/
+                       mv $source/data/* $target/data/
+                       chown -R $OWNER_SYSTEM_SHARE $target/data/
+                       chsmack -r -a $DEFAULT_RW_SMACK_LABEL$package $target/data
                fi
-               if [ -e $source/shared ]; then
-                       cp -aR --no-preserve=mode,ownership,context $source/shared $target/
-                       if [ -e $target/shared/data ]; then
-                               chown -R owner:system_share $target/shared/data
-                       fi
-                       if [ -e $target/shared/trusted ]; then
-                               chown -R owner:users $target/shared/trusted
-                       fi
+               if [ -e $source/shared/data ]; then
+                       mv $source/shared/data/* $target/shared/data/
+                       chsmack -r -a $DEFAULT_RW_SMACK_LABEL$package::SharedRO $target/shared/data
+                       chown -R $OWNER_SYSTEM_SHARE $target/shared/data
                fi
 
+               if [ -e $source/shared/trusted ] && [ -e $target/shared/trusted ]; then
+                       cp -aR --no-preserve=mode,ownership,context $source/shared/trusted/* $target/shared/trusted
+                       chown -R owner:users $target/shared/trusted
+               fi
                rm -rf $source
        done < $DB_RESULT_FILE
        rm -f $DB_RESULT_FILE
@@ -386,7 +323,7 @@ function init_user_tpk_preload_rw_packages() {
 
                        rm -f $CERT_TEMP_FILEPATH/$package.txt
                        migrate_cert_info $package
-                       move_user_tpk_rw_files $package
+                       move_user_pkg_rw_files $package
                else
                        #if exists, remove RO files in rw location
                        echo "Remove readonly updated pkg $package"
@@ -419,7 +356,7 @@ function init_user_wgt_preload_rw_packages() {
                                wgt-backend -y $package --preload-rw
                        fi
 
-                       move_user_wgt_rw_files $package
+                       move_user_pkg_rw_files $package
                else
                        echo "Remove readonly updated pkg $package"
                        if [ -e "$DEFAULT_PKG_APP_LOCATION/$package" ]; then
@@ -566,7 +503,7 @@ function init_user_tpk_packages() {
                rm -f $CERT_TEMP_FILEPATH/$package.txt
 
                migrate_cert_info $package
-               move_user_tpk_rw_files $package
+               move_user_pkg_rw_files $package
        done < $DB_RESULT_FILE
        rm -f $DB_RESULT_FILE
 }
@@ -583,7 +520,7 @@ function init_user_wgt_packages(){
                echo "init user wgt package $package..."
                wgt-backend -y $package
                chsmack -a System $DEFAULT_PKG_MANIFEST_LOCATION/$package.xml
-               move_user_wgt_rw_files $package
+               move_user_pkg_rw_files $package
        done < $DB_RESULT_FILE
        rm -f $DB_RESULT_FILE
 }
@@ -698,7 +635,7 @@ function make_web_widget_symlink(){
                 echo "processing web widget $app_id..."
                 rm -f $DEFAULT_PKG_APP_LOCATION/$package/bin/$app_id
                 ln -sf /usr/bin/web-widget-runtime $DEFAULT_PKG_APP_LOCATION/$package/bin/$app_id
-                chsmack -a User::Home $DEFAULT_PKG_APP_LOCATION/$package/bin/$app_id
+                chsmack -a $DEFAULT_RO_SMACK_LABEL $DEFAULT_PKG_APP_LOCATION/$package/bin/$app_id
                 chown $DEFAULT_RO_OWNER_GROUP $DEFAULT_PKG_APP_LOCATION/$package/bin/$app_id
                 chmod 755 $DEFAULT_PKG_APP_LOCATION/$package/bin/$app_id
 
@@ -706,6 +643,8 @@ function make_web_widget_symlink(){
         rm -f $DB_RESULT_FILE
 }
 
+shopt -s dotglob
+
 backup_db
 
 create_restriction_db