How to create directory and change it's owner with the deb package

133

Solution 1

You were right, you need a debian/my_package.postinst file to perform such operation:

#!/bin/sh

#DEBHELPER#

set -e

DIR="/var/log/my_package/"
USER="my_user"

mkdir -p ${DIR}    
if id -u ${USER} > /dev/null 2>&1; then    
    chown ${USER}:${USER} ${DIR}
fi

Note: The script checks if the user exists before calling chown.

Solution 2

You do not need to create a postinst script, but the solution is still a bit tricky. I use dh wildcard in debian/rules:

#!/usr/bin/make -f
%:
        dh $@

binary:
        dh $@

which does all the needed stuff. But I need to override some dir's ownership (lets call it data). So I must make some exception, I use special directives as follow:

    override_dh_install:
        dh_install   #calls default *.install and *.dirs installation
        install -d -o www-data -g www-data $(CURDIR)/debian/<package_name>/var/www/<something>/data 

The data directory do not need to be in *.dirs file. But still there is one trick. Debhelper contains script dh_fixperms, which would fix ownership back to root, so we need to override too:

override_dh_fixperms:
    dh_fixperms --exclude data

That's all. Keep in mind the data dir does not count as a conffile, so it will be removed on package removal. If you need to make it a conffile, it is another story.

Share:
133

Related videos on Youtube

space earth
Author by

space earth

Updated on September 18, 2022

Comments

  • space earth
    space earth over 1 year

    I want to call the controller function from view. This my view:

       <body>
       <div ng-app="appTable">
          <div ng-controller="Allocation">
             <button ng-click="add()"> Add </button> 
             <button ng-click="remove()">remove</button>
             <table>
                <th>
                <td>Date</td>
                <td>Project</td>
                <td>Release</td>
                <td>Feature</td>
                <td>Module name</td>
                <td>Hours spent</td>
                <td>Comment</td>
                </th>
                <tr ng-repeat="data in dataList">
                   <td><input type="checkbox" ng-model="data.isDelete"/></td>
                   <td>
                      <input type="text"
                         datepicker
                         ng-model="data.date" />                 
                   </td>
                   <td><input type="text" ng-model="data.dept"/></td>
                   <td>
                      <select ng-model="data.release" ng-options="x for x in range">
                      </select>
                   </td>
                   <td>
                      <select ng-model="data.feature" ng-options="x for x in feature">
                      </select>
                   </td>
                   <td>
                      <input type = "text" ng-model = "data.modulename">
                   </td>
                   <td>
                      <select ng-model="data.hours" ng-options="x for x in hours">
                      </select>
                   </td>
                   <td>
                      <input type = "text" ng-model = "data.comment">
                   </td>
                </tr>
             </table>
             <button ng-click="Submit()">Submit</button>
             <table>
                <tr ng-repeat="data in displayList">
                   <div ng-controller="Allocation as vm">
                      <div>{{vm.postdata(data.date)}}</div>
                   </div>
                   <p>Output Message : {{msg}}</p>
                   <p>StatusCode: {{statusval}}</p>
                   <p>Status: {{statustext}} </p>
                   <p>Response Headers: {{headers}} </p>
                   <td>
                      <p>{{data.date}}</p>
                   </td>
                   <td>
                      <p>{{data.dept}}</p>
                   </td>
                   <td>
                      <p>{{data.release}}</p>
                   </td>
                   <td>
                      <p>{{data.feature}} </p>
                   </td>
                   <td>
                      <p>{{data.modulename}}</p>
                   </td>
                   <td>
                      <p>{{data.hours}}</p>
                   </td>
                   <td>
                      <p>{{data.comment}}</p>
                   </td>
                   </td>
                </tr>
             </table>
          </div>
       </div>
    </body>
    

    This is script.

    <script>
        var app = angular.module("appTable", []);
    
        app.controller("Allocation", function($scope) {
            $scope.hours = ["1", "2", "3"];
            $scope.range = ["1", "2", "3"];
            $scope.feature = ["UT", "FSDS", "Coding/Devlopment", "QA"];
    
            $scope.dataList = [{
                date: '17/07/2016',
                dept: 'OneCell',
                release: '1',
                feature: "UT",
                modulename: "Redundancy",
                hours: "1",
                comment: "Add extra information"
            }];
    
            $scope.add = function() {
                var data = {};
                var size = $scope.dataList.length;
                if (!size) {
                    $scope.dataList = [{
                        date: '17/07/2016',
                        dept: 'OneCell',
                        release: '1',
                        feature: "UT",
                        modulename: "Redundancy",
                        hours: "1",
                        comment: "Add extra information"
                    }];
                } else {
                    size = size - 1;
                    data.date = $scope.dataList[size].date;
                    data.dept = $scope.dataList[size].dept;
                    data.release = $scope.dataList[size].release;
                    data.feature = $scope.dataList[size].feature;
                    data.modulename = $scope.dataList[size].modulename;
                    data.hours = $scope.dataList[size].hours;
                    data.comment = $scope.dataList[size].comment;
                    $scope.dataList.push(data);
                }
    
            };
    
            $scope.Submit = function() {
                $scope.test = "Submit is pressed...";
                $scope.displayList = [];
                angular.forEach($scope.dataList, function(v) {
                    if (!v.isDelete) {
                        $scope.displayList.push(v);
                    }
                });
                $scope.dataList.splice(0);
    
    
            };
            $scope.remove = function() {
                var newDataList = [];
                angular.forEach($scope.dataList, function(v) {
                    if (!v.isDelete) {
                        newDataList.push(v);
                    }
                });
                $scope.dataList = newDataList;
            };
    
            $scope.postdata = function(date) {
    
                var data = {
                    date: date,
                };
                $http.post('/add_status/', data).then(function(response) {
                    if (response.data)
                        $scope.msg = "Post Data Submitted Successfully!";
                }, function(response) {
                    $scope.msg = "Service not Exists";
                    $scope.statusval = response.status;
                    $scope.statustext = response.statusText;
                    $scope.headers = response.headers();
                });
            };
    
    
        });
    
    
        app.directive("datepicker", function() {
    
            function link(scope, element, attrs, controller) {
                // CALL THE "datepicker()" METHOD USING THE "element" OBJECT.
                element.datepicker({
                    onSelect: function(dt) {
                        scope.$apply(function() {
                            // UPDATE THE VIEW VALUE WITH THE SELECTED DATE.
                            controller.$setViewValue(dt);
    
                        });
                    },
                    dateFormat: "dd/mm/yy" // SET THE FORMAT.
                });
            }
    
            return {
                require: 'ngModel',
                link: link
            };
        });
    </script>
    

    As you can see in the view I have called the postdata function of the controller.This function internally uses msg variable.But view is not printing value of this variable.I am very new to Aj. Please help.

    • Liam
      Liam about 7 years
      What does I want to call controller function from view mean? This question is not clear
    • space earth
      space earth about 7 years
      I have postdata() function in my controller.I want to call this function from my view i.e. from HTML code.
  • bessarabov
    bessarabov about 10 years
    I'm extremely sorry, but this does not answer my question.
  • Sylvain Pineau
    Sylvain Pineau about 10 years
    Please explain why this postinst script does not answer your original question. I'm a bit puzzled now.
  • bessarabov
    bessarabov about 10 years
    I'm sorry that I haven't explain it in the proper manner. Your solution works fine and this is what I have implemented. But the docs say This generally means there is a problem with the Makefile. I understand this message that there is some other way to do it. And I want to find out what is the recomened way to do this task.
  • Sylvain Pineau
    Sylvain Pineau about 10 years
    The directory creation could be done in debian/rules which is the Makefile for debian packages. Since I didn't know your debian/rules I preferred to propose a solution based on a single file. But the chown command must be a post-installation process. debian/dirs should be avoided but my initial answer is perfectly fine. Please vote and accept it, thanks.
  • moritz
    moritz almost 8 years
    Does this require that the user and group exists on the system where the package is built? And if yes, is there a way to ensure that with a Debian-based mechanism?
  • space earth
    space earth about 7 years
    This thing is already I have done in my code.But it is not working
  • neptune
    neptune about 7 years
    @spaceearth if you resolved all the three issue I mentioned and still don't work, you should create an mcve to be easier to see what the problem is.
  • space earth
    space earth about 7 years
    I have tried that also,without using ng-controller="Allocation as vm",it prints function name as it is in output,like {{postdata(data.date)}}
  • anoop
    anoop about 7 years
    @spaceearth: you also need to inject $http in your controller, to make API calls, I edited my answer. check the fiddle link also
  • space earth
    space earth about 7 years
    I have seen your fiddle demo.But it is printing the Output Message,status code... empty.How to see console log in fiddle?
  • anoop
    anoop about 7 years
    @spaceearth : because I've commented the $http.post call, since I don't have your API. further if possible don't make post call on each iteration, try to accumulate your data and make 1 call
  • space earth
    space earth about 7 years
    I it is working.But it is continuously calling function.I want functionality like when submit button is called then only postData() function should be called. What should be done?
  • anoop
    anoop about 7 years
  • gerardw
    gerardw about 6 years
    This will create the directories on the system used to build the debian package, not the system the package is installed on.
  • kayn
    kayn over 3 years
    There is a typo. The ending should be postinst and not postint.
  • Alexis Wilke
    Alexis Wilke over 2 years
    @moritz Yes. That is the drawback of this technique. It needs to exist on both systems.
  • Alexis Wilke
    Alexis Wilke over 2 years
    I don't think that it makes sense to have a *.dirs and then use install -d ... since both create the directories. On my end, I simply use chown ... in the rules file.