# Cgit without webapp-config: possible? [SOLVED]

## halcon

Hi !

Why does cgit require webapp-config? I am not going to use it on virtual hosts. And I emerged it without vhosts USE flag. But, according to webapp.eclass, it means that I want "auto-installing using webapp-config" - I can't understand that logic.  :Question: 

----------

## alamahant

Not only cgit but many others like nextcloud wp phpmyadin etc.

Namely webapps.

This is Gentoo;s way of installing them.

I usually copy their directory from /usr/share to /var/www and create the conf file myself.

Then delete them

Or i directly go to their site and download the code from there.

But apparently cgit needs compiling.Its not only some web dir you can move around.It seems complicated....

----------

## Ionen

Not fond of the whole webapp system myself, just used my own ebuild back when I used cgit (but deleted that a while back, ended up hardly needing the web interface so I stopped running it).

----------

## halcon

alamahant, Ionen,

Thanks for your replies!

Yes, I've already understood that webapp-config is an old thing and that webapps-project does not have a lead...

I've recently had fun with making my own ebuild for cgit without dependency on webapp-config. It works, but I think I will correct it more while I'll be configuring cgit according to my needs (and while my needs will be growing  :Smile:  )

Please, if you notice anything wrong with my ebuild, especially related to the web security, tell me about that.

----------

## halcon

I wrote my first article in Gentoo Wiki about this topic.

Opinions, suggestions, corrections?

EDIT

It's funny, I've found only now that blog. Why didn't I find it earlier?  :Shocked: 

----------

## Hu

```
     1   # Copyright 1999-2021 Gentoo Authors
```

This line looks wrong to me.  The copyright start date is almost certainly wrong, since cgit is not that old.  The use of Gentoo Authors also seems strange, since as far as I know, you are not a Gentoo developer.

```
    55   src_prepare() {

    56      rmdir git || die
```

Does upstream actually ship an empty directory named git?

```
    59      echo "prefix = ${EPREFIX}/usr" >> cgit.conf

    60      echo "libdir = ${EPREFIX}/usr/$(get_libdir)" >> cgit.conf

    61      echo "CGIT_SCRIPT_PATH = ${MY_DIRS[CGIBINDIR]}" >> cgit.conf

    62      echo "CGIT_DATA_PATH = ${MY_DIRS[HTDOCSDIR]}" >> cgit.conf

    63      echo "CACHE_ROOT = ${MY_EMPTY_DIRS[CACHEDIR]}" >> cgit.conf

    64      echo "DESTDIR = ${D}" >> cgit.conf

    65      if use lua; then

    66         echo "LUA_PKGCONFIG = ${ELUA}" >> cgit.conf

    67      else

    68         echo "NO_LUA = 1" >> cgit.conf

    69      fi
```

This is a common, but suboptimal, pattern.  If you move the echo statements into a braced expression, you can have a single redirect for the entire expression.  Alternatively, for the first part at least, you could have a single multiline echo.

Telling the upstream build system about DESTDIR at the prepare phase is rather unusual.  Is this needed?

```
    76   src_compile() {

    77      emake V=1 AR="$(tc-getAR)" CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"

    78      use doc && emake V=1 doc-man
```

If you look up the default target for a make that does not specify one, then you could combine these two calls into a single make:

```
   set --

   use doc && set -- doc-man

   emake V=1 AR="$(tc-getAR)" CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" insert_upstream_default_make_target_here "$@"
```

```
    81   src_install() {

    82      local MY_DIR_KEY MY_EMPTY_DIR_KEY MY_DIR_VALUE MY_EMPTY_DIR_VALUE

    83      for MY_DIR_KEY in "${!MY_DIRS[@]}"; do

    84         MY_DIR_VALUE="${MY_DIRS[$MY_DIR_KEY]}"
```

This looks unnecessarily convoluted.  Since you only use the key to get the value, you could simplify this by having the shell assign the value to your iteration variable, so that you do not need a separate lookup to get the value.

```
    94      emake V=1 AR="$(tc-getAR)" CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" install
```

Does the install target need the toolchain variables again?  It should not be building anything at this point in the ebuild.

```
   112      for MY_EACH_DIR in "${MY_ALL_DIRS[@]}"; do

   113         if use nginx; then

   114            fowners -R nginx:nginx "${MY_EACH_DIR}"

   115         else

   116            fowners -R "${PN}":"${PN}" "${MY_EACH_DIR}"

   117         fi

   118         fperms 700 "${MY_EACH_DIR}"

   119      done
```

This could be simplified by moving the use nginx test out of the loop, and using it to set a variable to either nginx:nginx or $PN:$PN, as appropriate.  Then, inside the loop, pass that variable to fowners for the user/group value.

----------

## halcon

Hi, Hu!

Thank you a lot for your reply!

I haven't written this ebuild from scratch, I used the one from the main tree.

 *Hu wrote:*   

> 
> 
> ```
>      1   # Copyright 1999-2021 Gentoo Authors
> ```
> ...

 

Yes, really, "1999" could be replaced for another year. I've looked at other ebuilds in my overlay now, and I see that it is very common. Many other programs look not so old.

Regarding "Gentoo Authors": interesting, I see now that I don't know exactly what this term means. "Gentoo Foundation" is, sure, an organization. But who are "Gentoo Authors"? I naively assumed that it is a collective reference of everybody contributing to Gentoo: developers, users...

The same "Gentoo Authors" is written in all ebuilds in my overlay, including the first my ebuild for drm-master-utils that was written piece-by-piece by suggestions from you, fedeliallalinea, GDH-Gentoo and others. Sure that I am not a Gentoo developer. As far as I know, GDH-Gentoo is not either. Why do you raise this matter only now?

 *Hu wrote:*   

> 
> 
> ```
>     55   src_prepare() {
> 
> ...

 

Yes, it does.

 *Hu wrote:*   

> 
> 
> ```
>     59      echo "prefix = ${EPREFIX}/usr" >> cgit.conf
> 
> ...

 

Yes, indeed, multiple lines could be combined in one.

 *Hu wrote:*   

> Telling the upstream build system about DESTDIR at the prepare phase is rather unusual.  Is this needed?
> 
> ```
>     76   src_compile() {
> 
> ...

 

Hmm, I need to think about it.

 *Hu wrote:*   

> 
> 
> ```
>     81   src_install() {
> 
> ...

 

Do you mean I could get rid of the variable MY_DIR_VALUE? There was no this variable in my code before, but then I added it because I used to do that in my perl programs when a call to $hash->{$key} is repeated at least twice, because it is easier to make an error typing a longer variable name (1), and to shorten the lines (when there are nested hashes $hash->{$key1}{$key2}{$key3}{$key4}, lines are too long and look less readable)...(2) and it can work slower, by the way (if I am not mistaken).

 *Hu wrote:*   

> 
> 
> ```
>     94      emake V=1 AR="$(tc-getAR)" CC="$(tc-getCC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" install
> ```
> ...

 

I need to think about it too.

 *Hu wrote:*   

> 
> 
> ```
>    112      for MY_EACH_DIR in "${MY_ALL_DIRS[@]}"; do
> 
> ...

 

Yes, agreed!

EDIT

I'd like to be sure: do I understand correctly that everybody can create "own user pages" USERNAME/something on Gentoo Wiki, as I did, or is it intended for Gentoo developers only? Haven't I violated any rules?

----------

## Hu

 *halcon wrote:*   

> Yes, really, "1999" could be replaced for another year. I've looked at other ebuilds in my overlay now, and I see that it is very common. Many other programs look not so old.

 This is probably just copied from one ebuild to another as boilerplate, then.  No one cares about making it accurate, and by its nature tools cannot verify it to be correct. *halcon wrote:*   

> Regarding "Gentoo Authors": interesting, I see now that I don't know exactly what this term means. "Gentoo Foundation" is, sure, an organization. But who are "Gentoo Authors"? I naively assumed that it is a collective reference of everybody contributing to Gentoo: developers, users...

 I don't know.  I expect it would refer to the Gentoo maintainers who have access to the main tree, but that is just a guess. *halcon wrote:*   

> Why do you raise this matter only now?

 I probably never noticed it, or never thought about it.  I don't always do line-by-line reviews. *halcon wrote:*   

> Do you mean I could get rid of the variable MY_DIR_VALUE? There was no this variable in my code before, but then I added it because I used to do that in my perl programs when a call to $hash->{$key} is repeated at least twice, because it is easier to make an error typing a longer variable name (1), and to shorten the lines (when there are nested hashes $hash->{$key1}{$key2}{$key3}{$key4}, lines are too long and look less readable)...(2) and it can work slower, by the way (if I am not mistaken).

 You are correct, but you are approaching the problem from the wrong direction.  In Perl, if you do not need the key, you would foreach over the values of the hash, so that you never need to explicitly read from the hash at all.  Consider:

```
declare -A arr

arr[a]=b

arr[c]=d

for k in "${!arr[@]}"; do

   echo "k=$k arr[k]=${arr[$k]}"

done

for v in "${arr[@]}"; do

   echo "v=$v"

done
```

Both loops obtain the values from the array.  The second does not explicitly mention the key, and instead lets the shell handle the key implicitly.  The second loop has no access to the key, which could be a problem for some loops.  However, for your loops as written, I think this limitation is acceptable. *halcon wrote:*   

> I'd like to be sure: do I understand correctly that everybody can create "own user pages" USERNAME/something on Gentoo Wiki, as I did, or is it intended for Gentoo developers only? Haven't I violated any rules?

 I do not know.  I would expect that such a rule should be enforced in the permissions system, if the rule existed.  Enforcing it in software would be easier than expecting everyone to know not to do that.

----------

## halcon

 *Hu wrote:*   

> 
> 
> ```
> declare -A arr
> 
> ...

 

Yeah. You are right, as always  :Smile: 

I fixed this and some of other issues that you found.

 *Hu wrote:*   

>  *halcon wrote:*   I'd like to be sure: do I understand correctly that everybody can create "own user pages" USERNAME/something on Gentoo Wiki, as I did, or is it intended for Gentoo developers only? Haven't I violated any rules? I do not know.  I would expect that such a rule should be enforced in the permissions system, if the rule existed.  Enforcing it in software would be easier than expecting everyone to know not to do that.

 

Well, almost 24 hours have passed and my page hasn't been removed, so, there are chances, it is all right  :Rolling Eyes: 

----------

## halcon

I don't quite understand. Please elaborate.

----------

## Hu

 *halcon wrote:*   

> I don't quite understand. Please elaborate.

 The post to which you responded is the first post for that account.  Between that, the extremely generic nature of the response, and that the response is still a non-sequitur despite being generic, it is likely that it is a placeholder for spam to be edited in later.

----------

## halcon

 *Hu wrote:*   

> the first post for that account...extremely generic nature of the response

 

Thank you for the reminder. I had noticed both these details. I was interested if he would elaborate or not  :Smile: 

----------

