diff --git a/conf/gitweb.conf b/conf/gitweb.conf index 1ba84cd..19806fe 100644 --- a/conf/gitweb.conf +++ b/conf/gitweb.conf @@ -1,9 +1,15 @@ # path to git projects (.git) $projectroot = "/home/git/repositories/"; +# default order is "project" - I prefer sorting by age, altough it's more CPU intensive +$default_projects_order = "age"; + # directory to use for temp files $git_temp = "/tmp"; +# site name shown at the page title +#$site_name = "Git trees"; + # target of the home link on top of all pages #$home_link = $my_uri || "/"; @@ -11,7 +17,7 @@ $git_temp = "/tmp"; #$home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. -$projects_list = "/home/git/projects.list"; +#$projects_list = "/home/git/projects.list"; # stylesheet to use #@stylesheets = ("static/gitweb.css"); @@ -25,6 +31,56 @@ $projects_list = "/home/git/projects.list"; # the 'favicon' #$favicon = "static/git-favicon.png"; +# this prevents gitweb to show hidden repositories +#$export_ok = "git-daemon-export-ok"; +#$strict_export = 1; +# and this prevents gitweb to show any repository that doesn't have a file named 'gitweb-export-ok' +#$export_ok = "gitweb-export-ok"; + +# This lets it make the URLs you see in the header +#@git_base_url_list = ( 'git://' ); # git-diff-tree(1) options to use for generated patches #@diff_opts = ("-M"); -@diff_opts = (); \ No newline at end of file +@diff_opts = (); + +# Enable PATH_INFO so the server can produce URLs of the +# form: http://example.org/domain/project.git/xxx/xxx +# This allows for pretty URLs *within* the Git repository, +# also needs the Apache rewrite rules for full effect. +#$feature{'pathinfo'}{'default'} = [1]; + +# Neat way of prefixing the top URL listing +#our @extra_breadcrumbs = ( +# [ 'Site title or whatever' => 'http://example.org/' ], +# ); + +# List avatars next to committers +#$feature{'avatar'}{'default'} = ['gravatar']; + +# The category name is read from .git/category, in the same manner as .git/description. +#$projects_list_group_categories = 1; +#$project_list_default_category = "misc"; + +$projects_list_description_width = 80; + +# Enable blame, pickaxe search, snapshop, search, and grep +# support, but still allow individual projects to turn them off. +# These are features that users can use to interact with your Git trees. They +# consume some CPU whenever a user uses them, so you can turn them off if you +# need to. Note that the 'override' option means that you can override the +# setting on a per-repository basis. +$feature{'blame'}{'default'} = [1]; +$feature{'blame'}{'override'} = [1]; + +$feature{'pickaxe'}{'default'} = [1]; +$feature{'pickaxe'}{'override'} = [1]; + +$feature{'snapshot'}{'default'} = [1]; +$feature{'snapshot'}{'override'} = [1]; + +$feature{'search'}{'default'} = [1]; + +$feature{'grep'}{'default'} = [1]; +$feature{'grep'}{'override'} = [1]; + +$feature{'highlight'}{'default'} = [1]; diff --git a/conf/nginx.conf b/conf/nginx.conf index 4944fbb..42eb956 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,12 +1,30 @@ -location YNH_NGINX_PATH/index.cgi { - root /var/www/; +location YNH_WWW_PATHindex.cgi { + root YNH_APP_PATH; include fastcgi_params; gzip off; fastcgi_param SCRIPT_NAME $uri; fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; fastcgi_pass unix:/var/run/fcgiwrap.socket; } -location YNH_NGINX_PATH { - root /var/www/; +location YNH_WWW_PATH { + root YNH_APP_PATH; index index.cgi; -} \ No newline at end of file +} + +# static repo files for cloning over https +location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { + root YNH_GIT_PROJECT_ROOT; +} + +# requests that need to go to git-http-backend +location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { + root /home/git/repositories; + + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; + fastcgi_param PATH_INFO $uri; + fastcgi_param GIT_PROJECT_ROOT YNH_GIT_PROJECT_ROOT; + fastcgi_param GIT_HTTP_EXPORT_ALL ""; + fastcgi_param REMOTE_USER $remote_user; + include fastcgi_params; +} diff --git a/manifest.json b/manifest.json index e3dbdca..cfd9c81 100644 --- a/manifest.json +++ b/manifest.json @@ -1,19 +1,30 @@ { "name": "Gitweb", "id": "gitweb", + "packaging_format": 1, + "url": "https://github.com/rigelk/gitweb_ynh", "description": { "en": "Web interface to see gitolite repositories", "fr": "Une interface web pour consulter les dépôts gitolite" }, - "developer": { - "name": "Matlink", - "email": "matlink@matlink.fr" + "maintainer": { + "name": "rigelk", + "email": "par@rigelk.eu", + "url": "https://rigelk.eu" }, - "multi_instance": "false", + "requirements": { + "yunohost": ">> 2.5.4" + }, + "license": "free", + "services": [ + "nginx" + ], + "multi_instance": false, "arguments": { "install" : [ { "name": "domain", + "type": "domain", "ask": { "en": "Choose a domain for Gitweb", "fr": "Choisissez un domaine pour Gitweb" @@ -22,6 +33,7 @@ }, { "name": "path", + "type": "path", "ask": { "en": "Choose a path for Gitweb", "fr": "Choisissez un chemin pour Gitweb" @@ -29,22 +41,33 @@ "example": "/gitweb", "default": "/gitweb" }, + { + "name": "git_project_root", + "type": "path", + "ask": { + "en": "Choose an existing git project root for Gitweb", + "fr": "Choisissez un chemin existant où chercher vos projects git pour Gitweb" + }, + "example": "/home/git/repositories", + "default": "/home/git/repositories" + }, { "name": "admin", + "type": "user", "ask": { - "en": "Choose an admin user for Gitweb", + "en": "Choose an admin for Gitweb", "fr": "Choisissez un administrateur pour Gitweb" }, "example": "homer" }, { - "name": "public_site", + "name": "is_public", + "type": "boolean", "ask": { "en": "Should this application be public ?", "fr": "Est-ce que cette application doit être visible publiquement ?" }, - "choices": ["Yes", "No"], - "default": "No" + "default": true } diff --git a/scripts/install b/scripts/install index 93b82aa..e819d0c 100644 --- a/scripts/install +++ b/scripts/install @@ -1,43 +1,62 @@ #! /bin/bash +set -eu -app=gitweb +# Source app helpers +. /usr/share/yunohost/helpers -domain=$1 -path=$2 -admin=$3 -is_public=$4 -final_path=/var/www$path +# This is a single instance app +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN +is_public=$YNH_APP_ARG_IS_PUBLIC +git_project_root=$YNH_APP_ARG_GIT_PROJECT_ROOT + +final_path=/var/www/$app # Check domain/path availability -sudo yunohost app checkurl $domain$path -a $app -if [[ ! $? -eq 0 ]]; then - echo "Path of the domain is not available" - exit 1 -fi +sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ +|| ynh_die "Path not available: ${domain}${path_url}" # Check user sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" if [[ ! $? -eq 0 ]]; then echo "Error : the chosen admin user does not exist" - exit 1 + ynh_die 1 fi # Check /var/www/$app path is available if [ -f $final_path ]; then echo "This path already contains a folder" - exit 1 + ynh_die 1 fi +# Check directories +[[ -d $final_path ]] && ynh_die \ +"The destination directory '$final_path' already exists.\ + You should safely delete it before installing this app." +[[ ! -d $git_project_root ]] && ynh_die \ +"The git project root directory '$git_project_root' doesn't exist.\ + You should safely create it/choose another before installing this app." + +# Check user parameter +ynh_user_exists "$admin" \ + || ynh_die "The chosen admin user does not exist." + # Save app settings -sudo yunohost app setting $app admin -v "$admin" -sudo yunohost app setting $app is_public -v "$is_public" -sudo yunohost app setting $app final_path -v "$final_path" +ynh_app_setting_set $app admin "$admin" +ynh_app_setting_set $app is_public "$is_public" +ynh_app_setting_set $app final_path "$final_path" -echo "Updating apt ..." +# Installing packages +echo "Updating apt package db..." sudo apt-get -qq update echo "Installing dependancies ..." sudo apt-get install -qqy fcgiwrap gitweb >/dev/null 2>&1 +# Adding user www-data to group git sudo adduser www-data git sudo cp ../conf/gitweb.conf /etc/gitweb.conf @@ -46,18 +65,19 @@ sudo chmod 644 /etc/gitweb.conf sudo ln -s /usr/share/gitweb $final_path sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s,YNH_NGINX_PATH,$path,g" /etc/nginx/conf.d/$domain.d/$app.conf +sudo sed -i "s@YNH_WWW_PATH@$path_url@g" /etc/nginx/conf.d/$domain.d/$app.conf +sudo sed -i "s@YNH_APP_PATH@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf +sudo sed -i "s@YNH_GIT_PROJECT_ROOT@$git_project_root@g" /etc/nginx/conf.d/$domain.d/$app.conf sudo chown root: /etc/nginx/conf.d/$domain.d/$app.conf sudo chmod 600 /etc/nginx/conf.d/$domain.d/$app.conf - -sudo yunohost app addaccess $app -u $admin +sudo yunohost app addaccess --users="$admin" $app # If app is public, add url to SSOWat conf as skipped_uris -if [ "$is_public" = "Yes" ]; -then - sudo yunohost app setting $app skipped_uris -v "/" +if [[ $is_public -eq 1 ]]; then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" fi -sudo service nginx restart -sudo yunohost app ssowatconf \ No newline at end of file +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 7253ae9..75496f2 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,9 +1,13 @@ #! /bin/bash +set -u -app=gitweb +# Source app helpers +. /usr/share/yunohost/helpers -domain=$(sudo yunohost app setting $app domain) -final_path=$(sudo yunohost app setting $app final_path) +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_set $app domain) +final_path=$(ynh_app_setting_set $app final_path) sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf sudo rm -rf $final_path -sudo deluser www-data git \ No newline at end of file +sudo deluser www-data git