Open han-k59 opened 5 years ago
BASE="$HOME/Development/FreePascal"
if [ "$(id -u)" = "0" ]; then echo "This script should not be run as root" exit 1 fi
FPC="3.0" LAZ="1.5" OS_TARGET="darwin" OS_VERSION=$(sw_vers -productVersion | awk -F "." '{print $2}')
if [[ ! "$PATH" == "/opt/local/bin" ]]; then PATH=/opt/local/bin:$PATH fi
if [ "$OS_VERSION" -eq 7 ]; then echo "Detected OSX Lion" elif [ "$OS_VERSION" -eq 8 ]; then echo "Detected OSX Mountain Lion" elif [ "$OS_VERSION" -eq 9 ]; then echo "Detected OSX Mavericks" elif [ "$OS_VERSION" -eq 10 ]; then echo "Detected OSX Yosemite" elif [ "$OS_VERSION" -eq 11 ]; then echo "Detected OSX El Capitain" elif [ "$OS_VERSION" -eq 12 ]; then echo "Detected MacOS Sierra" elif [ "$OS_VERSION" -eq 13 ]; then echo "Detected MacOS High Sierra" elif [ "$OS_VERSION" -eq 14 ]; then echo "Detected MacOs Tiger" elif [ "$OS_VERSION" -eq 15 ]; then echo "Detected MacOs Catalina" elif [ "$OS_VERSION" -eq 16 ]; then echo "Detected MacOS Big Sur" elif [ "$OS_VERSION" -eq 17 ]; then echo "Detected MacOS Monterey" else echo "This installer does not recognize your OS" echo "done." echo exit 1 fi
if ! xcode-select -p &> /dev/null ; then
echo "Setup has detected that xcode tools are not installed"
read -p "Press [ENTER] to install xcode tools"
sudo xcode-select --install &> /dev/null ;
echo "Please wait for xcode tools to install"
echo
sleep 10s
read -p "After code tools are installed press [ENTER] to continue"
echo
if ! xcode-select -p &> /dev/null ; then
echo "Setup has detected that xcode tools were not completely installed"
echo "Please wait for xcode tools to install and re-run this script"
echo "done."
echo
fi
else
echo "Found xcode tools"
fi
if ! port version &> /dev/null ; then
echo "Setup has detected that macports is not installed"
read -p "Press [ENTER] to install macports"
echo "Please wait for macports to install"
MACPORTS=/tmp/macports.pkg
if [ ! -f "$MACPORTS" ]; then
if [ "$OS_VERSION" -eq 7 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.7-Lion.pkg
elif [ "$OS_VERSION" -eq 8 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.8-MountainLion.pkg
elif [ "$OS_VERSION" -eq 9 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.9-Mavericks.pkg
elif [ "$OS_VERSION" -eq 10 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.10-Yosemite.pkg
elif [ "$OS_VERSION" -eq 11 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.11-ElCapitan.pkg
elif [ "$OS_VERSION" -eq 12 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.12-Sierra.pkg
elif [ "$OS_VERSION" -eq 13 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.13-HighSierra.pkg
elif [ "$OS_VERSION" -eq 14 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.14-Mojave.pkg
elif [ "$OS_VERSION" -eq 15 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-10.15-Catalina.pkg
elif [ "$OS_VERSION" -eq 16 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-11-BigSur.pkg
elif [ "$OS_VERSION" -eq 17 ]; then
PKGURL=https://distfiles.macports.org/MacPorts/MacPorts-2.7.1-12-Monterey.pkg
fi
curl "$PKGURL" -o "$MACPORTS"
fi
open $MACPORTS
echo
sleep 10s
read -p "After macports is installed press [ENTER] to continue"
echo
if ! port version &> /dev/null ; then
echo "Setup has detected that macports was not completely installed"
echo "Please wait for macports to install and re-run this script"
echo "done."
echo
fi
else
echo "Found macports"
fi
if ! ggdb --version &> /dev/null ; then
echo "Setup has detected that the gnu debugger is not installed"
read -p "Press [ENTER] to install the gnu debugger"
sudo port install gdb
echo
if ! ggdb --version &> /dev/null ; then
echo "Setup has detected that the gnu debugger did not install"
echo "done."
echo
fi
else
echo "Found gnu debugger"
fi
if ! 7za --help &> /dev/null ; then
echo "Setup has detected that the 7-zip is not installed"
read -p "Press [ENTER] to install 7-zip"
sudo port install p7zip
echo
if ! 7za --help &> /dev/null ; then
echo "Setup has detected that 7-zip did not install"
echo "done."
echo
fi
else
echo "Found 7-zip"
fi
SIGNED="$(codesign -dv /opt/local/bin/ggdb 2>&1)"
if [[ $SIGNED == "object is not signed" ]] then echo echo "Setup has detected that the gnu debugger is not currently code signed." echo echo "After install is complete you will be provided instructions on how to sign the" echo "debugger. This will allow it authorization to attach to programs for debugging." echo read -p "Press [ENTER] to continue" fi
function expandPath() {
if [ uname
="Darwin" ]; then
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}";
else
echo $(readlink -m $1
)
fi
}
clear echo "This is the universal OSX script to install Free Pascal and Lazarus" echo "-------------------------------------------------------------------" echo echo "It will install copies of:" echo " Free Pascal $FPC" echo " Lazarus $LAZ" echo echo "This script not interfere with your existing Lazarus environment" echo
BASE=$HOME/Development/FreePascal
while true; do
echo "Enter an installation folder or press return to"
echo "accept the default install location"
echo
echo -n "[$BASE]: "
read CHOICE
echo
# Use BASE as the default
if [ -z "$CHOICE" ]; then
CHOICE=$BASE
fi
# Allow for relative paths
CHOICE=`eval echo $CHOICE`
EXPAND=`expandPath "$CHOICE"`
# Allow install only under your home folder
if [[ $EXPAND == $HOME* ]]; then
echo "The install folder will be:"
echo "$EXPAND"
echo
else
echo "The install folder must be under your personal home folder"
echo
continue
fi
# Confirm their choice
echo -n "Continue? (y,n): "
read CHOICE
echo
case $CHOICE in
[yY][eE][sS]|[yY])
;;
*)
echo "done."
echo
exit 1
;;
esac
# If folder already exists ask to remove it
if [ -d "$EXPAND" ]; then
echo "Directory already exist"
echo -n "Remove the entire folder and overwrite? (y,n): "
read CHOICE
case $CHOICE in
[yY][eE][sS]|[yY])
echo
rm -rf $EXPAND
;;
*)
echo
echo "done."
echo
exit 1
;;
esac
fi
break
done
BASE=$EXPAND mkdir -p "$BASE"
if [ ! -d "$BASE" ]; then echo "Could not create directory" echo echo "done." echo exit 1; fi
CURRENT=pwd
cd $BASE
ARCHIVE="fpc-$FPC.$OS_TARGET.7z" curl "http://cache.getlazarus.org/archives/$ARCHIVE" -o "$ARCHIVE" 7za x "$ARCHIVE" rm "$ARCHIVE"
function replace() { cd "$BASE/$1" shift SEARCH=$(echo "$1" | sed 's/[*.]/\&/g') SEARCH=$(echo "$SEARCH" | sed 's/\//\\//g') shift REPLACE=$(echo "$1" | sed 's/[*.]/\&/g') REPLACE=$(echo "$REPLACE" | sed 's/\//\\//g') shift
perl -pi -w -e "s/${SEARCH}/${REPLACE}/g;" $1 &> /dev/null
}
ORIGIN="/Users/macuser/Development/FreePascal" replace "lazarus/config" "$ORIGIN" "$BASE" "." replace "lazarus/lazarus.app/Contents/MacOS" "$ORIGIN" "$BASE" "lazarus" replace "fpc/bin" "$ORIGIN" "$BASE" "*.cfg" echo
cd $BASE ditto ./lazarus/lazarus.app ./Lazarus.app/ cd $BASE
TERMINAL="Free Pascal Terminal.command" echo "osascript -e 'tell app \"Terminal\"" > "$TERMINAL" echo " do script \"export PPC_CONFIG_PATH=\\"$BASE/fpc/bin\\" && export PATH=\\"\$PPC_CONFIG_PATH:\$PATH\\"\"" >> "$TERMINAL" echo "end tell'" >> "$TERMINAL" chmod +x "$TERMINAL"
function hit() {
if type "curl" > /dev/null; then
curl -s -o /dev/null "$1"
elif type "wget" > /dev/null; then
wget -q -O /dev/null "$1"
fi
}
hit "http://www.getlazarus.org/installed/?platform=macintosh"
echo "Free Pascal 3.0 with Lazarus install complete"
if [[ $SIGNED == "object is not signed" ]] then echo echo "The gnu debugger is not currently code signed" echo echo "Read http://lazarus.codebot.org/darwin/debugger for instructions on" echo "how to code sign the debugger" echo open "http://lazarus.codebot.org/darwin/debugger" echo fi
open "$BASE" cd $CURRENT
The script works great. Thanks! Unfortunally I can't install additional packages. Get error as below. fpcres is in the directory. FPC problem? Regards, Han Compile package cairocanvas_pkg 0.0: Success Compile package Printer4Lazarus 0.5: Success Build IDE: Exit code 2, Errors: 1, Warnings: 1 Warning: svn not in path. lazarus.pp(165,1) Error: Can't call the resource compiler "/home/pi/Development/FreePascal/fpc/bin/fpcres", switching to external mode