summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2017-04-24 20:47:31 +0800
committerGitHub <[email protected]>2017-04-24 20:47:31 +0800
commit38a85e0cfac525962e347174fb16080fc447664c (patch)
tree4cb4f1f8a834b1bda5c6d3661e55900f7677cef1 /scripts
parent212c890edf70f9f9b18543ec2879678f534ce244 (diff)
parent630f5f17601e5a35fb8b2e03fd7e3aad7af76c02 (diff)
Merge pull request #76 from TitanSnow/get
xmake getter improved
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get.ps1117
-rwxr-xr-xscripts/get.sh98
2 files changed, 197 insertions, 18 deletions
diff --git a/scripts/get.ps1 b/scripts/get.ps1
index 1b852c4c8..59be2c9db 100644
--- a/scripts/get.ps1
+++ b/scripts/get.ps1
@@ -1,12 +1,111 @@
# xmake getter
# usage: (in powershell)
-# Invoke-Webrequest <my location> -OutFile get.ps1
-# . .\get.ps1
+# Invoke-Expression (Invoke-Webrequest <my location> -UseBasicParsing).Content
-$ver='v2.1.3'
-Invoke-Webrequest "https://github.com/tboox/xmake/releases/download/$ver/xmake-$ver.exe" -OutFile "$pid-xmake-installer.exe"
-Start-Process -FilePath "$pid-xmake-installer.exe" -ArgumentList '/S /D=C:\xmake' -Wait
-Remove-Item "$pid-xmake-installer.exe"
-$env:Path+=";C:\xmake"
-[Environment]::SetEnvironmentVariable("Path",$env:Path,[System.EnvironmentVariableTarget]::User)
-xmake --version
+& {
+
+Function myExit($code){
+ if($code -is [int] -and $code -ne 0){
+ throw $Error[0]
+ }else{
+ break
+ }
+}
+
+Function writeErrorTip($msg){
+ Write-Host $msg -BackgroundColor Red -ForegroundColor White
+}
+
+Function writeLogoLine($msg){
+ Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue
+}
+
+writeLogoLine ' _ '
+writeLogoLine ' | | _ '
+writeLogoLine '__ ___ ______| |/ /___ '
+writeLogoLine '\ \/ | \ / / _ | / / __ \ '
+writeLogoLine ' \ /| \/ / / | | | __/ '
+writeLogoLine ' / \| \__/\ \_| \ \ \ \__. '
+writeLogoLine '/_/\_|_| |_\___\_\|\_\__/ getter'
+writeLogoLine ' '
+writeLogoLine ''
+
+if($PSVersionTable.PSVersion.Major -lt 5){
+ writeErrorTip 'Sorry but PowerShell v5+ is required'
+ throw 'PowerShell''s version too low'
+}
+$temppath=($env:TMP,$env:TEMP,'.' -ne $null)[0]
+$outfile=$temppath+"\$pid-xmake-installer.exe"
+try{
+ Write-Output "$pid"|Out-File -FilePath "$outfile"
+ Remove-Item "$outfile"
+}catch{
+ writeErrorTip 'Cannot write to temp path'
+ writeErrorTip 'Please set environment var "TMP" to another path'
+ myExit 1
+}
+if($ver -eq $null){ $ver='v2.1.3' }
+Write-Host 'Start downloading... Hope amazon S3 is not broken again'
+try{
+ Invoke-Webrequest "https://github.com/tboox/xmake/releases/download/$ver/xmake-$ver.exe" -OutFile "$outfile"
+}catch{
+ writeErrorTip 'Download failed!'
+ writeErrorTip 'Check your network or... the news of S3 break'
+ myExit 1
+}
+Write-Host 'Start installation... Hope your antivirus doesn''t trouble'
+$installdir=$HOME+'\xmake'
+Write-Host "Install to $installdir"
+try{
+ Start-Process -FilePath "$outfile" -ArgumentList "/S /D=$installdir" -Wait
+}catch{
+ Remove-Item "$outfile"
+ writeErrorTip 'Install failed!'
+ writeErrorTip 'Close your antivirus then try again'
+ myExit 1
+}
+Remove-Item "$outfile"
+Write-Host 'Adding to PATH... almost done'
+$env:Path+=";$installdir"
+[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path",[System.EnvironmentVariableTarget]::User)+";$installdir",[System.EnvironmentVariableTarget]::User) # this step is optional because installer writes path to regedit
+try{
+ xmake --version
+}catch{
+ writeErrorTip 'Everything is showing installation has finished'
+ writeErrorTip 'But xmake could not run... Why?'
+ myExit 1
+}
+if($branch -eq $null){ $branch='master' }
+Write-Host "Pulling xmake from branch $branch"
+$outfile=$temppath+"\$pid-xmake-repo.zip"
+try{
+ Invoke-Webrequest "https://github.com/tboox/xmake/archive/$branch.zip" -OutFile "$outfile"
+}catch{
+ writeErrorTip 'Pull Failed!'
+ writeErrorTip 'xmake is now available but may not be newest'
+ myExit
+}
+Write-Host 'Expanding archive...'
+New-Item -Path "$temppath" -Name "$pid-xmake-repo" -ItemType "directory" -Force
+$oldpwd=$pwd
+$repodir=$temppath+"\$pid-xmake-repo"
+try{
+ Expand-Archive "$outfile" "$repodir" -Force
+ Write-Host 'Self-building...'
+ Set-Location ($repodir+"\xmake-$branch\core")
+ xmake
+ Write-Host 'Copying new files...'
+ Copy-Item 'build\xmake.exe' "$installdir" -Force
+ Set-Location '..\xmake'
+ Copy-Item * "$installdir" -Recurse -Force
+ xmake --version
+}catch{
+ writeErrorTip 'Update Failed!'
+ writeErrorTip 'xmake is now available but may not be newest'
+}finally{
+ Set-Location "$oldpwd" -ErrorAction SilentlyContinue
+ Remove-Item "$outfile" -ErrorAction SilentlyContinue
+ Remove-Item "$repodir" -Recurse -Force -ErrorAction SilentlyContinue
+}
+
+}
diff --git a/scripts/get.sh b/scripts/get.sh
index eb3ae0657..11a72d854 100755
--- a/scripts/get.sh
+++ b/scripts/get.sh
@@ -1,18 +1,98 @@
-#!/bin/sh
+#!/bin/bash
# xmake getter
# usage: bash <(curl -s <my location>) [branch]
+# print a LOGO!
+echo -ne '\x1b[07m'
+echo ' _ '
+echo ' | | _ '
+echo '__ ___ ______| |/ /___ '
+echo '\ \/ | \ / / _ | / / __ \ '
+echo ' \ /| \/ / / | | | __/ '
+echo ' / \| \__/\ \_| \ \ \ \__. '
+echo '/_/\_|_| |_\___\_\|\_\__/ getter'
+echo ' '
+echo -e '\x1b[0m'
+
+brew --version >/dev/null 2>&1 && brew install --HEAD xmake && xmake --version && exit
+if [ 0 -ne $(id -u) ]
+then
+ sudoprefix=sudo
+else
+ sudoprefix=
+fi
+my_exit(){
+ rv=$?
+ if [ "x$1" != x ]
+ then
+ echo -ne '\x1b[41;37m'
+ echo "$1"
+ echo -ne '\x1b[0m'
+ fi
+ rm -rf /tmp/$$xmake_getter 2>/dev/null
+ if [ "x$2" != x ]
+ then
+ if [ $rv -eq 0 ];then rv=$2;fi
+ fi
+ exit $rv
+}
+test_tools()
+{
+ {
+ git --version &&
+ make --version &&
+ {
+ cc --version ||
+ gcc --version ||
+ clang --version
+ }
+ } >/dev/null 2>&1
+}
+install_tools()
+{
+ { apt-get --version >/dev/null 2>&1 && $sudoprefix apt-get install -y git build-essential; } ||
+ { yum --version >/dev/null 2>&1 && $sudoprefix yum install -y git && $sudoprefix yum groupinstall -y 'Development Tools'; } ||
+ { zypper --version >/dev/null 2>&1 && $sudoprefix zypper --non-interactive install git && $sudoprefix zypper --non-interactive install -t pattern devel_C_C++; } ||
+ { pacman -V >/dev/null 2>&1 && $sudoprefix pacman -S --noconfirm git base-devel; }
+}
+test_tools || { install_tools && test_tools; } || my_exit 'Dependencies Installation Fail' 1
branch=
-if [ x != x$1 ];then branch="-b $1";fi
-git clone --depth=1 $branch https://github.com/tboox/xmake.git /tmp/$$xmake_getter || exit $?
-make -C /tmp/$$xmake_getter --no-print-directory build || exit $?
-if [ 0 -eq $(id -u) ]
+if [ x != "x$1" ]
+then
+ branch="-b $1"
+ echo "Branch: $1"
+fi
+if [ 'x-b __local__' != "x$branch" ]
+then
+ git clone --depth=1 $branch https://github.com/tboox/xmake.git /tmp/$$xmake_getter || my_exit 'Clone Fail'
+else
+ cp -r "$(git rev-parse --show-toplevel 2>/dev/null || hg root 2>/dev/null || echo $PWD)" /tmp/$$xmake_getter || my_exit 'Clone Fail'
+fi
+make -C /tmp/$$xmake_getter --no-print-directory build || my_exit 'Build Fail'
+IFS=':'
+patharr=($PATH)
+prefix=
+for st in ${patharr[@]}
+do
+ if [[ "$st" = "$HOME"* ]]
+ then
+ cwd=$(pwd)
+ mkdir -p "$st"
+ cd "$st"
+ echo $$ > $$xmake_getter_test 2>/dev/null || continue
+ rm $$xmake_getter_test 2>/dev/null || continue
+ cd ..
+ mkdir -p share 2>/dev/null || continue
+ prefix=$(pwd)
+ cd "$cwd"
+ break
+ fi
+done
+if [ "x$prefix" != x ]
then
- make -C /tmp/$$xmake_getter --no-print-directory install || exit $?
+ make -C /tmp/$$xmake_getter --no-print-directory install prefix="$prefix"|| my_exit 'Install Fail'
else
- sudo make -C /tmp/$$xmake_getter --no-print-directory install || exit $?
+ $sudoprefix make -C /tmp/$$xmake_getter --no-print-directory install || my_exit 'Install Fail'
fi
-rm -rf /tmp/$$xmake_getter
xmake --version
-exit $?