about summary refs log tree commit diff stats
path: root/core/package.html
blob: 21415ae335d68cc600b701c11724bd94362fb503 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>2.4. Package Management</title>
    </head>
    <body>

        <a href="index.html">Core OS Index</a>

        <h1>2.4. Package Management</h1>

        <p>For more information read crux handbook Package management
        front-end:
        <a href="https://crux.nu/Handbook3-3#ntoc20">prt-get</a>
        and Introduction to
        <a href="https://crux.nu/Main/Handbook3-3#ntoc14">pkgutils</a>.</p>
        </p>


        <dl>
            <dt>pkgmk(8)</dt>

            <dd>Makes a software package. A package is an archive of
            files (.pkg.tar.gz, .pkg.tar.bz2 or  .pkg.tar.xz)
            that can be installed using pkgadd(8).</dd>

            <dt>pkgadd(8)</dt>

            <dd>install a software package. A package is an
            archive of files (.pkg.tar.gz).</dd>

            <dt>pkginfo(8)</dt>

            <dd>Displays information about software packages that
            are installed on the system or  that  reside  in  a
            particular directory.</dd>

            <dt>pkgrm(8)</dt>

            <dd>Removes/uninstalls a previously installed software
            packages.</dd>

            <dt>prt-get(8)</dt>

            <dd>prt-get is a package management tool which
            provides additional functionality to crux' package
            management system. It works with the local ports tree
            and is therefore fully compatible with ports(8) and
            pkgmk(8)/pkgadd(8)</dd>
        </dl>

        <p>Test configuration by runing prt-get as admin user installing
        ports that are related;</p>

        <pre>
        $ prt-get depinst prt-utils prt-get-bashcompletion
        </pre>

        <h2 id="sysup">2.4.1. Update System</h2>

        <p>Before build software get latest version of port collections;</p>

        <pre>
        $ sudo ports -u
        </pre>

        <p>When coming from install or there is to much updates, I prefer to
        update gcc, glibc, libtool and binutils before doing a sysup;</p>

        <pre>
        $ prt-get update gcc
        $ prt-get update glibc
        $ prt-get update libtool
        $ prt-get update binutils
        </pre>

        <p>Build and install updated versions of ports;</p>

        <pre>
        $ prt-get sysup
        </pre>

        <p>Rebuild any revision dependency;</p>

        <pre>
        $ prt-get update -fr $(revdep)
        </pre>

        <h2 id="depinst">2.4.2. Install port and dependencies</h2>

        <p>Installing using prt-get tool;</p>

        <pre>
        $ prt-get depinst git
        </pre>

        <p>Installing using pkgmk and pkgadd, first build the package;</p>

        <pre>
        $ cd /usr/ports/opt/git
        $ sudo -H -u pkgmk fakeroot pkgmk -d
        </pre>

        <p>Install the package;</p>

        <pre>
        $ sudo pkgadd /usr/ports/packages/git#2.9.3-1.pkg.tar.gz
        </pre>

        <p>If you user pkgmk and pkgadd allways check if README, pre and post 
        instal files exist.</p>

        <h3 id="ports">2.4.3. Ports collections</h3>

        <p>Clone this documentation;</p>

        <pre>
        $ git clone https://github.com/s1lvino/c9-doc.git
        </pre>

        <p>Install collections later documented;</p>

        <pre>
        $ sudo cp c9-doc/core/conf/ports/* /etc/ports/
        </pre>

        <p>Edit /etc/prt-get.conf to activate new collections;</p>

        <pre>
        # the following line enables the user maintained contrib collection
        prtdir /usr/ports/contrib

        # ports described on this documentation
        prtdir /usr/ports/c9-ports

        # 6c37 team provides a collection with freetype-iu, fontconfig-iu
        # and cairo-iu ports.
        prtdir /usr/ports/6c37-dropin
        prtdir /usr/ports/6c37
        </pre>

        <p>Get new ports;</p>

        <pre>
        $ sudo ports -u c9-ports
        $ sudo ports -u 6c37-dropin
        $ sudo ports -u 6c37
        </pre>

        <h2 id="info">2.4.4. Show port information</h2>

        <pre>
        $ prt-get info port_name
        </pre>

        <p>List files port install into system;</p>

        <pre>
        $ pkginfo -l package_name
        </pre>

        <p>Discover to wich port a file belongs;</p>

        <pre>
        $ pkginfo -o filename
        </pre>

        <h2 id="depends">2.4.5. Show port dependencies</h2>

        <pre>
        $ prt-get depends port_name
        </pre>

        <h2 id="printf">2.4.6. Print information</h2>

        <p>Example how to get ports installed from contrib. Maybe there is
        a "cleaner" way to this, for now is ok;</p>

        <pre>
        prt-get printf "%p %i %n %v\n" | grep "/usr/ports/contrib yes"
        </pre>

        <a href="index.html">Core OS Index</a>
        <p>This is part of the c9-doc Manual.
        Copyright (C) 2017
        c9 team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>

    </body>
</html>
                                                                                                                                           
 
                                                                    
              
                                                               
                               
                  














                                                                          
                                                                                                                                






                                                                                                  

                                                                                                                                
               
                                                        















                                                                                                                                      


                                            


                                                                                                                                




                 
                                                               












                                                                                                         

                                                                                 



                                               

                                                       







                                                  
bool Hide_warnings = false;

struct trace_stream {
  vector<pair<string, string> > past_lines;  // [(layer label, line)]
  // accumulator for current line
  ostringstream* curr_stream;
  string curr_layer;
  trace_stream() :curr_stream(NULL) {}
  ~trace_stream() { if (curr_stream) delete curr_stream; }

  ostringstream& stream(string layer) {
    newline();
    curr_stream = new ostringstream;
    curr_layer = layer;
    return *curr_stream;
  }

  // be sure to call this before messing with curr_stream or curr_layer
  void newline() {
    if (!curr_stream) return;
    string curr_contents = curr_stream->str();
    curr_contents.erase(curr_contents.find_last_not_of("\r\n")+1);
    past_lines.push_back(pair<string, string>(curr_layer, curr_contents));
    delete curr_stream;
    curr_stream = NULL;
  }

  string readable_contents(string layer) {  // missing layer = everything
    newline();
    ostringstream output;
    for (vector<pair<string, string> >::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
      if (layer.empty() || layer == p->first)
        output << p->first << ": " << with_newline(p->second);
    return output.str();
  }

  string with_newline(string s) {
    if (s[s.size()-1] != '\n') return s+'\n';
    return s;
  }
};

trace_stream* Trace_stream = NULL;

// Top-level helper. IMPORTANT: can't nest.
#define trace(layer)  !Trace_stream ? cerr /*print nothing*/ : Trace_stream->stream(layer)
// Warnings should go straight to cerr by default since calls to trace() have
// some unfriendly constraints (they delay printing, they can't nest)
#define raise  ((!Trace_stream || !Hide_warnings) ? cerr /*do print*/ : Trace_stream->stream("warn")) << __FILE__ << ":" << __LINE__ << " "

// raise << die exits after printing -- unless Hide_warnings is set.
struct die {};
ostream& operator<<(ostream& os, __attribute__((unused)) die) {
  if (Hide_warnings) return os;
  os << "dying\n";
  exit(1);
}

#define CLEAR_TRACE  delete Trace_stream, Trace_stream = new trace_stream;

#define DUMP(layer)  cerr << Trace_stream->readable_contents(layer)

// Trace_stream is a resource, lease_tracer uses RAII to manage it.
struct lease_tracer {
  lease_tracer() { Trace_stream = new trace_stream; }
  ~lease_tracer() { delete Trace_stream, Trace_stream = NULL; }
};

#define START_TRACING_UNTIL_END_OF_SCOPE  lease_tracer leased_tracer;

bool check_trace_contents(string FUNCTION, string FILE, int LINE, string layer, string expected) {  // empty layer == everything
  vector<string> expected_lines = split(expected, "");
  size_t curr_expected_line = 0;
  while (curr_expected_line < expected_lines.size() && expected_lines[curr_expected_line].empty())
    ++curr_expected_line;
  if (curr_expected_line == expected_lines.size()) return true;
  Trace_stream->newline();
  ostringstream output;
  for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
    if (!layer.empty() && layer != p->first)
      continue;
    if (p->second != expected_lines[curr_expected_line])
      continue;
    ++curr_expected_line;
    while (curr_expected_line < expected_lines.size() && expected_lines[curr_expected_line].empty())
      ++curr_expected_line;
    if (curr_expected_line == expected_lines.size()) return true;
  }

  ++Num_failures;
  cerr << "\nF " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << expected_lines[curr_expected_line] << "] in trace:\n";
  DUMP(layer);
  Passed = false;
  return false;
}

#define CHECK_TRACE_CONTENTS(...)  check_trace_contents(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)

int trace_count(string layer, string line) {
  Trace_stream->newline();
  long result = 0;
  for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
    if (layer == p->first)
      if (line == "" || p->second == line)
        ++result;
  }
  return result;
}

#define CHECK_TRACE_WARNS()  CHECK(trace_count("warn", "") > 0)
#define CHECK_TRACE_DOESNT_WARN() \
  if (trace_count("warn") > 0) { \
    ++Num_failures; \
    cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected warnings\n"; \
    DUMP("warn"); \
    Passed = false; \
    return; \
  }

bool trace_doesnt_contain(string layer, string line) {
  return trace_count(layer, line) == 0;
}

#define CHECK_TRACE_DOESNT_CONTAIN(...)  CHECK(trace_doesnt_contain(__VA_ARGS__))

vector<string> split(string s, string delim) {
  vector<string> result;
  string::size_type begin=0, end=s.find(delim);
  while (true) {
    if (end == string::npos) {
      result.push_back(string(s, begin, string::npos));
      break;
    }
    result.push_back(string(s, begin, end-begin));
    begin = end+delim.size();
    end = s.find(delim, begin);
  }
  return result;
}