File: toolbox

package info (click to toggle)
partclone 0.3.36%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,276 kB
  • sloc: ansic: 136,343; sh: 4,828; xml: 2,106; makefile: 501; asm: 383; perl: 106; sed: 16
file content (220 lines) | stat: -rwxr-xr-x 4,724 bytes parent folder | download
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#! /bin/bash

##  toolbox for the Partclone
##  initial copied from VLC
##  Authors: thomas thomas at nchc dot org dot tw 

###
###  Get a sane environment, just in case
###
LC_ALL=C
export LC_ALL
LANG=C
export LANG

##
##  Give help
##
help()
{
  cat << EOF
recognized flags are:
  --update-po             update translation files
  --update-log            update Changelog files from git
  --update-btrfs          update source of btrfs
    eg:
    ./toolbox --update-btrfs /tmp/partclone /tmp/btrfs-progs v6.8
  --update-version        generate src/version.h
EOF
  exit 1
}

##
## update btrfs
##

btrfs_update(){
    partcloneGitRepo=$1
    btrfsprogsGitRepo=$2
    tag=$3
    echo $@ $tag $partcloneGitRepo $btrfsprogsGitRepo
    
    pushd $partcloneGitRepo/src/
        btrfs_files=$(find btrfs -name "*.h" -o -name "*.c")
    popd
    echo $btrfs_files
    
    pushd $btrfsprogsGitRepo
    
        git checkout -b $tag $tag
        ./autogen.sh
        ./configure --disable-documentation 
        make
    
        cat libbtrfs/version.h
    
        set -e
        for source_file in $btrfs_files; do 
            echo $source_file
            btrfs_file=$(echo $source_file | sed s/^btrfs//)
            source_file_path=$(echo "$partcloneGitRepo/src/$source_file" | sed "s#//#/#g")
            btrfs_file_path=$(echo "$btrfsprogsGitRepo/$btrfs_file" | sed "s#//#/#g")
    
            if test -f "$btrfs_file_path"; then
                source_md5=$(md5sum -z $source_file_path |sed 's/ .*//')
                btrfs_md5=$(md5sum -z $btrfs_file_path |sed 's/ .*//')
    
                if [ "X$source_md5" != "X$btrfs_md5" ]; then
                    echo "cp $btrfs_file_path $source_file_path"
                    cp $btrfs_file_path $source_file_path
                else
                    echo "keep $source_file"
                fi
                echo "MD5: $source_md5 : $btrfs_md5"
            else
                echo "######"
                echo "can't find $source_file in $btrfs_file_path"
                echo "manually merge file!"
                find $btrfsprogsGitRepo -name `basename $source_file`
                echo "######"
            fi
    
        done
    
    popd
}

###
###  argument check
###

if test "$1" = ""
then
  help
fi

case "$1" in
  --update-po)
    action=po
    ;;
  --update-btrfs)
    action=btrfs
    ;;
  --update-log)
    action=changelog
    ;;
  --update-version)
    action=version
    ;;
  --help)
    help
    ;;
  *)
    echo "$0: unknown option $1"
    help
    ;;
esac
shift

##
##  Update the potfiles because no one ever does it
##
if test "${action}" = "po"
then
  # find out the source files
  echo "WARNING: you should run \"make update-po\" instead!" >&2
  cd po
  make update-po
  exit $?
fi

##
##  Update the source of btrfs
##

if test "${action}" = "btrfs"
then
    echo "btrfs sync parameters $@"
    btrfs_update $@
fi

##
## update Changelog from SVN
##
#if test "${action}" = "changelog"
#then
#  echo "Would you want to export svn log to ChangeLog(y/N)?"
#  read log
#  case "$log" in  
#    [yY] | [Yy][Ee][Ss] )
#      if which svn2cl 2>&1 >/dev/null ; then
#        echo "please input svn password to export svn log."
#        svn2cl --reparagraph --break-before-msg=2
#      else
#        echo "WARNING: you should install subversion-tools firstly."
#      fi
#      ;;
#    esac
#  exit $?
#fi
#

##
##  Create version file
##
if test "${action}" = "version"
then
  scriptdir=`dirname "$0"`
  file="$scriptdir/src/version.h"
  GIT_REPOSITORY=`git remote -v | grep partclone`
  GIT_REVISION=`git describe --abbrev=7 --always --tags`
  git_ver="none"

  if [ "${GIT_REPOSITORY}" = "" ];
  then
    echo "not git repository?"
    exit 0
  fi

  #if [ "${GIT_REVISION_UPSTREAM}" != "" ]; then
  #    git_ver=$GIT_REVISION_UPSTREAM
  #el
  if [ "${GIT_REVISION}" != "" ]; then
      git_ver=$GIT_REVISION
  else
      git_ver="none"
  fi

  if [ "$git_ver" != "none" ];
  then

cat > ${file}.tmp << EOF
/* DO NOT EDIT THIS FILE - IT IS REGENERATED AT EVERY COMPILE -
 * IT GIVES BETTER TRACKING OF DEVELOPMENT VERSIONS
 * WHETHER THEY ARE BUILT BY OTHERS OR DURING DEVELOPMENT OR FOR THE
 * OFFICIAL PARTCLONE RELEASES.
 */
#define git_version  "${git_ver}"

EOF
  # Do not modify the version file if the content did not change
  diff ${file}.tmp ${file} > /dev/null
  if [ "$?" != "0" ]
  then
    echo "update ${file}"
    mv ${file}.tmp ${file}
  else
    rm ${file}.tmp
  fi
  fi

  exit 0

fi

if test "${action}" = "changelog"
then
    # get source code from Jim Meyering at 
    # http://git.mymadcat.com/index.php/p/tracker/source/tree/master/gitlog-to-changelog
    perl gitlog-to-changelog --since 1999-01-01 > ChangeLog
fi