Skip to content

Instantly share code, notes, and snippets.

@adduc
Last active August 24, 2021 09:23
Show Gist options
  • Save adduc/2104076905f3e2c2e7c2dfc6b5c43b21 to your computer and use it in GitHub Desktop.
Save adduc/2104076905f3e2c2e7c2dfc6b5c43b21 to your computer and use it in GitHub Desktop.
My installation of mercurial, tortoisehg, and hg-git on Ubuntu 20.04 and newer
#!/bin/bash
TARGET_DIR=/opt/repos/third-parties
HG_GIT_VERSION=${1:-default}
HG_RELEASE_VERSION=${2:-5.5.2}
HG_REPO_VERSION=${3:-stable}
TORTOISEHG_VERSION=${4:-stable}
update() {
# Update packages
apt-get update
apt-get -y dist-upgrade
}
prepare() {
apt-get -y install \
curl \
gcc \
make \
python-is-python3 \
python3 \
python3-dev \
python3-distutils \
python3-docutils \
python3-dulwich \
python3-iniparse \
python3-pip
## Ubuntu provides packages for PyQt5 and QScintilla, but there
## appears to be a bug in the versions shipped with Ubuntu 20.10
## that crashes TortoiseHG when viewing console logs. Until this bug
## is fixed, use pip to install QT5 dependencies
# python3-pyqt5 \
# python3-pyqt5.qsci \
pip3 install PyQt5 QScintilla
mkdir -p ${TARGET_DIR}
}
install_hg_release() {
cd ${TARGET_DIR} \
&& curl "https://www.mercurial-scm.org/release/mercurial-${HG_RELEASE_VERSION}.tar.gz" -o mercurial.tar.gz \
&& tar xf mercurial.tar.gz \
&& rm -rf mercurial.tar.gz \
&& mv mercurial-* mercurial \
&& cd ${TARGET_DIR}/mercurial \
&& make -j $(nproc) build
}
install_hg_repo() {
cd ${TARGET_DIR} \
&& ${TARGET_DIR}/mercurial/hg clone -u ${HG_REPO_VERSION} https://www.mercurial-scm.org/repo/hg \
&& cd ${TARGET_DIR}/hg \
&& make -j $(nproc) build install \
&& rm -rf ${TARGET_DIR}/mercurial
}
install_hg_git() {
cd ${TARGET_DIR} \
&& hg clone https://foss.heptapod.net/mercurial/hg-git
}
install_tortoisehg() {
cd ${TARGET_DIR} \
&& hg clone -u ${TORTOISEHG_VERSION} https://foss.heptapod.net/mercurial/tortoisehg/thg \
&& ln -fs ${TARGET_DIR}/thg/thg /usr/local/bin/thg
}
main() {
set -xe
update
prepare
install_hg_release
install_hg_repo
install_hg_git
install_tortoisehg
}
main
@ai-matulis
Copy link

Thanks for the script!
TortoiseHG repo moved to another location
It now lives at https://foss.heptapod.net/mercurial/tortoisehg/thg

@adduc
Copy link
Author

adduc commented Oct 24, 2020

Thanks, I've updated the script to use the new TortoiseHG repository (and removed the cleanup function that was left over from when this script was ran in a docker container).

It worked without issue on the newly released Ubuntu 20.10

@shivankgtm
Copy link

How to run it after installing?

@adduc
Copy link
Author

adduc commented Oct 31, 2020

TortoiseHG can be invoked as thg via CLI (assuming /usr/local/bin is defined in PATH).

To make TortoiseHG show up in GNOME (or another desktop environment), here's what I tossed in ~/.local/share/applications/TortoiseHG.desktop:

[Desktop Entry]
Version=1.0
Type=Application
Name=TortoiseHG
Exec=thg
Icon=/opt/repos/third-parties/thg/icons/svg/thg_logo.svg

@VioletGiraffe
Copy link

VioletGiraffe commented Nov 17, 2020

Thank you for the very handy script! I'm really grateful for it and happy that I found it. The last time I tried building tortoisehg by the official manual, it took me 20 minutes to figure all the dependencies they fail to mention.

Found one error: line 36: pip: command not found
Since the script is installing python3-pip, it should call pip3, not pip!

@adduc
Copy link
Author

adduc commented Nov 17, 2020

I appreciate the feedback, the script has been updated.

@VioletGiraffe
Copy link

VioletGiraffe commented Nov 17, 2020

And another small issue / inconvenience: I ran the script with sudo (because without it apt fails and the script exits), but now I cannot run thg without sudo (getting "permission denied"), but I think this wouldn't have been necessary if thg wasn't built under sudo. In other words, I think the script should specifically use sudo, and only where it's needed, so that the script could be run without sudo.

Now I see root's home folder in the "Open repo" dialog so even just navigating the disk is a challenge.

@VioletGiraffe
Copy link

I fixed a few problems (mostly related to file and folder permissions) and simplified the script to use pip and apt instead of building everything from source (also removed hg-git which I don't need, so it's not a drop-in analog for this original script).
https://gist.github.com/VioletGiraffe/166b62c4e170174976ee7691431c25e6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment