unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

unrealircd-upgrade-script.in (4426B)

      1 #!/usr/bin/env bash
      2 #
      3 # This is stage 1 of the UnrealIRCd upgrade script
      4 # It downloads stage 2 online, verifies the integrity, and then
      5 # passes control to it to proceed with the rest of the upgrade.
      6 #
      7 # This is a bash script, so it is less cross-platform than the
      8 # rest of UnrealIRCd. We also mostly assume Linux/FreeBSD here.
      9 #
     10 
     11 BUILDDIR="@BUILDDIR@"
     12 SCRIPTDIR="@SCRIPTDIR@"
     13 DOCDIR="@DOCDIR@"
     14 TMPDIR="@TMPDIR@"
     15 
     16 function warn()
     17 {
     18 	echo
     19 	echo "WARNING: $*"
     20 	echo "This is for your information only. It is possible to continue."
     21 	echo "Press ENTER to continue, or CTRL+C to abort."
     22 	echo "If in doubt, see https://www.unrealircd.org/docs/FAQ#upgrade-verify-failed"
     23 	read xyz
     24 }
     25 
     26 function bigwarn()
     27 {
     28 	echo
     29 	echo "[!!!] WARNING: $*"
     30 	echo "Check https://www.unrealircd.org/docs/FAQ#upgrade-verify-failed !"
     31 	echo "Type 'IGNORE' in uppercase to continue if you think it is safe."
     32 	echo "Type anything else to abort."
     33 	read answer
     34 	if [ "$answer" != "IGNORE" ]; then
     35 		exit 1
     36 	fi
     37 }
     38 
     39 function fail()
     40 {
     41 	echo
     42 	echo "ERROR: $*"
     43 	echo "NOTE: Your existing UnrealIRCd is backed up to $BACKUPDIR"
     44 	echo "Perhaps check out the FAQ for common problems:"
     45 	echo "https://www.unrealircd.org/docs/FAQ#upgrade-failed"
     46 	echo "Otherwise, follow the manual upgrade procedure from"
     47 	echo "https://www.unrealircd.org/docs/Upgrading"
     48 	exit 1
     49 }
     50 
     51 if [ ! -d "$BUILDDIR" ]; then
     52 	echo "UnrealIRCd source not found at $BUILDDIR."
     53 	echo "Sorry, then it is not possible to know your existing settings and thus we cannot upgrade."
     54 	echo "Follow the manual upgrade procedure from https://www.unrealircd.org/docs/Upgrading"
     55 	exit 1
     56 fi
     57 
     58 FETCHER="wget"
     59 if ! wget --help 1>/dev/null 2>&1; then
     60 	# fetch is a pain: it always returns 1 (false) even for usage info and has no --version
     61 	fetch 1>/dev/null 2>&1
     62 	if [ "$?" -ne 1 ]; then
     63 		echo "The tool 'wget' is missing, which is used by this script."
     64 		echo "On Linux consider running 'sudo apt install wget' or 'sudo yum install wget'"
     65 		echo "and run this script again."
     66 		echo "Or, don't use this script and follow the manual upgrade procedure from"
     67 		echo "https://www.unrealircd.org/docs/Upgrading"
     68 		exit 1
     69 	fi
     70 	FETCHER="fetch"
     71 fi
     72 
     73 # Weird way to get version, but ok.
     74 cd "$BUILDDIR" || fail "Could not cd to builddir"
     75 UNREALVER="`./configure --version|head -n1|awk '{ print $3 }'`"
     76 cd .. || fail "Could not cd back"
     77 
     78 # Set and export all variables with settings
     79 export UNREALVER BUILDDIR SCRIPTDIR DOCDIR TMPDIR FETCHER
     80 
     81 # Download the install script
     82 if [ "$FETCHER" = "wget" ]; then
     83 	wget -O unrealircd-upgrade-script.stage2 "https://www.unrealircd.org/downloads/unrealircd-upgrade-script.stage2?from=$UNREALVER" || fail "Could not download online installer"
     84 	wget -O unrealircd-upgrade-script.stage2.asc "https://www.unrealircd.org/downloads/unrealircd-upgrade-script.stage2.asc" || fail "Could not download online installer signature"
     85 else
     86 	fetch -o unrealircd-upgrade-script.stage2 "https://www.unrealircd.org/downloads/unrealircd-upgrade-script.stage2?from=$UNREALVER" || fail "Could not download online installer"
     87 	fetch -o unrealircd-upgrade-script.stage2.asc "https://www.unrealircd.org/downloads/unrealircd-upgrade-script.stage2.asc" || fail "Could not download online installer signature"
     88 fi
     89 
     90 # GPG verification - if available
     91 if gpg --version 1>/dev/null 2>&1; then
     92 	if [ -f "$DOCDIR/KEYS" ]; then
     93 		gpg --import "$DOCDIR/KEYS"
     94 		echo
     95 		if gpg --batch --exit-on-status-write-error --verify unrealircd-upgrade-script.stage2.asc unrealircd-upgrade-script.stage2; then
     96 			echo "GPG: Verification succeeded. Download is genuine."
     97 			export NOGPG=0
     98 		else
     99 			bigwarn "GPG/PGP verification failed. This could be a security issue."
    100 			export NOGPG=1
    101 		fi
    102 	else
    103 		warn "Unable to check download integrity with GPG/PGP. Missing $DOCDIR/KEYS file."
    104 		export NOGPG=1
    105 	fi
    106 else
    107 	echo "WARNING: The GnuPG (GPG/PGP) verification tool 'gpg' is not installed."
    108 	if [[ "$OSTYPE" == "freebsd"* ]] ; then
    109 		echo "Consider running 'sudo pkg install gnupg'"
    110 	else
    111 		echo "Consider running 'sudo apt install gpg' or 'yum install gnupg2'"
    112 	fi
    113 	echo "When 'gpg' is installed then the UnrealIRCd upgrade script can"
    114 	echo "verify the digital signature of the download file."
    115 	warn "Unable to check download integrity"
    116 	export NOGPG=1
    117 fi
    118 
    119 chmod +x unrealircd-upgrade-script.stage2
    120 ./unrealircd-upgrade-script.stage2 $*
    121 SAVERET="$?"
    122 rm -f unrealircd-upgrade-script.stage2 unrealircd-upgrade-script.stage2.asc
    123 exit $SAVERET