Admin/init
author wenzelm
Fri, 16 Apr 2021 21:50:47 +0200
changeset 73584 1d4c9fa00821
parent 73517 d3f2038198ae
child 73588 a96de8bbe8a3
permissions -rwxr-xr-x
clarified options;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     1
#!/usr/bin/env bash
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     2
#
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     3
# Author: Makarius
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     4
#
73514
01acd0eb29ce clarified name;
wenzelm
parents: 73508
diff changeset
     5
# DESCRIPTION: initialize Isabelle repository clone or repository archive
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     6
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     7
73501
f026a9a0a43f proper Admin script, outside the settings environment;
wenzelm
parents: 73497
diff changeset
     8
## environment
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
     9
73501
f026a9a0a43f proper Admin script, outside the settings environment;
wenzelm
parents: 73497
diff changeset
    10
export ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)"
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    11
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    12
ISABELLE_REPOS="https://isabelle.sketis.net/repos/isabelle"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    13
73501
f026a9a0a43f proper Admin script, outside the settings environment;
wenzelm
parents: 73497
diff changeset
    14
f026a9a0a43f proper Admin script, outside the settings environment;
wenzelm
parents: 73497
diff changeset
    15
## diagnostics
f026a9a0a43f proper Admin script, outside the settings environment;
wenzelm
parents: 73497
diff changeset
    16
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    17
function usage()
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    18
{
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    19
  echo
73514
01acd0eb29ce clarified name;
wenzelm
parents: 73508
diff changeset
    20
  echo "Usage: Admin/init [OPTIONS]"
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    21
  echo
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    22
  echo "  Options are:"
73502
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    23
  echo "    -C           force clean working directory (no backup!)"
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    24
  echo "    -L           local history only: no pull from repository server"
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    25
  echo "    -R           version is current official release"
73515
wenzelm
parents: 73514
diff changeset
    26
  echo "    -U URL       Isabelle repository server"
wenzelm
parents: 73514
diff changeset
    27
  echo "                 (default: \"$ISABELLE_REPOS\")"
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    28
  echo "    -V PATH      version is taken from file, or directory"
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    29
  echo "                 with file \"ISABELLE_VERSION\""
73502
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    30
  echo "    -c           check clean working directory"
73504
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    31
  echo "    -f           fresh build of Isabelle/Scala/jEdit"
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    32
  echo "    -n           no build of Isabelle/Scala/jEdit"
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    33
  echo "    -r REV       version given in Mercurial notation (changeset id or tag)"
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    34
  echo "    -t           version is latest tip"
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    35
  echo
73514
01acd0eb29ce clarified name;
wenzelm
parents: 73508
diff changeset
    36
  echo "  Initialize the current ISABELLE_HOME directory, which needs to be a"
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    37
  echo "  repository clone (all versions) or repository archive (fixed version)."
73515
wenzelm
parents: 73514
diff changeset
    38
  echo "  Download required components. Build Isabelle/Scala/jEdit by default."
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    39
  echo
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    40
  exit 1
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    41
}
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    42
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    43
function fail()
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    44
{
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    45
  echo "$1" >&2
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    46
  exit 2
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    47
}
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    48
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    49
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    50
## process command line
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    51
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    52
#options
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    53
73504
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    54
BUILD_OPTIONS="-b"
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    55
PULL="true"
73504
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    56
73502
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    57
CLEAN_FORCE=""
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    58
CLEAN_CHECK=""
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    59
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    60
VERSION=""
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    61
VERSION_RELEASE=""
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    62
VERSION_PATH=""
73488
97692af929a4 more robust;
wenzelm
parents: 73487
diff changeset
    63
VERSION_REV=""
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    64
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    65
while getopts "CLRU:V:cfnr:t" OPT
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    66
do
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    67
  case "$OPT" in
73488
97692af929a4 more robust;
wenzelm
parents: 73487
diff changeset
    68
    C)
73502
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    69
      CLEAN_FORCE="--clean"
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    70
      ;;
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    71
    L)
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    72
      PULL=""
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
    73
      ;;
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    74
    R)
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    75
      VERSION="true"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    76
      VERSION_RELEASE="true"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    77
      VERSION_PATH=""
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    78
      VERSION_REV=""
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    79
      ;;
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    80
    U)
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    81
      ISABELLE_REPOS="$OPTARG"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    82
      ;;
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    83
    V)
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    84
      VERSION="true"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    85
      VERSION_RELEASE=""
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    86
      VERSION_PATH="$OPTARG"
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    87
      VERSION_REV=""
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
    88
      ;;
73502
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    89
    c)
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    90
      CLEAN_CHECK="--check"
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
    91
      ;;
73504
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    92
    f)
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    93
      BUILD_OPTIONS="-b -f"
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    94
      ;;
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    95
    n)
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    96
      BUILD_OPTIONS=""
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
    97
      ;;
73488
97692af929a4 more robust;
wenzelm
parents: 73487
diff changeset
    98
    r)
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
    99
      VERSION="true"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   100
      VERSION_RELEASE=""
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   101
      VERSION_PATH=""
73488
97692af929a4 more robust;
wenzelm
parents: 73487
diff changeset
   102
      VERSION_REV="$OPTARG"
97692af929a4 more robust;
wenzelm
parents: 73487
diff changeset
   103
      ;;
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
   104
    t)
73492
8c93418ea257 more options;
wenzelm
parents: 73491
diff changeset
   105
      VERSION="true"
8c93418ea257 more options;
wenzelm
parents: 73491
diff changeset
   106
      VERSION_RELEASE=""
8c93418ea257 more options;
wenzelm
parents: 73491
diff changeset
   107
      VERSION_PATH=""
73493
827f53095f1c more robust: lest hg work out remote tip;
wenzelm
parents: 73492
diff changeset
   108
      VERSION_REV="tip"
73492
8c93418ea257 more options;
wenzelm
parents: 73491
diff changeset
   109
      ;;
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   110
    \?)
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   111
      usage
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   112
      ;;
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   113
  esac
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   114
done
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   115
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   116
shift $(($OPTIND - 1))
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   117
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   118
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   119
# args
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   120
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   121
[ "$#" -ne 0 ] && usage
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   122
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   123
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   124
## main
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   125
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   126
if [ -z "$VERSION" ]; then
73504
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   127
  "$ISABELLE_HOME/bin/isabelle" components -I || exit "?$"
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   128
  "$ISABELLE_HOME/bin/isabelle" components -a || exit "?$"
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   129
  if [ -n "$BUILD_OPTIONS" ]; then
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   130
    "$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   131
  fi
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   132
elif [ ! -d "$ISABELLE_HOME/.hg" ]; then
73515
wenzelm
parents: 73514
diff changeset
   133
  fail "Not a repository clone: cannot switch version"
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   134
else
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   135
  if [ -n "$VERSION_REV" ]; then
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   136
    REV="$VERSION_REV"
73491
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   137
  elif [ -n "$VERSION_RELEASE" ]; then
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   138
    URL="$ISABELLE_REPOS/raw-file/tip/Admin/Release/official"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   139
    REV="$(curl -s -f "$URL" | head -n1)"
dbe5bbc2331e clarified treatment of multiple versions: last one counts;
wenzelm
parents: 73490
diff changeset
   140
    [ -z "$REV" ] && fail "Failed to access \"$URL\""
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   141
  elif [ -f "$VERSION_PATH" ]; then
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   142
    REV="$(cat "$VERSION_PATH")"
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   143
  elif [ -d "$VERSION_PATH" ]; then
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   144
    if [ -f "$VERSION_PATH/ISABELLE_VERSION" ]; then
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   145
      REV="$(cat "$VERSION_PATH/ISABELLE_VERSION")"
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   146
    else
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   147
      fail "Missing file \"$VERSION_PATH/ISABELLE_VERSION\""
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   148
    fi
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   149
  else
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   150
    fail "Missing file \"$VERSION_PATH\""
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   151
  fi
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   152
73507
wenzelm
parents: 73506
diff changeset
   153
  "$ISABELLE_HOME/bin/isabelle" components -I || exit "$?"
wenzelm
parents: 73506
diff changeset
   154
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   155
  export LANG=C
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   156
  export HGPLAIN=
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   157
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   158
  #Atomic exec: avoid inplace update of running script!
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
   159
  export PULL CLEAN_FORCE CLEAN_CHECK REV ISABELLE_REPOS BUILD_OPTIONS
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   160
  exec bash -c '
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   161
    set -e
73584
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
   162
    if [ -n "$PULL" ]; then
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
   163
      "${HG:-hg}" -R "$ISABELLE_HOME" pull -r "$REV" "$ISABELLE_REPOS"
1d4c9fa00821 clarified options;
wenzelm
parents: 73517
diff changeset
   164
    fi
73502
c582bf975a5b more options;
wenzelm
parents: 73501
diff changeset
   165
    "${HG:-hg}" -R "$ISABELLE_HOME" update -r "$REV" $CLEAN_FORCE $CLEAN_CHECK
73501
f026a9a0a43f proper Admin script, outside the settings environment;
wenzelm
parents: 73497
diff changeset
   166
    "$ISABELLE_HOME/bin/isabelle" components -a
73504
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   167
    if [ -n "$BUILD_OPTIONS" ]; then
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   168
      "$ISABELLE_HOME/bin/isabelle" jedit $BUILD_OPTIONS
c259c7a42ac3 more options: build is part of default setup;
wenzelm
parents: 73502
diff changeset
   169
    fi
73489
9460f1f45405 more robust: explicit repository root;
wenzelm
parents: 73488
diff changeset
   170
    "${HG:-hg}" -R "$ISABELLE_HOME" log -r "$REV"
73514
01acd0eb29ce clarified name;
wenzelm
parents: 73508
diff changeset
   171
    if [ ! -f "$ISABELLE_HOME/Admin/init" ]; then
01acd0eb29ce clarified name;
wenzelm
parents: 73508
diff changeset
   172
      echo >&2 "### The Admin/init script has disappeared in this version"
73497
7cdcf131699d tuned message;
wenzelm
parents: 73496
diff changeset
   173
      echo >&2 "### (need to invoke \"${HG:-hg} update\" before using it again)"
73494
e16133a05458 clarified messages;
wenzelm
parents: 73493
diff changeset
   174
    fi
73487
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   175
  '
47f055b40ab9 more convenient repository setup;
wenzelm
parents:
diff changeset
   176
fi