appledoc- runscript- Expected end of line but found identifier - objective-c

I'm trying to run this script as part of generating documentation
using appledoc plug in. But, I'm receiving this 'Expected end of line
but found identifier.' error when I run this script in Xcode(or
terminal). Please help me out as I'm new to scripting and i'm unable to identify the exact error in the code!
#!/bin/bash
tmpdir="tmpdocs"
finaldir="docs"
rm -rf $tmpdir
mkdir $tmpdir # we killed this last time, create it to avoid warnings from appledoc
cd ./AppledocTemplates/
git checkout master
git pull origin master
expectedversion=$(./templateversion.sh) # Check repo version
cd ..
##########################################
# Install templates if not current
##########################################
if [ ! -f ~/.appledoc/templateversion.sh ] #If this file doesn't exist, then need to install templates
then
cd ./AppledocTemplates/
./installtemplates.sh
if [ $? -ne 0 ] # Descriptive error message is sent in installtemplates. Just exit with error
then
exit 1
fi
cd ..
fi
version=$(~/.appledoc/templateversion.sh) # Check installed version
if [ $version -ne $expectedversion ]
then
echo "Updating templates"
cd ./AppledocTemplates/
./installtemplates.sh #wrong version - try installing
version=$(~/.appledoc/templateversion.sh)
if [ $? -ne 0 ] # Descriptive error message is sent in installtemplates. Just exit with error
then
cd ..
exit 1
fi
if [ $version -ne $expectedversion ] # Now is the version correct? If not, exit with error
then
cd ..
echo "You do not have the correct version of the appledoc templates"
echo "Make sure you run installtemplates.sh to put them in their correct location."
exit 1
fi
cd ..
fi
##########################################
# Compile the docs
##########################################
appledoc ./AppledocSettings.plist MySDK # Compile the docs
if [ $? -ne 0 ]
then
echo "Compile failure of source documents. MySDK doc creation not completed."
exit 1
fi
##########################################
# Stage docs in proper places and cleanup
##########################################
#Move the docs to final directory
rm -rf $finaldir # clean out whatever was in the final dir
mkdir $finaldir # and recreate it
#Copy the docset file to the docs directory so that it can be loaded into github
cp -a ~/Library/Developer/Shared/Documentation/DocSets/us.MySDK.MySDK-Total-SDK.docset ./$finaldir
if [ $? -ne 0 ]
then
echo "Unable to copy docset to ./docs"
exit 1
fi
# stage the html directories to their final destination
mv -f ./$tmpdir/html/* $finaldir
if [ $? -ne 0 ]
then
echo "Unable to move html files to ./docs"
exit 1
fi
rm -rf $tmpdir #clear out the tmp dir
echo "MySDK doc creation successful."
exit 0
The first one is the log screen shot if I run the script from the terminal.
Second is the log screen shot if I run the script from Xcode.

Related

Is it possible to use the "code" command in SSH'ed terminal to open VS Code on local machine with SSH extension?

Something I love about VS Code is that when I am using a terminal in WSL, I can run code file.txt, and it will open that file with VS Code on my local using the WSL remote extension.
Is it possible to do a similar thing with SSH? I.e., if I am SSH'ed into a remote host, is it possible to set things up so that running code file.txt will open VS Code on my local machine, connected via the remote SSH extension to open that file?
I found much better & simple answer thanks to this post.
Simply create new script file named code with below contents & put file under any folder from $PATH. (echo $PATH to see what folders you can use)
#! /usr/bin/env zsh
local max_retry=10
for i in {1..$max_retry}
do
local script=$(echo ~/.vscode-server/bin/*/bin/remote-cli/code(*oc[$i]N))
if [[ -z ${script} ]]
then
echo "VSCode remote script not found"
exit 1
fi
local socket=$(echo /run/user/$UID/vscode-ipc-*.sock(=oc[$i]N))
if [[ -z ${socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
${script} $# > /dev/null 2>&1
if [ "$?" -eq "0" ]; then
exit 0
fi
done
echo "Failed to find valid VS Code window"
Bash version
#! /bin/bash
max_retry=10
for i in $(seq 1 $max_retry)
do
recent_folder=$(ls ~/.vscode-server/bin/ -t | head -n$i)
script=$(echo ~/.vscode-server/bin/$recent_folder/bin/remote-cli/code)
if [[ -z ${script} ]]
then
echo "VSCode remote script not found"
exit 1
fi
socket=$(ls /run/user/$UID/vscode-ipc-* -t | head -n$i)
if [[ -z ${socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
${script} $#
if [ "$?" -eq "0" ]; then
exit 0
fi
done
echo "Failed to find valid VS Code window"
Update
Above script doesn't work with recent updates. I had to change first line to
local script=$(echo ~/.vscode-server/bin/*/bin/remote-cli/code(*oc[1]N))
Update2
Original script may fail if recently opened ssh window is closed, yet there is another SSHed window open. I have enhanced the script to enable retrying the command with recent N(default 10) windows.
You shouldn't have to do anything. VSCode automatically sets the path/PATH to the code in the path/PATH environment variable depending on your shell. See this response. You might be overwriting your path/PATH like I was. I was accidentally overwriting path in ~/.cshrc and PATH in ~/.bashrc and was running into the same issue. After fixing it, I can run code on the command line. which code returns the location of the command.
Until I spent time to figure it out, I was using the two methods mentioned below. Both of which worked for me in bash; you can modify it for your shell as you see fit. But really fix your path/PATH rather than using these methods.
Adding location of code to the PATH in ~/.bashrc
export PATH=${VSCODE_GIT_ASKPASS_NODE%/*}/bin:$PATH
OR
Setting alias to code in ~/.bashrc
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"
More on path vs. PATH here and here
Yes, sort of.
From a VSCode terminal run the command
env | grep VSCODE_IPC_HOOK_CLI
then copy-and-paste that line that line with export into your ssh terminal.
After that, you should be able to run code from your ~/.vscode-server/bin/XXX/bin directory.
VSCode terminal
SSH terminal
Update:
You can to automate this with a .bashrc and .profile to place the IPC code into a temp file, and source that when you do your ssh login.
For example, this works for me...
Append this to ~/.bashrc
#
if [ "$VSCODE_IPC_HOOK_CLI" != "" ]; then
cat >$HOME/.vscode_env.sh <<EOF
#
if [ "\$VSCODE_IPC_HOOK_CLI" = "" ]; then
export VSCODE_IPC_HOOK_CLI="$VSCODE_IPC_HOOK_CLI"
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"
fi
EOF
fi
And append this to your ~/.profile
[ -f $HOME/.vscode_env.sh ] && . $HOME/.vscode_env.sh
(There may be more elegant ways. And you still have to start at least 1 terminal in your remote VSCode session.)
this works to me
if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
local script=$(echo ~/.vscode-server/bin/*/bin/remote-cli/code(*oc[1]N))
if [[ -z ${script} ]]
then
echo "VSCode remote script not found"
exit 1
fi
local socket=$(echo /run/user/$UID/vscode-ipc-*.sock(=oc[1]N))
if [[ -z ${socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
alias code=${script}
fi
Use the below commands to open a folder or a file on the remote terminal.
Note: vscode-server must be already installed on the remote host (It would be, if you have already connected to it). Also the absolute path has to be specified for the file or folder. Use -n to launch in new window,-r to reuse same window.
code --folder-uri <absolute-path>
code --file-uri <absolute-path-file-name>
Example:
code -r --folder-uri /home/myscripts/src
code -n --file-uri /home/myscripts/src/math/sample.py

How can I easily patch and build gems after running gem/bundle install?

How can I automate patching and re-building gems after running a gem/bundle update?
(I want to patch gem-ctags to use ripper-tags instead of ctags)
The following script achieves this, and has some smarts to work around patch returning a failure code when some or all of a patch has already been applied:
#!/bin/bash
# Usage: gem-patch
# Code updates: https://gist.github.com/HaleTom/275f28403828b9b9b93d313990fc94f4
# Features:
# Work around `patch` returning non-zero if some patch hunks are already applied
# Apply all patches in $patch_dir (in order) to their corresponding gem(s)
# Build a gem only after all patches have been applied
# Only build the gem if it was patched
# Robust error handling
patch_dir="$HOME/lib/gem-patch"
# Patches are assumed to be made with git patch
# Files are to be named gem-name or gem-name.patch-explanation
# Multiple patches are applied in filename order
set -e -u
shopt -s nullglob # Globs are '' when no files match a pattern
gems_dir="$(gem environment gemdir)/gems"
if ! compgen -G "$patch_dir/*" > /dev/null; then
echo "Couldn't find any patches located in $patch_dir. Quitting." 2>&1
exit 1
fi
# Save the current "gemname-1.2.3" so that when it changes to a new one
# (ie, all patches have been applied) it can be built only once
function build_prev_if_needed {
if [[ ${prev_gem_ver:="${gem_ver:=''}"} != "$gem_ver" ]]; then
# We've moved on to another gem, build the last one
( cd "$gems_dir/$prev_gem_ver" &&
gem build "${prev_gem_ver%%-[-0-9.]*}.gemspec"
)
fi
prev_gem_ver="$gem_ver"
}
for patch in "$patch_dir"/*; do
gem_name=$(basename "${patch%%[.]*}") found_one=false
# $gem_dir becomes "rails-5.0.0.1" from find at end of loop
while read -d '' -r gem_dir; do
found_one=true
# Build the previously seen gem if we've moved on to a new one
gem_ver=${gem_dir##$gems_dir/}
echo -n "$gem_ver (patch $(basename "$patch")): "
# If we could reverse the patch, then it has already been applied; skip it
if patch --dry-run --reverse -d "$gem_dir" -fp1 --ignore-whitespace -i "$patch" >/dev/null 2>&1; then
echo "skipping (already applied)"
continue
else # patch not yet applied
echo "patching..."
# Patch returns non-zero if some hunks have already been applied
if ! patch -d "$gem_dir" -fsp1 --ignore-whitespace -i "$patch"; then
# Check that the patch was fully applied by pretending to reverse it
if patch --dry-run --reverse -d "$gem_dir" -fp1 --ignore-whitespace -i "$patch" >/dev/null 2>&1; then
echo "Ignoring failure: hunk(s) were already applied"
else
echo "Patch failed for $gem_dir" >&2; exit 1;
fi
fi
build_prev_if_needed
fi
done < <(find "$gems_dir" -maxdepth 1 -type d -regex ".*/$gem_name-[-0-9.]+" -print0)
if [[ $found_one != true ]]; then
echo "Fatal: Patch file '$(basename "$patch")': Couldn't find any gem sources named $gems_dir/$(basename "$patch")*" >&2; exit 1
fi
done # $gem_dir is now blank
gem_ver=''
build_prev_if_needed

How to get error message from ditto command , when it fails to archive

Using ditto command we are archiving folder. When folder contains some files which does not have read permission. It fails to archive. That time ditto command logs error message saying " ditto: "Path" : Permission denied. How to get this error message.
As with any UNIX command, errors are written to stderr, which can be captured by adding 2> file to end of the command:
$ ditto src dst 2> error
$ cat error
ditto: /Users/andy/tmp/src/./x: Permission denied
If you are running ditto from a shell script, then something like this should work:
#!/bin/sh
errfile=/tmp/errors.$$
(cd ~/tmp; ditto src dst 2> $errfile)
if [ $? -ne 0 ]; then
echo There was a problem:
cat $errfile
else
echo Everything is cool
fi

Host key verification failed [rsync: connection unexpectedly closed]

I'm stuck with a peculiar problem, where rsync command is not running when it is executed through crontab.
Below is the code :
#!/bin/sh -x
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/mysql/bin:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools:~/usr/lib/jvm/jdk-6/bin
/bin/sh /etc/profile
MyUSER="root" # USERNAME
MyPASS="password" # PASSWORD
MyHOST="localhost" # Hostname
Password="" #Linux Password
MYSQL="$(which mysql)"
if [ -z "$MYSQL" ]; then
echo "Error: MYSQL not found"
exit 1
fi
MYSQLADMIN="$(which mysqladmin)"
if [ -z "$MYSQLADMIN" ]; then
echo "Error: MYSQLADMIN not found"
exit 1
fi
CHOWN="$(which chown)"
if [ -z "$CHOWN" ]; then
echo "Error: CHOWN not found"
exit 1
fi
CHMOD="$(which chmod)"
if [ -z "$CHMOD" ]; then
echo "Error: CHMOD not found"
exit 1
fi
GZIP="$(which gzip)"
if [ -z "$GZIP" ]; then
echo "Error: GZIP not found"
exit 1
fi
CP="$(which cp)"
if [ -z "$CP" ]; then
echo "Error: CP not found"
exit 1
fi
MV="$(which mv)"
if [ -z "$MV" ]; then
echo "Error: MV not found"
exit 1
fi
RM="$(which rm)"
if [ -z "$RM" ]; then
echo "Error: RM not found"
exit 1
fi
RSYNC="$(which rsync)"
if [ -z "$RSYNC" ]; then
echo "Error: RSYNC not found"
exit 1
fi
MYSQLBINLOG="$(which mysqlbinlog)"
if [ -z "$MYSQLBINLOG" ]; then
echo "Error: MYSQLBINLOG not found"
exit 1
fi
# Get data in dd-mm-yyyy format
NOW="$(date +"%d-%m-%Y-%T")"
DEST="/home/db-backup"
mkdir $DEST/Increment_backup.$NOW
LATEST=$DEST/Increment_backup.$NOW
$MYSQLADMIN -u$MyUSER -p$MyPASS flush-logs
newestlog=`ls -d /usr/local/mysql/data/mysql-bin.?????? | sed 's/^.*\.//' | sort -g | tail -n 1`
echo $newestlog
for file in `ls /usr/local/mysql/data/mysql-bin.??????`
do
if [ "/usr/local/mysql/data/mysql-bin.$newestlog" != "$file" ]; then
echo $file
echo $Password | sudo -S $CHMOD 0777 $file
#sudo $MYSQLBINLOG $file>$file.$NOW.sql
$CP "$file" $LATEST
#$RM "$file.$NOW.sql"
#$MV $file.sql.gz /$LATEST
fi
done
for file1 in `ls $LATEST/mysql-bin.??????`
do
$MYSQLBINLOG $file1>$file1.$NOW.sql
$GZIP -9 "$file1.$NOW.sql"
$RM "$file1"
done
$RSYNC -v -e ssh $LATEST abc#192.168.1.9:/home/rsync-backup/
#FILE=$LATEST/"mysql-bin.??????"
#$MYSQLBINLOG $FILE>$FILE.$NOW.sql
#$GZIP -f "$FILE.$NOW.sql"
pwd
Rsync happens when the code is run manually, but fails when it is run through crontab. Rest of the commands are working fine. From the logs I got this information:
Host key verification failed.^M
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
This is basically due to the first time authentication issue for ssh. If you were to ensure that the host is added to known_hosts manually or have an expect for the prompt in your script, it should work.
The authenticity of host '[IP]:20022 ([IP]:22)' can't be established.
RSA key fingerprint is bc:87:52:cf:ac:3e:67:74:1b:e1:0b:e3:e2:06:d8:21.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[IP]:22' (RSA) to the list of known hosts
This kind of error is usually caused by differences in the environment. A good troubleshooting step is to run "env" at the start of the program and compare the cron and non-cron version.
You should also run the command as "sh -x" which will show you all the expansions which will help identify which variable is not being set properly.
This could be your HOME directory is encrypted.
If your user is logged, it works, but when it's a cron, even it's executing the same user it does not have access to your $HOME/.ssh directory

Maven + Mercurial for Build Numbers

I can't figure out how to get a Mercurial revision id put into my Maven build (ideally I would like it in the MANIFEST of my jars and war).
The closest solution I could find is:
mvn -DbuildNumber=`hg id -i`
Which won't really work for Windows or my Hudson server.
Luckily Hudson tags my builds but I would like some more assurance if the builds were also tagged with the Mercurial changset id.
Have a look at this previous question and the link from the accepted answer. Basically, you want to do the same thing except that you'll want to use the buildnumber:hgchangeset goal with Mercurial to get a changeset property with the content of hg id -i.
Unfortunately, hg id -i is too long for use. I created a script that will calculate an accurate build number. However, there are two exceptions. If there was not previous release on the branch, then it cannot be valid. If there are changes in the local repo, then it cannot be valid. In my build script I mark the build as "x.x.UNSTABLE" whenever that happens.
I use a REL_PATTERN to pick up the last tag in the current branch that was marked as an actual release. Then I calculate the build number by tracking the commit log count from that release + all commits to the branch since that release.
#!/bin/bash
REL_PATTERN="release-[0-9]*\.[0-9]*\.[0-9]*"
BRANCH=$( hg branch )
CURR_REV=$( hg id -n )
if [ "${CURR_REV: -1}" = "+" ] ; then
echo "ERROR: This workspace contains uncommitted code. Cannot calculate build number" >&2
echo "UNSTABLE"
exit 1
fi
RELEASE=$( hg log --rev="branch($BRANCH) and tag() and 1:$CURR_REV" -T "{tags} {rev}\n"|grep "${REL_PATTERN} "|tail -1 )
if [ "$RELEASE" = "" ] ; then
echo "ERROR: Unable to locate version tag" >&2
echo "UNSTABLE"
exit 1
fi
RELEASE_REV=$( echo $RELEASE|cut -f 2 -d ' ' )
RELEASE_TAG=$( echo $RELEASE|cut -f 1 -d ' ' )
REVS=$( hg log -P $RELEASE_REV -b $BRANCH -T "{rev}\n"|wc -l )
BUILD=$( hg log -r1:$CURR_REV -P $RELEASE_REV -b $BRANCH -T "{rev}\n"|wc -l )
echo "BRANCH=$BRANCH" >&2
echo "CURR_REV=$CURR_REV" >&2
echo "RELEASE_REV=$RELEASE_REV" >&2
echo "RELEASE_TAG=$RELEASE_TAG" >&2
echo "BUILD=$BUILD" >&2
echo $BUILD