buildsystem 6.1 KB
Newer Older
1
#!/bin/bash
Manuel Tortosa's avatar
Manuel Tortosa committed
2

3
# bulidsystem: Shared functions for the Akabei Build System
Manuel Tortosa's avatar
Manuel Tortosa committed
4
#
5 6 7
# Copyright © 2015       Samir Benmendil <chakra@rmz.io>
# Copyright © 2014-2015  Luca Giambonini <almack[at]chakraos[dot]org>
# Copyright © 2011-2012  Manuel Tortosa <manutortosa[at]chakra-project[dot]org>
Manuel Tortosa's avatar
Manuel Tortosa committed
8
#
9 10 11 12
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
13
#
14 15 16 17
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
18
#
19 20
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
21

Manuel Tortosa's avatar
Manuel Tortosa committed
22
# checks remotelly for the actual list of available repositories
23
check_available_repos() {
24
  msg "searching for «$1»"
25
  local repo_exist="false"
26
  local checktr=$(ssh $_ssh_user@$_rsync_server -p $_ssh_port "cd packages && ls -d */ | cut -f1 -d'/'")
27 28

  if [ "$checktr" != "" ] ; then
29 30
    for _repo_check in $checktr ; do
      if [ "$_repo_check" = "$1" ] ; then
31 32 33
        repo_exist="true"
      fi
    done
34
    if [ "$repo_exist" != "true" ] ; then
35
      newline
36
      error "the repo «$1» does not exists"
37 38 39 40 41 42 43
      error "$(echo "$checktr" | sed 's/ok+/available repos:/g')"
      newline
      exit 1
    fi
  else
    newline
    error "unable to check available repos"
44
    if [ "$checktr" != "" ] ; then
45
      error "$checktr"
46
    fi
47 48 49
    newline
    exit 1
  fi
50 51
}

Manuel Tortosa's avatar
Manuel Tortosa committed
52
# determine the final target repository
Manuel Tortosa's avatar
Manuel Tortosa committed
53
handle_target() {
54 55 56
  if [ "$_dest" != "" ] ; then
    check_available_repos "$_dest"
    _final_dest=$_dest
57
  else
58
    _final_dest=$_cur
59
  fi
Manuel Tortosa's avatar
Manuel Tortosa committed
60 61
}

Manuel Tortosa's avatar
Manuel Tortosa committed
62
# performs a clean over a remote repository
63
repo_clean() {
64
  newline
65 66
  status_start "cleaning «$1-$(get_arch)»"
  local clean=$(ssh $_ssh_user@$_rsync_server -p $_ssh_port "akbm --repo-name $1 --arch $(get_arch) --repo-clean" 2>&1 | tee /dev/tty)
67

68
  if [[ "$clean" == *"::SUCCESS::"* ]]; then
69 70 71
    status_done
  else
    status_fail
72
    error "$clean"
73
  fi
74 75
}

76 77
# performs a clean over a local repository
local_repo_clean() {
78
  newline
79
  status_start "cleaning «local-$CHROOT.db.tar»"
80 81

  # remove current database, then recreate an empty one and add local pkgs if present
82 83 84
  rm ~/_repo/$CHROOT/local-$CHROOT.db.tar &>/dev/null
  tar cvf ~/_repo/$CHROOT/local-$CHROOT.db.tar --files-from /dev/null
  repo-add ~/_repo/$CHROOT/local-$CHROOT.db.tar *.pkg.tar.*z &>/dev/null
85 86

  status_done
87 88
}

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
# takes a list of find patterns and transform it into arguments to find
find_args() {
  local -a fargs=("-name" "$(glob $1)"); shift
  while [[ $# -gt 0 ]]; do
    fargs+=("-o" "-name" "$(glob $1)"); shift
  done
  echo "${fargs[@]}"
}

# checks whether $1 contains a globbing pattern
# returns: '$1' or '*$1*'
glob() {
  if [[ "$1" =~ [][*?] ]]; then
    echo -n "$1"
  else
    echo -n "*$1*"
  fi
}

Manuel Tortosa's avatar
Manuel Tortosa committed
108
# stablish the working repository and the folder for storing any uploaded package
109
set_repos_and_sync_folder() {
110
  for cr in core desktop lib32 gtk; do
111 112
    if [ "$(echo "$_cur_repo" | cut -d- -f1)" == $cr ] ; then
      _cur=$(echo "$_cur_repo" | cut -d- -f2)
113
    fi
114 115
    if [ "$(echo "$_dest_repo" | cut -d- -f1)" == $cr ] ; then
      _dest=$(echo "$_dest_repo" | cut -d- -f2)
116
    fi
117 118 119 120 121 122 123
  done
  if [ "$_cur" = "" ] ; then
    _cur=$_cur_repo
  fi
  if [ "$_dest" = "" ] ; then
    _dest=$_dest_repo
  fi
124 125 126 127
  if [ "$_cur" = "testing" ] ; then
    _sync_folder="_testing-$_sarch/"
  elif [ "$_cur" = "unstable" ] ; then
    _sync_folder="_unstable-$_sarch/"
128 129 130
  else
    _sync_folder="_repo/remote/"
  fi
131 132
}

133 134 135 136
upload_files() {
  local repo=$1; shift    # repostitory to upload to
  local -a files=( $* )   # files to upload

Samir Benmendil's avatar
Samir Benmendil committed
137 138 139 140 141 142
  rsync -rltoDvh \
    --omit-dir-times  \
    --numeric-ids \
    --progress \
    --delay-updates \
    -e "ssh -p $_ssh_port" \
totte's avatar
totte committed
143
    "${files[@]}" $_ssh_user@$_rsync_server:/srv/www/rsync.chakralinux.org/packages/$repo/$(get_arch)/
Manuel Tortosa's avatar
Manuel Tortosa committed
144 145
}

146 147
# remotely sign the database
# TODO: check the agent socket is passed and working
Samir Benmendil's avatar
Samir Benmendil committed
148
sign_online_database() {
149 150
  # remove current signature file and remotely execute gpg --detach-sign command to sign the databases
  # enable verbose to indicate the procedure
Chaoting Liu's avatar
Chaoting Liu committed
151
  local _remote_socket=$(ssh ${_ssh_user}@${_rsync_server} -p ${_ssh_port} gpgconf --list-dir agent-socket)
152
  status_start 'remotely signing the database \n'
153 154 155 156 157
  for ext in gz xz; do
  ssh -R${_remote_socket}:$(gpgconf --list-dir agent-socket) $_ssh_user@$_rsync_server -p $_ssh_port \
    gpg --batch --detach-sign packages/$1/$(get_arch)/$1.db.tar.$ext
  done
  newline
158
  status_done
159 160
}

161
sign_online_pkg() {
162
  # remotely execute gpg --detach-sign command to sign the package
Chaoting Liu's avatar
Chaoting Liu committed
163
  local _remote_socket=$(ssh ${_ssh_user}@${_rsync_server} -p ${_ssh_port} gpgconf --list-dir agent-socket)
164
  status_start "remotely signing the pkg $2 \n"
165 166
  ssh $_ssh_user@$_rsync_server -R${_remote_socket}:$(gpgconf --list-dir agent-socket) -p $_ssh_port \
    gpg -v --batch --detach-sign "packages/$1/$(get_arch)/$2"
167
  newline
168 169 170
  status_done
}

Manuel Tortosa's avatar
Manuel Tortosa committed
171
# copies the files from the temporary folder to a given folder and performs a repo-clean there
Samir Benmendil's avatar
Samir Benmendil committed
172 173 174 175 176 177 178 179 180
move_to_cache() {
  if [[ $# -eq 0 ]]; then
    error "No packages given."
    exit 1
  fi
  local cache=/var/cache/pacman/pkg
  msg "Moving packages to «$cache»"
  sudo -v
  sudo mv $* $cache
Manuel Tortosa's avatar
Manuel Tortosa committed
181 182
}

Luca Giambonini's avatar
Luca Giambonini committed
183 184
# performs a remote lock over a repository
lock_repo() {
185
  newline
186 187
  status_start "locking «$1-$(get_arch)»"
  local lock=$(ssh $_ssh_user@$_rsync_server -p $_ssh_port "akbm --repo-name $1 --arch $(get_arch) --lock" 2>&1 | tee /dev/tty)
188

189
  if [[ "$lock" == *"::SUCCESS::"* ]]; then
190
    status_done
191
    return 0
192 193
  else
    status_fail
194
    error "$lock"
195
    return 1
196
  fi
Luca Giambonini's avatar
Luca Giambonini committed
197 198 199 200
}

# performs a remote unlock over a repository
unlock_repo() {
201
  newline
202 203
  status_start "unlocking «$1-$(get_arch)»"
  local unlock=$(ssh $_ssh_user@$_rsync_server -p $_ssh_port "akbm --repo-name $1 --arch $(get_arch) --unlock" 2>&1 | tee /dev/tty)
204

205
  if [[ "$unlock" == *"::SUCCESS::"* ]]; then
206 207 208
    status_done
  else
    status_fail
209
    error "$unlock"
210 211
  fi
}
212 213

# vim: set et sw=2 ts=2: