@@ -45,37 +45,6 @@ file_is_available() {
4545 esac
4646}
4747
48- case " ${DBSYNC_REV:- " " } " in
49- " " )
50- echo " The value for DBSYNC_REV cannot be empty" >&2
51- exit 1
52- ;;
53-
54- " master" | " HEAD" )
55- export DBSYNC_REV=" master"
56-
57- if [ ! -e cardano-db-sync ]; then
58- git clone --depth 1 https://github.com/IntersectMBO/cardano-db-sync.git
59- fi
60-
61- cd cardano-db-sync || exit 1
62- git fetch origin master
63- ;;
64-
65- * )
66- if [ ! -e cardano-db-sync ]; then
67- git clone https://github.com/IntersectMBO/cardano-db-sync.git
68- fi
69-
70- cd cardano-db-sync || exit 1
71- git fetch
72- ;;
73- esac
74-
75- git stash
76- git checkout " $DBSYNC_REV "
77- git rev-parse HEAD
78-
7948DBSYNC_TAR_URL=" ${DBSYNC_TAR_URL:- " " } "
8049
8150# Check if DBSYNC_TAR_URL is empty and DBSYNC_REV is a version number
@@ -88,29 +57,62 @@ if [[ -z "$DBSYNC_TAR_URL" && "$DBSYNC_REV" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
8857 fi
8958fi
9059
91-
9260if [ -n " $DBSYNC_TAR_URL " ]; then
9361 # download db-sync
94- DBSYNC_TAR_FILE=" $WORKDIR /dbsync_bins.tar.gz"
62+ mkdir -p cardano-db-sync && cd cardano-db-sync || exit 1
63+ DBSYNC_TAR_FILE=" $PWD /dbsync_bins.tar.gz"
9564 curl -sSL " $DBSYNC_TAR_URL " > " $DBSYNC_TAR_FILE " || exit 1
96- rm -rf " ${WORKDIR } /dbsync_download"
97- mkdir -p " ${WORKDIR } /dbsync_download/"
98- tar -C " ${WORKDIR } /dbsync_download/" -xzf " $DBSYNC_TAR_FILE " || exit 1
65+ rm -rf " ${PWD } /dbsync_download"
66+ mkdir -p " ${PWD } /dbsync_download/"
67+ tar -C " ${PWD } /dbsync_download/" -xzf " $DBSYNC_TAR_FILE " || exit 1
9968 rm -f " $DBSYNC_TAR_FILE "
10069 rm -f db-sync-node
101- ln -s " ${WORKDIR } /dbsync_download" db-sync-node || exit 1
70+ ln -s " ${PWD } /dbsync_download" db-sync-node || exit 1
10271 rm -f smash-server || rm -f smash-server/bin/cardano-smash-server
10372 mkdir -p smash-server/bin
104- ln -s " ${WORKDIR} /dbsync_download/bin/cardano-smash-server" smash-server/bin/cardano-smash-server || exit 1
73+ ln -s " ${PWD} /dbsync_download/bin/cardano-smash-server" smash-server/bin/cardano-smash-server || exit 1
74+ export DBSYNC_SCHEMA_DIR=" $( readlink -m db-sync-node) /schema"
10575else
10676 # Build db-sync
77+ case " ${DBSYNC_REV:- " " } " in
78+ " " )
79+ echo " The value for DBSYNC_REV cannot be empty" >&2
80+ exit 1
81+ ;;
82+
83+ " master" | " HEAD" )
84+ export DBSYNC_REV=" master"
85+
86+ if [ ! -e cardano-db-sync ]; then
87+ git clone --depth 1 https://github.com/IntersectMBO/cardano-db-sync.git
88+ fi
89+
90+ cd cardano-db-sync || exit 1
91+ git fetch origin master
92+ ;;
93+
94+ * )
95+ if [ ! -e cardano-db-sync ]; then
96+ git clone https://github.com/IntersectMBO/cardano-db-sync.git
97+ fi
98+
99+ cd cardano-db-sync || exit 1
100+ git fetch
101+ ;;
102+ esac
103+
104+ git stash
105+ git checkout " $DBSYNC_REV "
106+ git rev-parse HEAD
107+
107108 nix build --accept-flake-config .# cardano-db-sync -o db-sync-node \
108109 || nix build --accept-flake-config .# cardano-db-sync:exe:cardano-db-sync -o db-sync-node \
109110 || exit 1
110111 # Build cardano-smash-server
111112 if [ " ${SMASH:- " false" } " != " false" ]; then
112113 nix build --accept-flake-config .# cardano-smash-server -o smash-server || exit 1
113114 fi
115+ export DBSYNC_SCHEMA_DIR=" $PWD /schema"
114116fi
115117
116118if [ ! -e db-sync-node/bin/cardano-db-sync ]; then
@@ -125,20 +127,20 @@ if [ -e smash-server/bin/cardano-smash-server ]; then
125127fi
126128export PATH_PREPEND
127129
128- export DBSYNC_SCHEMA_DIR=" $PWD /schema"
129-
130130if [ -n " ${DBSYNC_SKIP_INDEXES:- " " } " ]; then
131131 # Delete the indexes only after the binaries are ready, so the binaries can be retrieved from
132132 # the nix binary cache if available.
133133 rm -f " $DBSYNC_SCHEMA_DIR " /migration-4-000*
134134
135- cleanup_dbsync_repo () {
136- local _origpwd=" $PWD "
137- cd " $DBSYNC_SCHEMA_DIR " /.. || exit 1
138- # shellcheck disable=SC2015
139- git stash && git stash drop || :
140- cd " $_origpwd " || exit 1
141- }
135+ if [ -z " $DBSYNC_TAR_URL " ]; then
136+ cleanup_dbsync_repo () {
137+ local _origpwd=" $PWD "
138+ cd " $DBSYNC_SCHEMA_DIR " /.. || exit 1
139+ # shellcheck disable=SC2015
140+ git stash && git stash drop || :
141+ cd " $_origpwd " || exit 1
142+ }
143+ fi
142144fi
143145
144146cd " $REPODIR " || exit 1
0 commit comments